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

View file

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