[locations] Add distance and speed calculations
This commit is contained in:
@ -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,
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user