Last active
December 28, 2024 11:06
-
-
Save cubercsl/43bfc8d95bc1b31313e02b266e7738f9 to your computer and use it in GitHub Desktop.
Useful domjudge scripts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"allow_team_submission_download": true, | |
"auth_methods": [ | |
"ipaddress" | |
], | |
"clar_answers": [ | |
"No comment.", | |
"Read the problem statement carefully." | |
], | |
"clar_categories": { | |
"general": "General issue", | |
"tech": "Technical issue" | |
}, | |
"clar_default_problem_queue": "", | |
"clar_queues": [], | |
"compile_penalty": false, | |
"data_source": 1, | |
"default_compare": "compare", | |
"default_full_debug": "full_debug", | |
"default_run": "run", | |
"diskspace_error": 1048576, | |
"enable_parallel_judging": 1, | |
"event_feed_format": 1, | |
"external_ccs_submission_url": "", | |
"external_contest_source_critical": 120, | |
"icat_url": "", | |
"ip_autologin": 1, | |
"judgehost_activated_by_default": true, | |
"judgehost_critical": 120, | |
"judgehost_warning": 30, | |
"lazy_eval_results": 1, | |
"memory_limit": 2097152, | |
"output_display_limit": 2000, | |
"output_limit": 8192, | |
"output_storage_limit": 2000, | |
"penalty_time": 20, | |
"print_command": "domjuge-print [file] [original] [language] [username] [teamname] [teamid] [location]", | |
"process_limit": 64, | |
"results_prio": { | |
"correct": 1, | |
"memory-limit": 99, | |
"no-output": 99, | |
"output-limit": 99, | |
"run-error": 99, | |
"timelimit": 99, | |
"wrong-answer": 99 | |
}, | |
"results_remap": { | |
"no-output": "wrong-answer", | |
"output-limit": "wrong-answer" | |
}, | |
"score_in_seconds": false, | |
"script_filesize_limit": 2621440, | |
"script_memory_limit": 2097152, | |
"script_timelimit": 30, | |
"show_affiliation_logos": 1, | |
"show_affiliations": true, | |
"show_balloons_postfreeze": false, | |
"show_compile": 2, | |
"show_flags": 0, | |
"show_limits_on_team_page": true, | |
"show_pending": true, | |
"show_public_stats": true, | |
"show_relative_time": 1, | |
"show_sample_output": false, | |
"show_teams_submissions": true, | |
"sourcefiles_limit": 1, | |
"sourcesize_limit": 256, | |
"team_column_width": 0, | |
"thumbnail_size": 200, | |
"time_format": "H:i", | |
"timelimit_overshoot": "1s|10%", | |
"verification_required": false | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# SPDX-License-Identifier: MIT | |
import argparse | |
import csv | |
import json | |
import os | |
from pathlib import Path | |
COUNTRY_REMAP = { | |
'CN': 'CHN', | |
'HK': 'HKG', | |
'MO': 'MAC', | |
} | |
def generate(team_tsv: Path, ip_tsv: Path, icpc_school: Path, output_path: Path): | |
groups = [] | |
teams = [] | |
organization = [] | |
accounts = [] | |
affiliations = {} | |
total_affiliations = 1 | |
cds_video_config = [] | |
group_map = { | |
'正式队伍': 'participants', | |
'打星队伍': 'observers', | |
} | |
groups.append(dict(id='participants', name='正式队伍', sortorder=0)) | |
groups.append(dict(id='observers', name='打星队伍', sortorder=0, color='#ffcc33')) | |
if icpc_school.exists(): | |
icpc_school_map = {school['name']['zh']: school for school in json.loads(icpc_school.read_text())} | |
else: | |
icpc_school_map = [] | |
if ip_tsv is not None: | |
ip_map = {row['location']: row['ip'] for row in csv.DictReader(open(ip_tsv))} | |
else: | |
ip_map = {} | |
with open(team_tsv, 'r') as f: | |
for school_name in sorted(list({line['school_name'] for line in csv.DictReader(f, delimiter='\t')})): | |
if school_name not in affiliations: | |
if school_name in icpc_school_map: | |
affiliations[school_name] = 'icpc-%05d' % icpc_school_map[school_name]['id'] | |
country = icpc_school_map[school_name]['country'] | |
else: | |
affiliations[school_name] = 'inst-%05d' % total_affiliations | |
total_affiliations += 1 | |
country = 'CN' | |
print(f'Warning: {school_name} not found in icpc_school.json') | |
org = dict( | |
id=affiliations[school_name], | |
name=school_name, | |
formal_name=school_name, | |
country=COUNTRY_REMAP.get(country, country), | |
) | |
organization.append(org) | |
with open(team_tsv, 'r') as f: | |
for line in csv.DictReader(f, delimiter='\t'): | |
school_name, team_name, member1, member2, member3, coach, location = \ | |
line['school_name'], line['team_name'], \ | |
line['member1'], line['member2'], line['member3'], line['coach'], \ | |
line['location'] | |
team_type = '正式队伍' if not team_name.startswith('⭐') else '打星队伍' | |
team_id = location | |
members = [] | |
if member1: members.append(member1) | |
if member2: members.append(member2) | |
if member3: members.append(member3) | |
if coach: members.append(f'{coach}(教练)') | |
teams.append( | |
dict( | |
id=team_id, | |
name=team_name.lstrip('⭐'), | |
display_name=team_name, | |
organization_id=affiliations[school_name], | |
room=location, | |
members=', '.join(members), | |
group_ids = [group_map[team_type]] | |
) | |
) | |
account = dict( | |
id=team_id, | |
name=team_name, | |
username=location, | |
team_id=team_id, | |
type='team', | |
) | |
if ip := ip_map.get(location): | |
account['ip'] = ip | |
cds_video_config.append(f'<video id="{team_id}" desktop="http://{ip}:9090" webcam="http://{ip}:8080" />') | |
else: | |
print(f'Warning: {team_id} has no ip address') | |
accounts.append(account) | |
accounts.append( | |
dict( | |
id='balloon', | |
name='Balloon Printer', | |
username='balloon', | |
type='balloon' | |
) | |
) | |
accounts.append( | |
dict( | |
id='jury', | |
name='Jury', | |
username='jury', | |
type='judge' | |
) | |
) | |
organization.sort(key=lambda x: x['id']) | |
teams.sort(key=lambda x: x['id']) | |
accounts.sort(key=lambda x: x['id']) | |
os.makedirs(output_path, exist_ok=True) | |
print(f'Writing to {output_path}') | |
(output_path / 'groups.json').write_text(json.dumps(groups, indent=2, ensure_ascii=False)) | |
(output_path / 'organizations.json').write_text(json.dumps(organization, indent=2, ensure_ascii=False)) | |
(output_path / 'teams.json').write_text(json.dumps(teams, indent=2, ensure_ascii=False)) | |
(output_path / 'accounts.json').write_text(json.dumps(accounts, indent=2, ensure_ascii=False)) | |
(output_path / 'cds_video_config.xml').write_text('\n'.join(cds_video_config)) | |
if __name__ == '__main__': | |
argparser = argparse.ArgumentParser() | |
argparser.add_argument('team', type=Path) | |
argparser.add_argument('--ip', type=Path, dest='ip_tsv', nargs='?') | |
argparser.add_argument('--school', type=Path, dest='icpc_school', nargs='?') | |
argparser.add_argument('-o', type=Path, dest='output_path', default=Path().cwd()) | |
args = argparser.parse_args() | |
generate(args.team, args.ip_tsv, args.icpc_school, args.output_path) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash -e | |
if [ $# -lt 7 ]; then | |
echo "😠 Something went wrong." | |
echo "💬 Please contact the contest staff." | |
echo "Error: not enough arguments" >&2 | |
echo "Usage: $0 <filename> <origname> <language> <username> <teamname> <teamid> <location>" >&2 | |
echo "Set print command to: $0 [file] [original] [language] [username] [teamname] [teamid] [location]" >&2 | |
exit 1 | |
fi | |
if command -v isutf8 >/dev/null 2>&1; then | |
if ! isutf8 -v "$1"; then | |
echo "🥵 File is not UTF-8 encoded." | |
echo "💬 Please save it as UTF-8 and try again." | |
exit 1 | |
fi | |
fi | |
PRINT_SERVER=https://print.ecfinal.icpc/ | |
filename=$1; shift | |
origname=$1; shift | |
language=$1; shift | |
username=$1; shift | |
teamname=$1; shift | |
teamid=$1; shift | |
location=$1; shift | |
echo "📄 Filename: $origname" | |
echo "🔡 Language: $language" | |
echo "👤 User Name: $username" | |
[ -n "$teamname" ] && echo "👥 Team Name: $teamname" || teamname="$username" | |
[ -n "$teamid" ] && echo "🆔 Team ID: $teamid" | |
[ -n "$location" ] && echo "💺 Location: $location" | |
exec curl -fsS \ | |
-F file=@"$filename" \ | |
-F filename="$origname" \ | |
-F lang="$language" \ | |
-F tname="$teamname" \ | |
-F team="$teamid" \ | |
-F location="$location" \ | |
$PRINT_SERVER 2>&1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import sys | |
import json | |
from pathlib import Path | |
from collections import Counter | |
def main(): | |
if len(sys.argv) != 2: | |
print(f"Usage: {sys.argv[0]} <path>") | |
sys.exit(1) | |
event_feed = Path(sys.argv[1]) | |
if not event_feed.exists(): | |
print(f"Error: {event_feed} not found") | |
sys.exit(1) | |
events = event_feed.read_text().splitlines() | |
event_counter = Counter() | |
total_events = 0 | |
send_judging_events = set() | |
for event in events: | |
event_data = json.loads(event) | |
event_counter[event_data['type']] += 1 | |
total_events += 1 | |
if event_data['type'] == 'runs': | |
continue | |
if event_data['type'] == 'judgements': | |
if event_data['id'] in send_judging_events: | |
# We want to set the endtime and max runtime only once (once the verdict is known) | |
continue | |
if event_data['data']['judgement_type_id'] is not None and event_data['data']['end_time'] is not None: | |
send_judging_events.add(event_data['id']) | |
print(json.dumps(event_data, ensure_ascii=False)) | |
print(f"Total events: {total_events}", file=sys.stderr) | |
print(f"Runs: {event_counter['runs']}", file=sys.stderr) | |
print(f"Submissions: {event_counter['submissions']}", file=sys.stderr) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment