Skip to content

Commit 4c4113b

Browse files
committed
Add simulation speed as option to the replay script. (#115)
Also do a minor fix to always prepend single digit minutes/seconds with 0s. (cherry picked from commit f130761)
1 parent b9f1051 commit 4c4113b

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

provision-contest/replay.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
parser.add_argument('--insecure', help='do not verify SSL certificate', action='store_true')
3131
parser.add_argument('-r', '--no_remap_teams', help='do not remap team ID\'s to team ID\'s of contest from API.', action='store_true')
3232
parser.add_argument('-i', '--internal_data_source', help='The API uses an internal API source.', action='store_true')
33+
parser.add_argument('-f', '--simulation_speed', help='Speed up replay speed by this factor.')
3334

3435
args = parser.parse_args()
3536

@@ -100,6 +101,8 @@
100101
logging.info('Contest will be started at '
101102
+ time.strftime('%X %x %Z', time.localtime(contest_start)) + '.')
102103
simulation_speed = orig_contest_duration/contest_duration
104+
if args.simulation_speed:
105+
simulation_speed = float(args.simulation_speed)
103106
logging.info(f'Simulation speed: {simulation_speed}')
104107

105108
if args.internal_data_source:
@@ -119,12 +122,15 @@
119122
if not submission['id']:
120123
continue
121124
times = submission['contest_time'].split(':')
122-
orig_submission_time = int(times[0])*3600 + int(times[1])*60 + float(times[2])
125+
hours = int(times[0])
126+
minutes = int(times[1])
127+
seconds = float(times[2])
128+
orig_submission_time = hours*3600 + minutes*60 + seconds
123129
new_submission_time = orig_submission_time/simulation_speed
124130
time_from_start = time.time() - contest_start
125131
time_diff = new_submission_time - time_from_start
126132
if time_diff > 0:
127-
logging.info(f'Waiting for simulated contest time of {times[0]}:{times[1]}:{times[2]}.')
133+
logging.info(f'Waiting for simulated contest time of {hours}:{minutes:02}:{seconds:06.3f}.')
128134
spinner = Halo(spinner='dots', text=f'Sleeping for ~{str(round(time_diff,2))}s')
129135
spinner.start()
130136
while time_diff > 1:

0 commit comments

Comments
 (0)