-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproblem_config.py
More file actions
80 lines (69 loc) · 3.19 KB
/
problem_config.py
File metadata and controls
80 lines (69 loc) · 3.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import yaml
class Limits:
def __init__(self, **kwargs):
self.time_multiplier = kwargs.get('time_multiplier', 5)
self.time_safety_margin = kwargs.get('time_safety_margin', 2)
self.memory = kwargs.get('memory', 1024)
self.output = kwargs.get('output', 8)
self.code = kwargs.get('code', 128)
self.compilation_time = kwargs.get('compilation_time', 60)
self.compilation_memory = kwargs.get('compilation_memory', 1024)
self.validation_time = kwargs.get('validation_time', 60)
self.validation_memory = kwargs.get('validation_memory', 1024)
self.validation_output = kwargs.get('validation_output', 8)
self.time_limit = None
def __str__(self):
lines = []
if self.time_limit:
lines.append(f"- Time Limit: {self.time_limit} seconds")
lines.append(f"- Memory Limit: {self.memory} MiB")
lines.append(f"- Output Limit: {self.output} KiB")
lines.append(f"- Code Limit: {self.code} KiB")
lines.append(f"- Compilation Time Limit: {self.compilation_time} seconds")
return '\n'.join(lines)
class ProblemConfig:
def __init__(self, *, name, **kwargs):
self.name = name
self.license = kwargs.get('license', 'unknown')
self.rights_owner = kwargs.get('rights_owner', kwargs.get('author', "") or kwargs.get('source', ""))
self.author = kwargs.get('author', "")
self.source = kwargs.get('source', "")
self.type = kwargs.get('type', 'pass-fail')
self.validation = kwargs.get('validation', 'default')
validator_flags = kwargs.get('validator_flags', "")
output_validator_flags = kwargs.get('output_validator_flags', "")
if validator_flags is None:
validator_flags = ""
if output_validator_flags is None:
output_validator_flags = ""
self.validator_flags = validator_flags.split() + output_validator_flags.split()
self.languages = kwargs.get('languages', None)
if self.languages is not None:
self.languages = set(self.languages.split())
self.limits = Limits(**kwargs.get('limits', {}))
def language_allowed(self, language_id):
return self.languages is None or language_id in self.languages
def __str__(self):
lines = []
if self.name:
lines.append(f"- Name: {self.name}")
if self.rights_owner and self.rights_owner != self.author and self.rights_owner != self.source:
lines.append(f"- Rights owner: {self.rights_owner}")
if self.source:
lines.append(f"- Source: {self.source}")
if self.author:
authors = self.author.split(',')
if len(self.author) == 1:
lines.append(f"- Author: {authors[0]}")
else:
lines.append(f"- Authors:")
for author in authors:
author = author.strip()
lines.append(f" - {author}")
lines.append(str(self.limits))
return '\n'.join(lines)
def load_problem_config(filename):
config = {}
with open(filename) as config_file:
config = yaml.safe_load(config_file)
return ProblemConfig(**config)