Auto-update: Fri Nov 15 14:40:39 PST 2024
This commit is contained in:
parent
a6c8480322
commit
76c725a250
3 changed files with 22 additions and 5 deletions
|
@ -28,6 +28,7 @@ Db = Database.init('sys') # load configuration from config/sys.yaml
|
||||||
Dir = DirConfig.init('dirs') # load configuration from config/dirs.yaml
|
Dir = DirConfig.init('dirs') # load configuration from config/dirs.yaml
|
||||||
|
|
||||||
# Load module configurations
|
# Load module configurations
|
||||||
|
Gis = Config.init('gis', 'secrets', Dir)
|
||||||
Img = Config.init('img', 'secrets', Dir)
|
Img = Config.init('img', 'secrets', Dir)
|
||||||
Llm = Config.init('llm', 'secrets', Dir)
|
Llm = Config.init('llm', 'secrets', Dir)
|
||||||
News = Config.init('news', 'secrets', Dir)
|
News = Config.init('news', 'secrets', Dir)
|
||||||
|
|
|
@ -4,6 +4,9 @@ custom_locations:
|
||||||
longitude: -123.049396
|
longitude: -123.049396
|
||||||
radius: 2
|
radius: 2
|
||||||
|
|
||||||
|
map:
|
||||||
|
max_zoom: 11
|
||||||
|
|
||||||
layers:
|
layers:
|
||||||
- url: "https://gis.blm.gov/arcgis/rest/services/Cadastral/BLM_Natl_PLSS_CadNSDI/MapServer/1/query"
|
- url: "https://gis.blm.gov/arcgis/rest/services/Cadastral/BLM_Natl_PLSS_CadNSDI/MapServer/1/query"
|
||||||
table_name: "public.plss_townships"
|
table_name: "public.plss_townships"
|
||||||
|
|
|
@ -19,7 +19,7 @@ from playwright.async_api import async_playwright
|
||||||
from zoneinfo import ZoneInfo
|
from zoneinfo import ZoneInfo
|
||||||
from dateutil.parser import parse as dateutil_parse
|
from dateutil.parser import parse as dateutil_parse
|
||||||
from typing import Optional, List, Union
|
from typing import Optional, List, Union
|
||||||
from sijapi import Sys, Db, TZ, GEO
|
from sijapi import Sys, Db, TZ, GEO, Gis
|
||||||
from sijapi.classes import Location
|
from sijapi.classes import Location
|
||||||
from sijapi.utilities import haversine, assemble_journal_path
|
from sijapi.utilities import haversine, assemble_journal_path
|
||||||
from sijapi.serialization import json_dumps
|
from sijapi.serialization import json_dumps
|
||||||
|
@ -124,7 +124,7 @@ async def get_last_location() -> Optional[Location]:
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
async def generate_and_save_heatmap(
|
wasync 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
|
||||||
|
@ -139,6 +139,7 @@ Generate a heatmap for the given date range and save it as a PNG file.
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
from staticmap import StaticMap, CircleMarker
|
from staticmap import StaticMap, CircleMarker
|
||||||
|
import math
|
||||||
|
|
||||||
start_date = await dt(start_date)
|
start_date = await dt(start_date)
|
||||||
if end_date:
|
if end_date:
|
||||||
|
@ -150,10 +151,23 @@ Generate a heatmap for the given date range and save it as a PNG file.
|
||||||
if not locations:
|
if not locations:
|
||||||
raise ValueError("No locations found for the given date range")
|
raise ValueError("No locations found for the given date range")
|
||||||
|
|
||||||
# Create map with correct URL template
|
# Calculate bounds
|
||||||
|
lats = [loc.latitude for loc in locations]
|
||||||
|
lons = [loc.longitude for loc in locations]
|
||||||
|
lat_diff = max(lats) - min(lats)
|
||||||
|
lon_diff = max(lons) - min(lons)
|
||||||
|
|
||||||
|
# Calculate zoom level - lower number = more zoomed out
|
||||||
|
zoom = min(
|
||||||
|
Gis.map.max_zoom,
|
||||||
|
int(math.log2(360 / max(lat_diff, lon_diff))) - 1
|
||||||
|
)
|
||||||
|
|
||||||
|
# Create map with correct URL template and zoom
|
||||||
m = StaticMap(
|
m = StaticMap(
|
||||||
640, 360,
|
640, 360,
|
||||||
url_template='https://cartodb-basemaps-a.global.ssl.fastly.net/dark_all/{z}/{x}/{y}.png'
|
url_template='https://cartodb-basemaps-a.global.ssl.fastly.net/dark_all/{z}/{x}/{y}.png',
|
||||||
|
zoom=zoom
|
||||||
)
|
)
|
||||||
|
|
||||||
# Add markers with heat effect
|
# Add markers with heat effect
|
||||||
|
@ -177,7 +191,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:
|
||||||
|
|
Loading…
Reference in a new issue