Auto-update: Fri Nov 15 15:00:14 PST 2024

This commit is contained in:
sanj 2024-11-15 15:00:14 -08:00
parent 2ed65c0960
commit fb803a8af7

View file

@ -128,14 +128,14 @@ async def generate_and_save_heatmap(
start_date: Union[str, int, datetime], start_date: Union[str, int, datetime],
end_date: Optional[Union[str, int, datetime]] = None, end_date: Optional[Union[str, int, datetime]] = None,
output_path: Optional[Path] = None output_path: Optional[Path] = None
) -> Path: ) -> Optional[Path]:
""" """
Generate a heatmap for the given date range and save it as a PNG file. Generate a heatmap for the given date range and save it as a PNG file.
:param start_date: The start date for the map (or the only date if end_date is not provided) :param start_date: The start date for the map (or the only date if end_date is not provided)
:param end_date: The end date for the map (optional) :param end_date: The end date for the map (optional)
:param output_path: The path to save the PNG file (optional) :param output_path: The path to save the PNG file (optional)
:return: The path where the PNG file was saved :return: The path where the PNG file was saved, or None if no locations found
""" """
try: try:
from staticmap import StaticMap, CircleMarker from staticmap import StaticMap, CircleMarker
@ -149,7 +149,7 @@ Generate a heatmap for the given date range and save it as a PNG file.
locations = await fetch_locations(start_date, end_date) locations = await fetch_locations(start_date, end_date)
if not locations: if not locations:
raise ValueError("No locations found for the given date range") return None
# Calculate bounds # Calculate bounds
lats = [loc.latitude for loc in locations] lats = [loc.latitude for loc in locations]
@ -157,10 +157,10 @@ Generate a heatmap for the given date range and save it as a PNG file.
lat_diff = max(lats) - min(lats) lat_diff = max(lats) - min(lats)
lon_diff = max(lons) - min(lons) lon_diff = max(lons) - min(lons)
# Calculate zoom level using system config # If all points at same location, use default zoom
zoom = min( zoom = 12 if (lat_diff == 0 and lon_diff == 0) else min(
Gis.map.max_zoom, Gis.map.max_zoom,
int(math.log2(360 / max(lat_diff, lon_diff))) - 1 int(math.log2(360 / max(0.01, lat_diff, lon_diff))) - 1
) )
# Create map with correct URL template # Create map with correct URL template
@ -193,7 +193,6 @@ 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): async def generate_map(start_date: datetime, end_date: datetime, max_points: int):
locations = await fetch_locations(start_date, end_date) locations = await fetch_locations(start_date, end_date)
if not locations: if not locations: