|
29 | 29 | parser.add_argument('-s', '--submissionid', help='submission to start at.')
|
30 | 30 | parser.add_argument('--insecure', help='do not verify SSL certificate', action='store_true')
|
31 | 31 | 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')
|
| 32 | +parser.add_argument('-I', '--ignore_teamids', help='Completely randomize teamids during replay, not storing any mapping.', action='store_true') |
32 | 33 | parser.add_argument('-i', '--internal_data_source', help='The API uses an internal API source.', action='store_true')
|
33 | 34 | parser.add_argument('-f', '--simulation_speed', help='Speed up replay speed by this factor.')
|
34 | 35 |
|
|
53 | 54 | submissions = json.load(open('submissions.json'))
|
54 | 55 | logging.info(f'Loaded {len(submissions)} submissions.')
|
55 | 56 |
|
| 57 | +problem_data = requests.get(f'{api_url}/contests/{contest}/problems', verify=verify).json() |
| 58 | +known_problem_ids = set([p['id'] for p in problem_data]) |
| 59 | +used_problem_ids = set([s['problem_id'] for s in submissions]) |
| 60 | +unknown_problem_ids = used_problem_ids.difference(known_problem_ids) |
| 61 | +if unknown_problem_ids: |
| 62 | + if len(unknown_problem_ids) == len(used_problem_ids): |
| 63 | + logging.critical('None of the used problem IDs is known.') |
| 64 | + sys.exit(-1) |
| 65 | + logging.error(f'Some problem IDs are used but not known: {unknown_problem_ids}') |
| 66 | + |
56 | 67 | contest_data = requests.get(f'{api_url}/contests/{contest}', verify=verify).json()
|
| 68 | +if 'code' in contest_data and 'message' in contest_data and contest_data['code'] != 200: |
| 69 | + code = contest_data['code'] |
| 70 | + msg = contest_data['message'] |
| 71 | + logging.critical(f'Failed to retrieve contest, HTTP status code: {code}, message: {msg}') |
| 72 | + sys.exit(-1) |
| 73 | + |
57 | 74 | while not contest_data['start_time']:
|
58 | 75 | logging.info(f'Start time unknown - contest delayed.')
|
59 | 76 | time_diff = 30
|
|
67 | 84 | contest_start_obj = datetime.strptime(contest_data['start_time'], '%Y-%m-%dT%H:%M:%S%z')
|
68 | 85 | contest_duration = (datetime.strptime(contest_data['duration'], '%H:%M:%S.000') - datetime(1900, 1, 1)).total_seconds()
|
69 | 86 |
|
70 |
| -if not args.no_remap_teams: |
| 87 | +if args.no_remap_teams: |
| 88 | + if args.ignore_teamids: |
| 89 | + logging.critical('Cannot specify --no_remap_teams and --ignore_teamids at the same time.') |
| 90 | + sys.exit(-1) |
| 91 | + |
| 92 | + logging.info('Keeping original team IDs.') |
| 93 | +else: |
71 | 94 | # Get the teams from the contest
|
72 | 95 | team_data = requests.get(f'{api_url}/contests/{contest}/teams', verify=verify).json()
|
73 | 96 | team_ids = [team['id'] for team in team_data if not team['hidden']]
|
74 | 97 |
|
75 | 98 | if not team_ids:
|
76 |
| - print('Contest has no teams, can\'t submit') |
| 99 | + logging.critical('Contest has no teams, can\'t submit.') |
77 | 100 | sys.exit(-1)
|
78 | 101 |
|
79 |
| - logging.info(f'Remapping teams to {len(team_ids)} teams from API') |
80 |
| -else: |
81 |
| - logging.info('Keeping original teams') |
| 102 | + logging.info(f'Remapping teams to {len(team_ids)} teams from API.') |
82 | 103 |
|
83 | 104 | now = time.time()
|
84 | 105 | orig_contest_duration = 5 * 60 * 60
|
|
151 | 172 | else:
|
152 | 173 | problem_label = problem_id
|
153 | 174 | if not args.no_remap_teams:
|
154 |
| - if team_id not in team_problem_team_map: |
155 |
| - team_problem_team_map[team_id] = dict() |
156 |
| - if problem_label not in team_problem_team_map[team_id]: |
157 |
| - team_problem_team_map[team_id][problem_label] = random.choice(team_ids) |
158 |
| - team_id = team_problem_team_map[team_id][problem_label] |
| 175 | + if args.ignore_teamids: |
| 176 | + team_id = random.choice(team_ids) |
| 177 | + else: |
| 178 | + if team_id not in team_problem_team_map: |
| 179 | + team_problem_team_map[team_id] = dict() |
| 180 | + if problem_label not in team_problem_team_map[team_id]: |
| 181 | + team_problem_team_map[team_id][problem_label] = random.choice(team_ids) |
| 182 | + team_id = team_problem_team_map[team_id][problem_label] |
159 | 183 | else:
|
160 | 184 | team_id = submission['team_id']
|
161 | 185 |
|
|
0 commit comments