79484480

Date: 2025-03-04 17:49:38
Score: 1.5
Natty:
Report link

To detail what I said in the comment, the solution would look like this:

score_analysis.py

from dataclasses import dataclass, field

from .json_serialization import *
from .domain import *


class MatchAnalysisDTO(JsonDomainBase):
    name: str
    score: Annotated[HardSoftDecimalScore, ScoreSerializer]
    justification: object


class ConstraintAnalysisDTO(JsonDomainBase):
    name: str
    weight: Annotated[HardSoftDecimalScore, ScoreSerializer]
    matches: list[MatchAnalysisDTO]
    score: Annotated[HardSoftDecimalScore, ScoreSerializer]

rest_api.py

async def setup_context(request: Request) -> EmployeeSchedule:
    json = await request.json()
    return EmployeeSchedule.model_validate_json(json)

@app.put("/schedules/analyze")
async def analyze_timetable(employee_schedule: Annotated[EmployeeSchedule, Depends(setup_context)]) -> dict:
    return {'constraints': [ConstraintAnalysisDTO(
        name=constraint.constraint_name,
        weight=constraint.weight,
        score=constraint.score,
        matches=[
            MatchAnalysisDTO(
                name=match.constraint_ref.constraint_name,
                score=match.score,
                justification=match.justification
            )
            for match in constraint.matches
        ]
    ) for constraint in solution_manager.analyze(employee_schedule).constraint_analyses]}

Note: This is an example of a solution. Adapt it for your needs.

Please let me know if this was useful.

Reasons:
  • RegEx Blacklisted phrase (2.5): Please let me know
  • Long answer (-1):
  • Has code block (-0.5):
  • Low reputation (0.5):
Posted by: Diallo Francis Patrick