Class: Omega::Contest
- Inherits:
-
Base
- Object
- Base
- Omega::Contest
show all
- Defined in:
- lib/omega/contest.rb
Instance Attribute Summary
Attributes inherited from Base
#data
Instance Method Summary
collapse
Methods inherited from Base
#initialize
Constructor Details
This class inherits a constructor from Omega::Base
Instance Method Details
#add_admin_group(group) ⇒ Object
66
67
68
|
# File 'lib/omega/contest.rb', line 66
def add_admin_group(group)
@client.add_admin_group(data[:alias], group)
end
|
#add_problem(name) ⇒ Object
62
63
64
|
# File 'lib/omega/contest.rb', line 62
def add_problem(name)
@client.add_problem_to_contest(data[:alias], name)
end
|
#add_user(user) ⇒ Object
42
43
44
45
46
47
48
|
# File 'lib/omega/contest.rb', line 42
def add_user(user)
if user.is_a?(String)
@client.add_user_to_contest(user, data[:alias])
else
@client.add_user_to_contest(user.data[:username], data[:alias])
end
end
|
#alias ⇒ Object
58
59
60
|
# File 'lib/omega/contest.rb', line 58
def alias
@data[:alias].downcase
end
|
#all_sources ⇒ Object
20
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/omega/contest.rb', line 20
def all_sources
sources = []
offset = 0
bach = runs
until bach.empty?
sources += bach
offset += bach.size
bach = runs(offset)
end
sources
end
|
#clarifications ⇒ Object
50
51
52
|
# File 'lib/omega/contest.rb', line 50
def clarifications
@client.clarifications(data[:alias])
end
|
#full_details ⇒ Object
34
35
36
|
# File 'lib/omega/contest.rb', line 34
def full_details
@full_details ||= @client.scrap_get("/contest/#{data[:alias]}/edit/")
end
|
#group_admin?(group_name) ⇒ Boolean
38
39
40
|
# File 'lib/omega/contest.rb', line 38
def group_admin?(group_name)
full_details[:group_admins].any? { |group| group[:alias].casecmp(group_name).zero? }
end
|
#observe(score_notifier, clar_noritifer) ⇒ Object
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
|
# File 'lib/omega/contest.rb', line 70
def observe(score_notifier, clar_noritifer)
last = current = scoreboard
sleep(5)
Thread.new do
loop do
clarifications.select { |clar| clar[:answer].nil? || clar[:answer].empty? }
.each { |clar| clar_noritifer.call(clar) }
sleep(300)
rescue StandardError => e
puts e.message
sleep(3000)
end
end
loop do
current = scoreboard
last.users.each do |score|
current_score = current.score_for(score.username)
score.problems.each do |problem|
name = problem[:alias]
current_problem = current_score.score_for(name)
last_points = problem[:points]
current_points = current_problem[:points]
if current_points != last_points
score_notifier.call(data[:alias], score.username, name, current_points, last_points,
data[:alias])
end
end
end
last = current
sleep(15)
rescue StandardError => e
puts e.message
sleep(3000)
end
end
|
#problems ⇒ Object
12
13
14
|
# File 'lib/omega/contest.rb', line 12
def problems
@data[:problems]
end
|
#runs(offset = 0, page_size = 100) ⇒ Object
16
17
18
|
# File 'lib/omega/contest.rb', line 16
def runs(offset = 0, page_size = 100)
@client.contest_runs(data[:alias], offset, page_size)
end
|
#scoreboard ⇒ Object
8
9
10
|
# File 'lib/omega/contest.rb', line 8
def scoreboard
@client.scoreboard(data[:alias])
end
|
#users ⇒ Object
54
55
56
|
# File 'lib/omega/contest.rb', line 54
def users
scoreboard.users
end
|