Routen-Validierung: >15 km/h Ø zählt nicht für Stats/Trophäen, SW by-v331
This commit is contained in:
parent
b5e4eab84d
commit
7ac421fcf9
7 changed files with 40 additions and 16 deletions
|
|
@ -13,6 +13,14 @@ from routes.push import send_push_to_user
|
|||
|
||||
router = APIRouter()
|
||||
|
||||
_MAX_AVG_KMH = 15.0 # Über diesem Wert wird die Route nicht für Stats/Trophäen gewertet
|
||||
|
||||
def _check_speed(distanz_km, dauer_min) -> bool:
|
||||
"""True = gültig, False = zu schnell (wahrscheinlich motorisiert)."""
|
||||
if not distanz_km or not dauer_min or dauer_min <= 0:
|
||||
return True
|
||||
return (distanz_km / (dauer_min / 60)) <= _MAX_AVG_KMH
|
||||
|
||||
|
||||
def _haversine(lat1: float, lon1: float, lat2: float, lon2: float) -> float:
|
||||
R = 6_371_000
|
||||
|
|
@ -135,26 +143,30 @@ async def create_route(data: RouteCreate, user=Depends(get_current_user)):
|
|||
if len(data.gps_track) < 2:
|
||||
raise HTTPException(400, "GPS-Track braucht mindestens 2 Punkte.")
|
||||
|
||||
gps_json = json.dumps([p.model_dump() for p in data.gps_track])
|
||||
gps_json = json.dumps([p.model_dump() for p in data.gps_track])
|
||||
is_valid = int(_check_speed(data.distanz_km, data.dauer_min))
|
||||
|
||||
with db() as conn:
|
||||
cur = conn.execute("""
|
||||
INSERT INTO routes
|
||||
(user_id, name, beschreibung, gps_track, distanz_km, dauer_min,
|
||||
schwierigkeit, untergrund, schatten, leine_empfohlen, is_public, hunde_tauglichkeit)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
schwierigkeit, untergrund, schatten, leine_empfohlen, is_public,
|
||||
hunde_tauglichkeit, is_valid)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
""", (
|
||||
user['id'], data.name, data.beschreibung, gps_json,
|
||||
data.distanz_km, data.dauer_min, data.schwierigkeit, data.untergrund,
|
||||
int(data.schatten) if data.schatten is not None else None,
|
||||
int(data.leine_empfohlen) if data.leine_empfohlen is not None else None,
|
||||
int(data.is_public) if data.is_public is not None else 1,
|
||||
data.hunde_tauglichkeit,
|
||||
data.hunde_tauglichkeit, is_valid,
|
||||
))
|
||||
row = conn.execute("SELECT * FROM routes WHERE id = ?", (cur.lastrowid,)).fetchone()
|
||||
update_streak(user['id'], conn)
|
||||
check_and_award(user['id'], conn)
|
||||
return _parse(row)
|
||||
result = _parse(row)
|
||||
result['is_valid'] = bool(is_valid)
|
||||
return result
|
||||
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue