omegaup 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/omega/cli.rb +11 -1
- data/lib/omega/cli/contest.rb +8 -0
- data/lib/omega/client.rb +20 -1
- data/lib/omega/contest.rb +36 -5
- data/lib/omega/contest_run.rb +17 -0
- data/lib/omega/version.rb +1 -1
- data/omega.gemspec +1 -0
- metadata +17 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 444fc13885fc5e35380254f0b820c54d3fe2134f5f271e3b420e9245acf84d03
|
4
|
+
data.tar.gz: cd81162a29dc5d7ceeedffefca870c37c4260d425bd5ba61431d0352425a3f3a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c98905259ad2bfb854142e4be40226417586edaada2da806916dfa1446f16a8bfae18bd619a47c6707fcba4e32f80888a99d12903f10a9011cefe74443a78bee
|
7
|
+
data.tar.gz: cd133c92f5fb7332fc90c371227459c6d3a488a2456700036cca833c3eb9bb1a100dd7cf7686b893471d1db568fb66860ead28f8e3b769714167cd43fdd43b7d
|
data/lib/omega/cli.rb
CHANGED
@@ -15,6 +15,7 @@ module Omega
|
|
15
15
|
scoreboard
|
16
16
|
create-contest
|
17
17
|
add-problem
|
18
|
+
sources
|
18
19
|
help
|
19
20
|
].freeze
|
20
21
|
|
@@ -27,16 +28,18 @@ Commands:
|
|
27
28
|
- user Generates a dump of the user data in yml format.
|
28
29
|
- scoreboard Gets contest scoreboard with users and score.
|
29
30
|
- clarifications Gets contest clarifications.
|
31
|
+
- sources Downloads all code sources into path
|
30
32
|
Parametes:
|
31
33
|
--contest Contest name
|
32
34
|
--user Username or email
|
33
35
|
--user-file A file path containing a list of user one per line without
|
34
36
|
header
|
35
37
|
--open Filter to only open clarifications
|
38
|
+
--path Path to store results
|
36
39
|
Setup:
|
37
40
|
You need to add two env variables with your omegaup credentials.
|
38
41
|
OMEGAUP_URL *Optional* This is intended for development purpose, it will target
|
39
|
-
to https://
|
42
|
+
to https://omegaup.com by default.
|
40
43
|
OMEGAUP_USER *Required* Your OmegaUp Username or Email
|
41
44
|
OMEGAUP_PASS *Required* Your OmegaUp Password
|
42
45
|
)
|
@@ -65,6 +68,11 @@ OMEGAUP_PASS *Required* Your OmegaUp Password
|
|
65
68
|
opt :contest, 'Contest ShortName or identifier', type: :string
|
66
69
|
opt :open, 'Filter to only open clars'
|
67
70
|
end
|
71
|
+
when 'sources'
|
72
|
+
Optimist.options do
|
73
|
+
opt :contest, 'Contest ShortName or identifier', type: :string
|
74
|
+
opt :path, 'Path to store results', type: :string
|
75
|
+
end
|
68
76
|
# when 'create-contest'
|
69
77
|
# Optimist.options do
|
70
78
|
# opt :contest, 'Contest ShortName or identifier', type: :string
|
@@ -105,6 +113,8 @@ OMEGAUP_PASS *Required* Your OmegaUp Password
|
|
105
113
|
scoreboard(@cmd_opts[:contest])
|
106
114
|
when 'clarifications'
|
107
115
|
clarifications(@cmd_opts[:contest], @cmd_opts[:open])
|
116
|
+
when 'sources'
|
117
|
+
download_sources(@cmd_opts[:contest], @cmd_opts[:path])
|
108
118
|
end
|
109
119
|
end
|
110
120
|
end
|
data/lib/omega/cli/contest.rb
CHANGED
@@ -40,6 +40,14 @@ module Omega
|
|
40
40
|
rescue StandardError => e
|
41
41
|
puts "#{contest_name}: #{e.message}"
|
42
42
|
end
|
43
|
+
|
44
|
+
def download_sources(contest_name, path)
|
45
|
+
Dir.mkdir(path) unless File.directory?(path)
|
46
|
+
contest = omega.contest(contest_name)
|
47
|
+
contest.all_sources.each do |source|
|
48
|
+
source.save_at(path)
|
49
|
+
end
|
50
|
+
end
|
43
51
|
end
|
44
52
|
end
|
45
53
|
end
|
data/lib/omega/client.rb
CHANGED
@@ -3,6 +3,7 @@
|
|
3
3
|
require_relative 'contest'
|
4
4
|
require_relative 'scoreboard'
|
5
5
|
require_relative 'user'
|
6
|
+
require_relative 'contest_run'
|
6
7
|
|
7
8
|
require 'httparty'
|
8
9
|
|
@@ -26,10 +27,15 @@ module Omega
|
|
26
27
|
@config = conf
|
27
28
|
end
|
28
29
|
|
29
|
-
def perform_request(method, endpoint, data)
|
30
|
+
def perform_request(method, endpoint, data, retried = false)
|
30
31
|
url = "#{@config['endpoint']}#{endpoint}"
|
31
32
|
response = self.class.send(method, url, body: data)
|
32
33
|
body = JSON.parse(response.body, symbolize_names: true)
|
34
|
+
|
35
|
+
if body[:errorcode] == 401 && !retried
|
36
|
+
login
|
37
|
+
return perform_request(method, endpoint, data, true)
|
38
|
+
end
|
33
39
|
raise OmegaError, body if body[:error]
|
34
40
|
|
35
41
|
body
|
@@ -71,6 +77,10 @@ module Omega
|
|
71
77
|
data[:clarifications]
|
72
78
|
end
|
73
79
|
|
80
|
+
def respond_clarif(id, response)
|
81
|
+
post('/api/clarification/update/', { clarification_id: id, answer: response })
|
82
|
+
end
|
83
|
+
|
74
84
|
def user(user)
|
75
85
|
data = post('/api/user/profile/', { username: user })
|
76
86
|
User.new(self, data)
|
@@ -83,5 +93,14 @@ module Omega
|
|
83
93
|
def problems_solved(user)
|
84
94
|
post('/api/user/problemsSolved/', { username: user })
|
85
95
|
end
|
96
|
+
|
97
|
+
def run_details(run)
|
98
|
+
post('/api/run/details/', { run_alias: run })
|
99
|
+
end
|
100
|
+
|
101
|
+
def contest_runs(contest, offset, page_size)
|
102
|
+
data = post('/api/contest/runs/', { contest_alias: contest, offset: offset, rowcount: page_size })
|
103
|
+
data[:runs].map { |run| ContestRun.new(self, run) }
|
104
|
+
end
|
86
105
|
end
|
87
106
|
end
|
data/lib/omega/contest.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require_relative 'base'
|
4
|
+
require_relative 'contest_run'
|
4
5
|
|
5
6
|
module Omega
|
6
7
|
class Contest < Base
|
@@ -8,6 +9,24 @@ module Omega
|
|
8
9
|
@client.scoreboard(data[:alias])
|
9
10
|
end
|
10
11
|
|
12
|
+
def runs(offset = 0, page_size = 100)
|
13
|
+
@client.contest_runs(data[:alias], offset, page_size)
|
14
|
+
end
|
15
|
+
|
16
|
+
def all_sources
|
17
|
+
sources = []
|
18
|
+
offset = 0
|
19
|
+
bach = runs
|
20
|
+
|
21
|
+
until bach.empty?
|
22
|
+
sources += bach
|
23
|
+
offset += bach.size
|
24
|
+
bach = runs(offset)
|
25
|
+
end
|
26
|
+
|
27
|
+
sources
|
28
|
+
end
|
29
|
+
|
11
30
|
def add_user(user)
|
12
31
|
if user.is_a?(String)
|
13
32
|
@client.add_user_to_contest(user, data[:alias])
|
@@ -20,26 +39,38 @@ module Omega
|
|
20
39
|
@client.clarifications(data[:alias])
|
21
40
|
end
|
22
41
|
|
23
|
-
def observe
|
42
|
+
def observe(score_notifier, clar_noritifer)
|
24
43
|
last = current = scoreboard
|
25
44
|
sleep(5)
|
45
|
+
Thread.new do
|
46
|
+
loop do
|
47
|
+
clarifications.select { |clar| clar[:answer].nil? || clar[:answer].empty? }
|
48
|
+
.each { |clar| clar_noritifer.call(clar) }
|
49
|
+
sleep(300)
|
50
|
+
rescue StandardError => ex
|
51
|
+
puts ex.message
|
52
|
+
sleep(3000)
|
53
|
+
end
|
54
|
+
end
|
26
55
|
loop do
|
27
56
|
current = scoreboard
|
28
57
|
last.users.each do |score|
|
29
|
-
puts score.username
|
58
|
+
# puts score.username
|
30
59
|
current_score = current.score_for(score.username)
|
31
60
|
score.problems.each do |problem|
|
32
61
|
name = problem[:alias]
|
33
62
|
current_problem = current_score.score_for(name)
|
34
63
|
last_points = problem[:points]
|
35
64
|
current_points = current_problem[:points]
|
36
|
-
|
37
|
-
yield(contest_name, score.username, name, current_points, last_points) if current_points != last_points
|
65
|
+
score_notifier.call(data[:alias], score.username, name, current_points, last_points, data[:alias]) if current_points != last_points
|
38
66
|
end
|
39
|
-
puts '-' * 60
|
40
67
|
end
|
68
|
+
# puts '-' * 60
|
41
69
|
last = current
|
42
70
|
sleep(15)
|
71
|
+
rescue StandardError => ex
|
72
|
+
puts ex.message
|
73
|
+
sleep(3000)
|
43
74
|
end
|
44
75
|
end
|
45
76
|
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require_relative 'base'
|
2
|
+
|
3
|
+
module Omega
|
4
|
+
class ContestRun < Base
|
5
|
+
def details
|
6
|
+
@details ||= @client.run_details(@data[:guid])
|
7
|
+
end
|
8
|
+
|
9
|
+
def source_code
|
10
|
+
details[:source]
|
11
|
+
end
|
12
|
+
|
13
|
+
def save_at(path)
|
14
|
+
File.write("#{path}/#{@data[:guid]}.yaml", { details: details, data: @data }.to_yaml)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/omega/version.rb
CHANGED
data/omega.gemspec
CHANGED
@@ -23,6 +23,7 @@ Gem::Specification.new do |spec|
|
|
23
23
|
spec.require_paths = ['lib']
|
24
24
|
|
25
25
|
spec.add_development_dependency 'amazing_print'
|
26
|
+
spec.add_development_dependency 'httparty'
|
26
27
|
spec.add_development_dependency 'minitest', '~> 5'
|
27
28
|
spec.add_development_dependency 'optimist'
|
28
29
|
spec.add_development_dependency 'rake', '~> 10.0'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: omegaup
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gilberto Vargas
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-05-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: amazing_print
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: httparty
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: minitest
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -83,6 +97,7 @@ files:
|
|
83
97
|
- lib/omega/cli/contest.rb
|
84
98
|
- lib/omega/client.rb
|
85
99
|
- lib/omega/contest.rb
|
100
|
+
- lib/omega/contest_run.rb
|
86
101
|
- lib/omega/scoreboard.rb
|
87
102
|
- lib/omega/user.rb
|
88
103
|
- lib/omega/version.rb
|