Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvements to replay script: #119

Merged
merged 1 commit into from
Apr 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 34 additions & 10 deletions provision-contest/replay.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
parser.add_argument('-s', '--submissionid', help='submission to start at.')
parser.add_argument('--insecure', help='do not verify SSL certificate', action='store_true')
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')
parser.add_argument('-I', '--ignore_teamids', help='Completely randomize teamids during replay, not storing any mapping.', action='store_true')
parser.add_argument('-i', '--internal_data_source', help='The API uses an internal API source.', action='store_true')
parser.add_argument('-f', '--simulation_speed', help='Speed up replay speed by this factor.')

Expand All @@ -53,7 +54,23 @@
submissions = json.load(open('submissions.json'))
logging.info(f'Loaded {len(submissions)} submissions.')

problem_data = requests.get(f'{api_url}/contests/{contest}/problems', verify=verify).json()
known_problem_ids = set([p['id'] for p in problem_data])
used_problem_ids = set([s['problem_id'] for s in submissions])
unknown_problem_ids = used_problem_ids.difference(known_problem_ids)
if unknown_problem_ids:
if len(unknown_problem_ids) == len(used_problem_ids):
logging.critical('None of the used problem IDs is known.')
sys.exit(-1)
logging.error(f'Some problem IDs are used but not known: {unknown_problem_ids}')

contest_data = requests.get(f'{api_url}/contests/{contest}', verify=verify).json()
if 'code' in contest_data and 'message' in contest_data and contest_data['code'] != 200:
code = contest_data['code']
msg = contest_data['message']
logging.critical(f'Failed to retrieve contest, HTTP status code: {code}, message: {msg}')
sys.exit(-1)

while not contest_data['start_time']:
logging.info(f'Start time unknown - contest delayed.')
time_diff = 30
Expand All @@ -67,18 +84,22 @@
contest_start_obj = datetime.strptime(contest_data['start_time'], '%Y-%m-%dT%H:%M:%S%z')
contest_duration = (datetime.strptime(contest_data['duration'], '%H:%M:%S.000') - datetime(1900, 1, 1)).total_seconds()

if not args.no_remap_teams:
if args.no_remap_teams:
if args.ignore_teamids:
logging.critical('Cannot specify --no_remap_teams and --ignore_teamids at the same time.')
sys.exit(-1)

logging.info('Keeping original team IDs.')
else:
# Get the teams from the contest
team_data = requests.get(f'{api_url}/contests/{contest}/teams', verify=verify).json()
team_ids = [team['id'] for team in team_data if not team['hidden']]

if not team_ids:
print('Contest has no teams, can\'t submit')
logging.critical('Contest has no teams, can\'t submit.')
sys.exit(-1)

logging.info(f'Remapping teams to {len(team_ids)} teams from API')
else:
logging.info('Keeping original teams')
logging.info(f'Remapping teams to {len(team_ids)} teams from API.')

now = time.time()
orig_contest_duration = 5 * 60 * 60
Expand Down Expand Up @@ -151,11 +172,14 @@
else:
problem_label = problem_id
if not args.no_remap_teams:
if team_id not in team_problem_team_map:
team_problem_team_map[team_id] = dict()
if problem_label not in team_problem_team_map[team_id]:
team_problem_team_map[team_id][problem_label] = random.choice(team_ids)
team_id = team_problem_team_map[team_id][problem_label]
if args.ignore_teamids:
team_id = random.choice(team_ids)
else:
if team_id not in team_problem_team_map:
team_problem_team_map[team_id] = dict()
if problem_label not in team_problem_team_map[team_id]:
team_problem_team_map[team_id][problem_label] = random.choice(team_ids)
team_id = team_problem_team_map[team_id][problem_label]
else:
team_id = submission['team_id']

Expand Down
Loading