Fix gps coords

This commit is contained in:
Leonardo Segala 2025-08-02 09:05:30 +02:00
parent f3101ad8ab
commit b7aebadffe
3 changed files with 12 additions and 8 deletions

View file

@ -85,7 +85,9 @@ def join():
if room.pin is not None and room.pin != code:
return error("Invalid code")
if room.distance > room.range_size:
distance = distance_between_coords(room.coord, Coordinates(latitude=int(request.args["lat"]), longitude=int(request.args["lot"])))
if distance > room.range_size:
return error("You are not within the room range")
return {"success": True, "ws": f"/ws/{room_id}"}
@ -145,7 +147,7 @@ def room_new():
room = Room(
id=max(state.rooms or [0]) + 1, #
coord=(float(lat), float(lon)),
coord=Coordinates(int(lat), int(lon)),
range_size=int(room_range),
name=room_name,
pin=room_pin,
@ -165,12 +167,12 @@ def room_new():
def room():
lat = request.args.get("lat")
lon = request.args.get("lon")
if lat and lon:
user_coords = Coordinates(latitude=float(lat), longitude=float(lon))
user_coords = Coordinates(latitude=int(lat), longitude=int(lon))
else:
return error("Missing user coordinates")
distance = distance_between_coords(user_coords, room.coord)
return [
{
"id": room.id,
@ -178,10 +180,10 @@ def room():
"private": room.pin is not None,
"coords": room.coord,
"range": room.range_size,
"distance": distance,
"distance": d,
}
for room in state.rooms.values()
if distance <= room.range_size
if (d := distance_between_coords(user_coords, room.coord)) <= room.range_size
]

View file

@ -1,6 +1,8 @@
import math
from dataclasses import dataclass
@dataclass
class Coordinates:
latitude: int
longitude: int

View file

@ -1,6 +1,7 @@
import random
from dataclasses import dataclass
from gps import Coordinates
from song import Song
USER_SCORE_WEIGHT = 0.7
@ -30,12 +31,11 @@ class Rank:
@dataclass
class Room:
id: int
coord: tuple[float, float]
coord: Coordinates
name: str
pin: int | None
tags: set[str]
range_size: int # in meters ??
distance: float
songs: dict[str, UserScoredSong] # all songs + user score (the playlist)
history: list[Song] # all songs previously played