Skip to content

Commit

Permalink
[italy_yaml] Load all contest parameters from contest.yaml
Browse files Browse the repository at this point in the history
  • Loading branch information
Virv12 committed Nov 6, 2024
1 parent 078bbf6 commit afeb4de
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions cmscontrib/loaders/italy_yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,11 @@ def load(src, dst, src_name, dst_name=None, conv=lambda i: i):


def parse_datetime(val):
if isinstance(val, datetime):
return val.astimezone(timezone.utc)
if isinstance(val, (int, float)):
return datetime.fromtimestamp(val, timezone.utc)
return datetime.fromisoformat(val)
raise ValueError("Invalid datetime format.")


def make_timedelta(t):
Expand Down Expand Up @@ -173,11 +175,26 @@ def get_contest(self):

args = {}

# Contest information
load(conf, args, ["name", "nome_breve"])
load(conf, args, ["description", "nome"])
load(conf, args, "allowed_localizations")
load(conf, args, "languages")
load(conf, args, "submissions_download_allowed")
load(conf, args, "allow_questions")
load(conf, args, "allow_user_tests")
load(conf, args, "score_precision")

logger.info("Loading parameters for contest %s.", args["name"])

# Logging in
load(conf, args, "block_hidden_participations")
load(conf, args, "allow_password_authentication")
load(conf, args, "allow_registration")
load(conf, args, "ip_restriction")
load(conf, args, "ip_autologin")

# Token parameters
# Use the new token settings format if detected.
if "token_mode" in conf:
load(conf, args, "token_mode")
Expand Down Expand Up @@ -219,16 +236,23 @@ def get_contest(self):
if args["token_gen_interval"].total_seconds() == 0:
args["token_gen_interval"] = timedelta(minutes=1)

# Times
load(conf, args, ["start", "inizio"], conv=parse_datetime)
load(conf, args, ["stop", "fine"], conv=parse_datetime)
load(conf, args, ["per_user_time"], conv=make_timedelta)
load(conf, args, ["timezone"])
load(conf, args, ["per_user_time"], conv=make_timedelta)

# Limits
load(conf, args, "max_submission_number")
load(conf, args, "max_user_test_number")
load(conf, args, "min_submission_interval", conv=make_timedelta)
load(conf, args, "min_user_test_interval", conv=make_timedelta)

# Analysis mode
load(conf, args, "analysis_enabled")
load(conf, args, "analysis_start", conv=parse_datetime)
load(conf, args, "analysis_stop", conv=parse_datetime)

tasks = load(conf, None, ["tasks", "problemi"])
participations = load(conf, None, ["users", "utenti"])
participations = [] if participations is None else participations
Expand Down

0 comments on commit afeb4de

Please sign in to comment.