Skip to content

Commit d9545ee

Browse files
committed
feat: graph parses json according to frontend requirements
1 parent 4822b90 commit d9545ee

2 files changed

Lines changed: 23 additions & 3 deletions

File tree

evaluation_function/evaluation.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -617,13 +617,29 @@ def _err(msg: str) -> Result:
617617

618618
# ── parse & validate inputs ──────────────────────────────────────────
619619

620+
# Parse response (student's graph)
621+
response_dict = _to_dictish(response) or {}
622+
623+
# Check if response contains frontend pipe-delimited format and convert
624+
if is_frontend_format(response_dict):
625+
parsed_graph = parse_frontend_graph(response_dict)
626+
response_dict = {"graph": parsed_graph}
627+
620628
try:
621-
resp = Response.model_validate(_to_dictish(response) or {})
629+
resp = Response.model_validate(response_dict)
622630
except ValidationError as e:
623631
return _err(f"Invalid response schema: {e}")
624632

633+
# Parse answer (teacher's reference)
634+
answer_dict = _to_dictish(answer) or {}
635+
636+
# Check if answer contains frontend pipe-delimited format and convert
637+
if is_frontend_format(answer_dict):
638+
parsed_graph = parse_frontend_graph(answer_dict)
639+
answer_dict = {"graph": parsed_graph}
640+
625641
try:
626-
ans = Answer.model_validate(_to_dictish(answer) or {})
642+
ans = Answer.model_validate(answer_dict)
627643
except ValidationError as e:
628644
return _err(f"Invalid answer schema: {e}")
629645

@@ -633,7 +649,7 @@ def _err(msg: str) -> Result:
633649
except ValidationError as e:
634650
if ans.graph is None:
635651
return _err(
636-
"Testing: Invalid params schema. Expected e.g. "
652+
"Invalid params schema. Expected e.g. "
637653
"{'evaluation_type': 'connectivity'|'bipartite'|'graph_coloring'|...}. "
638654
f"Error: {e}"
639655
)

evaluation_function/schemas/graph.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
class Node(BaseModel):
1212
id: str = Field(..., description="Unique identifier for the node")
1313
label: Optional[str] = Field(None, description="Display label")
14+
x: Optional[float] = Field(None, description="X coordinate for visual display (not used in evaluation)")
15+
y: Optional[float] = Field(None, description="Y coordinate for visual display (not used in evaluation)")
1416

1517
class Config:
1618
extra = "allow"
@@ -31,6 +33,8 @@ class Graph(BaseModel):
3133
nodes: list[Node] = Field(..., description="List of nodes in the graph")
3234
edges: list[Edge] = Field(default_factory=list, description="List of edges")
3335
directed: bool = Field(False, description="Whether the graph is directed")
36+
weighted: bool = Field(False, description="Whether the graph is weighted (metadata only, not used in evaluation)")
37+
multigraph: bool = Field(False, description="Whether the graph allows multiple edges (metadata only, not used in evaluation)")
3438

3539
class Config:
3640
extra = "allow"

0 commit comments

Comments
 (0)