[locations] Add distance and speed calculations
All checks were successful
build & deploy / test (push) Successful in 1m57s
build & deploy / deploy (push) Successful in 27s

This commit is contained in:
2026-05-01 11:50:24 -04:00
parent acf0c342bf
commit de733d5893
6 changed files with 340 additions and 2 deletions

View File

@ -1034,6 +1034,8 @@ def manual_scrobble_twitch_channel(
def gpslogger_scrobble_location(data_dict: dict, user_id: int) -> Scrobble:
from locations.utils import detect_movement
location = GeoLocation.find_or_create(data_dict)
timestamp = pendulum.parse(data_dict.get("time", timezone.now()))
@ -1052,6 +1054,24 @@ def gpslogger_scrobble_location(data_dict: dict, user_id: int) -> Scrobble:
provider = LOCATION_PROVIDERS[data_dict.get("prov")]
# Store GPS data in log
if "gps_data" not in scrobble.log.keys():
scrobble.log["gps_data"] = {}
gps_data = {
"speed": data_dict.get("speed"),
"accuracy": data_dict.get("accuracy"),
"direction": data_dict.get("direction"),
"activity": data_dict.get("activity"),
"provider": provider,
"battery": data_dict.get("battery"),
}
scrobble.log["gps_data"] = gps_data
# Run movement detection using utils function
movement_data = detect_movement(scrobble)
scrobble.log["movement_detection"] = movement_data
if "gps_updates" not in scrobble.log.keys():
scrobble.log["gps_updates"] = []
@ -1076,6 +1096,7 @@ def gpslogger_scrobble_location(data_dict: dict, user_id: int) -> Scrobble:
"timestamp": extra_data.get("timestamp"),
"raw_timestamp": data_dict.get("time"),
"media_type": Scrobble.MediaType.GEO_LOCATION,
"movement_data": movement_data,
},
)