@@ -2,7 +2,6 @@ class ExternalApi::V1::ViewerController < ExternalApiController
22 before_action :authenticate_admin!
33
44 def teams
5- images = RunnerMaster ::get_images
65 teams = Team . where ( account_type : :real )
76 problems = Problem . where ( hidden : [ false , nil ] )
87 rounds = Round . where ( disabled : [ false , nil ] )
@@ -13,12 +12,8 @@ def teams
1312 score_map [ team . id ] = { }
1413 rounds . each do |round |
1514 problems . each do |problem |
16- # search latest image on the current round
17- # TODO: this method can be faster
18- image = find_image ( images , team . login_name , problem . exploit_container_name , round . start_at )
19- next if image . nil?
20- # get score from image digest, team login name, exploit container name which is before than round started
21- score = find_score ( scores , image [ 'digest' ] , team . login_name , problem . exploit_container_name , round . start_at )
15+ # get score from team login name, exploit container name which is before than round started
16+ score = find_score ( scores , team . login_name , problem . exploit_container_name , round . start_at )
2217 next if score . nil?
2318
2419 # calc score
@@ -44,7 +39,6 @@ def teams
4439 end
4540
4641 def table
47- images = RunnerMaster ::get_images
4842 teams = Team . where ( account_type : :real )
4943 problems = Problem . where ( hidden : [ false , nil ] )
5044 rounds = Round . where ( disabled : [ false , nil ] )
@@ -58,12 +52,8 @@ def table
5852 problems . each do |problem |
5953 score_map [ problem . id ] = { }
6054 rounds . each do |round |
61- # search latest image on the current round
62- # TODO: this method can be faster
63- image = find_image ( images , team . login_name , problem . exploit_container_name , round . start_at )
64- next if image . nil?
65- # get score from image digest, team login name, exploit container name which is before than round started
66- score = find_score ( scores , image [ 'digest' ] , team . login_name , problem . exploit_container_name , round . start_at )
55+ # get score from team login name, exploit container name which is before than round started
56+ score = find_score ( scores , team . login_name , problem . exploit_container_name , round . start_at )
6757 next if score . nil?
6858
6959 # calc score
@@ -88,7 +78,6 @@ def table
8878 def problems
8979 result = { }
9080
91- images = RunnerMaster ::get_images
9281 teams = Team . where ( account_type : :real )
9382 problems = Problem . where ( hidden : [ false , nil ] )
9483 rounds = Round . where ( disabled : [ false , nil ] )
@@ -104,12 +93,8 @@ def problems
10493 result [ problem . id ] [ :round ] [ round . id ] [ :start_at ] = round . start_at
10594 result [ problem . id ] [ :round ] [ round . id ] [ :team_result ] = { }
10695 teams . each do |team |
107- # search latest image on the current round
108- # TODO: this method can be faster
109- image = find_image ( images , team . login_name , problem . exploit_container_name , round . start_at )
110- next if image . nil?
111- # get score from image digest, team login name, exploit container name which is before than round started
112- score = find_score ( scores , image [ 'digest' ] , team . login_name , problem . exploit_container_name , round . start_at )
96+ # get score from team login name, exploit container name which is before than round started
97+ score = find_score ( scores , team . login_name , problem . exploit_container_name , round . start_at )
11398 next if score . nil?
11499
115100 result [ problem . id ] [ :round ] [ round . id ] [ :team_result ] [ team . id ] = score . runner_round_id
@@ -167,27 +152,11 @@ def capture_type
167152 }
168153 end
169154
170- private
171- def find_image ( images , team , exploit_container_name , before_at )
172- # XXX: image['CreatedAt'] はUTCなのでJSTに変えておく
173- images = images . map { |i |
174- new_i = i . dup
175- new_i [ 'CreatedAt' ] = Time . parse ( new_i [ 'CreatedAt' ] + ' +00:00' ) . in_time_zone ( 'Tokyo' )
176- new_i
177- }
178- images
179- . sort { |a , b | b [ 'CreatedAt' ] <=> a [ 'CreatedAt' ] } # find latest image
180- . find { |image |
181- ( image [ 'team' ] == team && image [ 'exploit_container' ] == exploit_container_name &&
182- image [ 'CreatedAt' ] . to_i <= before_at . to_i )
183- }
184- end
185-
186155 # get a sore which has same image_digest, team_login_name and problem_name before before_at
187156 # scores are sorted by runner_started_at so that it returns latest score
188- def find_score ( scores , image_digest , team_login_name , exploit_container_name , before_at )
157+ def find_score ( scores , team_login_name , exploit_container_name , before_at )
189158 scores . find { |score |
190- ( score . image_digest == image_digest && score . team_login_name == team_login_name &&
159+ ( score . team_login_name == team_login_name &&
191160 score . problem_name == exploit_container_name && score . runner_started_at . to_i <= before_at . to_i )
192161 }
193162 end
0 commit comments