Auto-update: Fri Nov 15 14:45:24 PST 2024

This commit is contained in:
sanj 2024-11-15 14:45:24 -08:00
parent eef08fd4c5
commit 1104a11c9c

View file

@ -125,10 +125,10 @@ async def get_last_location() -> Optional[Location]:
async def generate_and_save_heatmap(
start_date: Union[str, int, datetime],
end_date: Optional[Union[str, int, datetime]] = None,
output_path: Optional[Path] = None
) -> Path:
start_date: Union[str, int, datetime],
end_date: Optional[Union[str, int, datetime]] = None,
output_path: Optional[Path] = None
) -> Path:
"""
Generate a heatmap for the given date range and save it as a PNG file.
@ -157,18 +157,20 @@ Generate a heatmap for the given date range and save it as a PNG file.
lat_diff = max(lats) - min(lats)
lon_diff = max(lons) - min(lons)
# Calculate zoom level - lower number = more zoomed out
# Calculate zoom level using system config
zoom = min(
Gis.map.max_zoom,
int(math.log2(360 / max(lat_diff, lon_diff))) - 1
)
# Create map with correct URL template and zoom
# Create map with correct URL template
m = StaticMap(
640, 360,
url_template='https://cartodb-basemaps-a.global.ssl.fastly.net/dark_all/{z}/{x}/{y}.png',
zoom=zoom
url_template='https://cartodb-basemaps-a.global.ssl.fastly.net/dark_all/{z}/{x}/{y}.png'
)
# Set zoom level after creation
m.zoom = zoom
# Add markers with heat effect
for loc in locations:
@ -191,6 +193,7 @@ Generate a heatmap for the given date range and save it as a PNG file.
async def generate_map(start_date: datetime, end_date: datetime, max_points: int):
locations = await fetch_locations(start_date, end_date)
if not locations: