Fix scrobbling of locations

This commit is contained in:
2023-11-24 15:41:10 +01:00
parent 49e4e9b69a
commit 880f810aa1
3 changed files with 12 additions and 14 deletions

View File

@ -55,17 +55,9 @@ class GeoLocation(ScrobblableMixin):
logger.error("No lat or lon keys in data dict")
return
lat_int, lat_places = data_dict.get("lat", "").split(".")
lon_int, lon_places = data_dict.get("lon", "").split(".")
alt_int, alt_places = data_dict.get("alt", "").split(".")
truncated_lat = lat_places[0:5]
truncated_lon = lon_places[0:5]
truncated_alt = alt_places[0:3]
data_dict["lat"] = float(".".join([lat_int, truncated_lat]))
data_dict["lon"] = float(".".join([lon_int, truncated_lon]))
data_dict["altitude"] = float(".".join([alt_int, truncated_alt]))
data_dict["lat"] = float(data_dict.get("lat", ""))
data_dict["lon"] = float(data_dict.get("lon", ""))
data_dict["altitude"] = float(data_dict.get("alt", ""))
location = cls.objects.filter(
lat=data_dict.get("lat"),

View File

@ -6,7 +6,7 @@ from scrobbles.stats import get_scrobble_count_qs
class GeoLocationListView(generic.ListView):
model = GeoLocation
paginate_by = 200
paginate_by = 75
def get_queryset(self):
return super().get_queryset().order_by("-created")

View File

@ -630,8 +630,14 @@ class Scrobble(TimeStampedModel):
if self.media_obj.__class__.__name__ in ["GeoLocation"]:
logger.info(f"Calculate proximity to last scrobble")
if self.previous:
same_lat = self.previous.media_obj.lat == self.media_obj.lat
same_lon = self.previous.media_obj.lon == self.media_obj.lon
same_lat = (
self.previous.media_obj.truncated_lat
== self.media_obj.truncated_lat
)
same_lon = (
self.previous.media_obj.truncated_lon
== self.media_obj.truncated_lon
)
if same_lat and same_lon: # We have moved
logger.info("Yes - We're in the same place!")
updatable = True