|
@@ -1,4 +1,4 @@
|
|
|
-from typing import List
|
|
|
+from typing import List, Optional
|
|
|
|
|
|
from fastapi import APIRouter, Depends
|
|
|
from fastapi_camelcase import CamelModel
|
|
@@ -7,7 +7,7 @@ from pydantic import confloat
|
|
|
from sqlalchemy.orm import Session
|
|
|
|
|
|
from .. import scoring
|
|
|
-from ..schemas import CacheInfo, GeneratorInfo
|
|
|
+from ..schemas import CacheInfo, GameConfig, GeneratorInfo, ScoreMethodEnum
|
|
|
from ..db import get_db, queries
|
|
|
from ..point_gen import points, generator_info
|
|
|
|
|
@@ -22,6 +22,8 @@ class Point(CamelModel):
|
|
|
class ScoreCheck(CamelModel):
|
|
|
point1: Point
|
|
|
point2: Point
|
|
|
+ score_method: Optional[ScoreMethodEnum] = None
|
|
|
+ round_number: Optional[int] = None
|
|
|
|
|
|
|
|
|
class Score(CamelModel):
|
|
@@ -47,8 +49,25 @@ def health():
|
|
|
|
|
|
|
|
|
@router.post("/score", response_model=Score)
|
|
|
-def check_score(points: ScoreCheck):
|
|
|
- score, distance = scoring.score((points.point1.lat, points.point1.lng), (points.point2.lat, points.point2.lng))
|
|
|
+def check_score(check: ScoreCheck):
|
|
|
+ match check.score_method:
|
|
|
+ case ScoreMethodEnum.country_race:
|
|
|
+ # TODO is there a way to make this more well-defined?
|
|
|
+ return Score(distance=0, score=0)
|
|
|
+ case ScoreMethodEnum.hard:
|
|
|
+ score, distance = scoring.score_hard((check.point1.lat, check.point1.lng), (check.point2.lat, check.point2.lng))
|
|
|
+ case ScoreMethodEnum.nightmare:
|
|
|
+ score, distance = scoring.score_nightmare((check.point1.lat, check.point1.lng), (check.point2.lat, check.point2.lng))
|
|
|
+ case ScoreMethodEnum.ramp:
|
|
|
+ score, distance = scoring.score((check.point1.lat, check.point1.lng), (check.point2.lat, check.point2.lng))
|
|
|
+ if check.round_number is not None:
|
|
|
+ score *= 1 + ((check.round_number - 1) * 0.5)
|
|
|
+ case ScoreMethodEnum.ramp_hard:
|
|
|
+ score, distance = scoring.score_hard((check.point1.lat, check.point1.lng), (check.point2.lat, check.point2.lng))
|
|
|
+ if check.round_number is not None:
|
|
|
+ score *= 1 + ((check.round_number - 1) * 0.5)
|
|
|
+ case _:
|
|
|
+ score, distance = scoring.score((check.point1.lat, check.point1.lng), (check.point2.lat, check.point2.lng))
|
|
|
return Score(distance=distance, score=score)
|
|
|
|
|
|
|