Last active
May 23, 2024 13:00
-
-
Save cubercsl/43bfc8d95bc1b31313e02b266e7738f9 to your computer and use it in GitHub Desktop.
Useful domjudge scripts
This file contains 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 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 | |
import re | |
from pathlib import Path | |
def country_matcher(name: str) -> str: | |
HKG = re.compile(r'^香港.*大學$|^香港.*大学$') | |
if HKG.match(name): | |
return 'HKG' | |
return 'CHN' | |
def generate(team_tsv: Path, ip_tsv: Path, school_domain: 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')) | |
school_domain_map = json.load(open(school_domain)) if school_domain else {} | |
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 school_domain_map: | |
affiliations[school_name] = school_domain_map[school_name].replace('.', '-') | |
else: | |
affiliations[school_name] = 'inst-%03d' % total_affiliations | |
total_affiliations += 1 | |
organization.append( | |
dict( | |
id=affiliations[school_name], | |
name=school_name, | |
formal_name=school_name, | |
country=country_matcher(school_name), | |
) | |
) | |
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' | |
) | |
) | |
for name, orignization_id in affiliations.items(): | |
organization.append( | |
dict( | |
id=orignization_id, | |
name=name, | |
formal_name=name, | |
country=country_matcher(name), | |
) | |
) | |
organization.sort(key=lambda x: x['id'] if not x['id'].startswith('inst-') else 'zzz' + 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}') | |
json.dump(groups, open(output_path / 'groups.json', 'w'), indent=2, ensure_ascii=False) | |
json.dump(organization, open(output_path / 'organizations.json', 'w'), indent=2, ensure_ascii=False) | |
json.dump(teams, open(output_path / 'teams.json', 'w'), indent=2, ensure_ascii=False) | |
json.dump(accounts, open(output_path / 'accounts.json', 'w'), indent=2, ensure_ascii=False) | |
print('\n'.join(cds_video_config),file=open(output_path / 'cds_video_config.xml', 'w')) | |
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='school_domain', nargs='?') | |
argparser.add_argument('-o', type=Path, dest='output_path', default=Path().cwd()) | |
args = argparser.parse_args() | |
generate(args.team, args.ip_tsv, args.school_domain, args.output_path) |
This file contains 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 | |
# SPDX-License-Identifier: MIT | |
if [ $# -lt 7 ]; then | |
echo "Something went wrong. 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 | |
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 "Username: $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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment