Skip to content
This repository was archived by the owner on Oct 23, 2023. It is now read-only.

Commit 71295a6

Browse files
committed
Implemented JSON ui for Terry-like tasks
1 parent 7e4bc5f commit 71295a6

5 files changed

Lines changed: 159 additions & 43 deletions

File tree

python/formats/terry_format.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
import os.path
44
import platform
55
import random
6-
from typing import Optional, List
7-
86
from task_maker.args import Arch, CacheMode, UIS
97
from task_maker.config import Config
108
from task_maker.formats import get_options, TerryTask, list_files, \
@@ -15,6 +13,7 @@
1513
from task_maker.uis.terry import TerryUIInterface
1614
from task_maker.uis.terry_curses_ui import TerryCursesUI
1715
from task_maker.uis.terry_finish_ui import TerryFinishUI
16+
from typing import Optional, List
1817

1918

2019
def get_extension(target_arch: Arch):
@@ -41,8 +40,8 @@ def get_manager(manager: str, target_arch: Arch,
4140
true and no managers are found, None is returned, otherwise an exception is
4241
raised.
4342
"""
44-
managers = list_files(
45-
["managers/%s.*" % manager], exclude=["managers/%s.*.*" % manager])
43+
managers = list_files(["managers/%s.*" % manager],
44+
exclude=["managers/%s.*.*" % manager])
4645
if len(managers) == 0:
4746
if not optional:
4847
raise FileNotFoundError("Missing manager: %s" % manager)
@@ -111,7 +110,9 @@ def evaluate_task(frontend: Frontend, task: TerryTask,
111110
"""
112111
Build the computation DAG and run it in order to test all the solutions.
113112
"""
114-
ui_interface = TerryUIInterface(task, config.ui == UIS.PRINT)
113+
ui_interface = TerryUIInterface(
114+
task, config.ui == UIS.PRINT or config.ui == UIS.JSON,
115+
config.ui == UIS.JSON)
115116
curses_ui = None
116117
finish_ui = None
117118
if config.ui == UIS.CURSES:
@@ -201,11 +202,13 @@ class TerryFormat(TaskFormat):
201202
"""
202203
Entry point for the terry format
203204
"""
205+
204206
@staticmethod
205207
def clean():
206208
"""
207209
Clean all the generated files: all the compiled managers.
208210
"""
211+
209212
def remove_file(path: str) -> None:
210213
try:
211214
os.remove(path)

python/tests/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,5 @@ bin/
1111

1212
*.linux.x86_64
1313
*.linux.i686
14+
15+
correttore

python/uis/__init__.py

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,23 @@ def generation(self,
483483
log += state
484484
self._print(log, state, data=data, cached=cached)
485485

486+
def terry_generation(self,
487+
solution: str,
488+
seed: int,
489+
state: str,
490+
data: str = None,
491+
cached: bool = False):
492+
if self.json:
493+
self._json("generation", state, {
494+
"solution": solution,
495+
"seed": seed
496+
}, data, cached)
497+
else:
498+
log = ("Generation of input for %s with seed %d " %
499+
(solution, seed)).ljust(50)
500+
log += state
501+
self._print(log, state, data=data, cached=cached)
502+
486503
def validation(self,
487504
testcase: int,
488505
subtask: int,
@@ -500,6 +517,19 @@ def validation(self,
500517
log += state
501518
self._print(log, state, data=data, cached=cached)
502519

520+
def terry_validation(self,
521+
solution: str,
522+
state: str,
523+
data: str = None,
524+
cached: bool = False):
525+
if self.json:
526+
self._json("validation", state, {"solution": solution}, data,
527+
cached)
528+
else:
529+
log = ("Validation of input for %s " % solution).ljust(50)
530+
log += state
531+
self._print(log, state, data=data, cached=cached)
532+
503533
def solving(self,
504534
testcase: int,
505535
subtask: int,
@@ -545,6 +575,18 @@ def evaluate(self,
545575
log = log.ljust(50) + state
546576
self._print(log, state, data=data, cached=cached)
547577

578+
def terry_evaluate(self,
579+
solution: str,
580+
state: str,
581+
data: str = None,
582+
cached: bool = False):
583+
if self.json:
584+
self._json("evaluate", state, {"solution": solution}, data, cached)
585+
else:
586+
log = ("Evaluate solution %s " % solution).ljust(50)
587+
log += state
588+
self._print(log, state, data=data, cached=cached)
589+
548590
def checking(self,
549591
solution: str,
550592
testcase: int,
@@ -564,6 +606,55 @@ def checking(self,
564606
log += state
565607
self._print(log, state, data=data, cached=cached)
566608

609+
def terry_checking(self,
610+
solution: str,
611+
state: str,
612+
data: str = None,
613+
cached: bool = False):
614+
if self.json:
615+
self._json("checking", state, {"solution": solution}, data, cached)
616+
else:
617+
log = ("Checking solution %s " % solution).ljust(50)
618+
log += state
619+
self._print(log, state, data=data, cached=cached)
620+
621+
def testcase_outcome(self, solution: str, testcase: int, subtask: int,
622+
info: "TestcaseSolutionInfo"):
623+
if self.json:
624+
self._json(
625+
"testcase-outcome", "success", {
626+
"solution": solution,
627+
"testcase": testcase,
628+
"subtask": subtask,
629+
"status": str(info.status).split(".")[-1],
630+
"score": info.score,
631+
"message": info.message
632+
})
633+
else:
634+
log = "Outcome of solution %s: score=%f message=%s" % (
635+
solution, info.score, info.message)
636+
self._print(log, "SUCCESS")
637+
638+
def terry_solution_outcome(self, solution: str, info: "SolutionInfo"):
639+
if self.json:
640+
self._json(
641+
"solution-outcome", "success", {
642+
"solution":
643+
solution,
644+
"status":
645+
str(info.status).split(".")[-1],
646+
"score":
647+
info.score,
648+
"message":
649+
info.message,
650+
"testcases":
651+
[str(s).split(".")[-1] for s in info.testcases_status]
652+
})
653+
else:
654+
log = "Outcome of solution %s: score=%f message=%s" % (
655+
solution, info.score, info.message)
656+
self._print(log, "SUCCESS")
657+
567658
def warning(self, message: str):
568659
if self.json:
569660
self._json("warning", "warning", {"message": message})

python/uis/ioi.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,9 @@ def getResultChecking(result: Result):
568568
cached=result.was_cached)
569569
self.testing[solution].update_default_check_result(
570570
subtask, testcase, result)
571+
self.ui_printer.testcase_outcome(
572+
solution, testcase, subtask,
573+
self.testing[solution].testcase_results[subtask][testcase])
571574

572575
def skippedChecking():
573576
self.ui_printer.checking(solution, testcase, subtask, "SKIPPED")
@@ -581,6 +584,9 @@ def getStderr(stderr):
581584
def customCheckerResult():
582585
self.testing[solution].update_custom_check_result(
583586
subtask, testcase, custom_checker_state)
587+
self.ui_printer.testcase_outcome(
588+
solution, testcase, subtask,
589+
self.testing[solution].testcase_results[subtask][testcase])
584590

585591
if has_custom_checker:
586592
custom_checker_state.set_callback(customCheckerResult)

0 commit comments

Comments
 (0)