chore: sweep dead code across all three services
Per review §1 — verified no callers before each deletion:
- _next_scrape_utc (context dict key never read by any template)
- ALERT_SCRAPE_INTERVAL_SECONDS settings import (only _next_scrape_utc read it)
- alert/paths.py (imported by nothing)
- alert/settings.py LANGUAGE (alert doesn't use translations.toml)
- alert/main.py: the vestigial `c = {}` connectivity dict, the comment
about re-enabling it, and the entire connectivity block in
_flat_payload — the web-side columns stay NULL on insert now
- alert/maps.py: DESTINATIONS, calculate_score, _get_next_weekday,
_calculate_transfers (only geocode is used in the scraper)
- alert/flat.py: connectivity + display_address properties,
_connectivity field, unused datetime import
- apply/utils.py str_to_preview (no callers) — file removed
- web/matching.py: max_morning_commute + commute check
- web/app.py: don't pass connectivity dict into flat_matches_filter,
don't write email_address through update_notifications
- web/db.py: get_error (no callers); drop kill_switch,
max_morning_commute, email_address from their allowed-sets so they're
not writable through update_* anymore
- web/settings.py + docker-compose.yml: SMTP_HOST/PORT/USERNAME/PASSWORD/
FROM/STARTTLS (notifications.py is telegram-only now)
DB columns themselves (kill_switch, email_address, max_morning_commute,
connectivity_morning_time, connectivity_night_time) stay in the schema
— SQLite can't drop them cheaply and they're harmless.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
617c76cb54
commit
ebb11178e7
11 changed files with 5 additions and 166 deletions
|
|
@ -1,25 +1,12 @@
|
|||
import logging
|
||||
|
||||
import googlemaps
|
||||
from datetime import datetime, timedelta, time as dt_time
|
||||
from settings import GMAPS_API_KEY
|
||||
|
||||
logger = logging.getLogger("flat-alert")
|
||||
|
||||
class Maps:
|
||||
DESTINATIONS = {
|
||||
"Hbf": "Berlin Hauptbahnhof",
|
||||
"Friedrichstr": "Friedrichstraße, Berlin",
|
||||
"Kotti": "Kottbusser Tor, Berlin",
|
||||
"Warschauer": "Warschauer Straße, Berlin",
|
||||
"Ostkreuz": "Ostkreuz, Berlin",
|
||||
"Nollendorf": "Nollendorfplatz, Berlin",
|
||||
"Zoo": "Zoologischer Garten, Berlin",
|
||||
"Kudamm": "Kurfürstendamm, Berlin",
|
||||
"Gesundbrunnen": "Gesundbrunnen, Berlin",
|
||||
"Hermannplatz": "Hermannplatz, Berlin"
|
||||
}
|
||||
|
||||
class Maps:
|
||||
def __init__(self):
|
||||
self.gmaps = googlemaps.Client(key=GMAPS_API_KEY)
|
||||
|
||||
|
|
@ -36,69 +23,3 @@ class Maps:
|
|||
except Exception as e:
|
||||
logger.warning("geocode failed for %r: %s", address, e)
|
||||
return None
|
||||
|
||||
def _get_next_weekday(self, date, weekday):
|
||||
days_ahead = weekday - date.weekday()
|
||||
if days_ahead <= 0:
|
||||
days_ahead += 7
|
||||
return date + timedelta(days_ahead)
|
||||
|
||||
def _calculate_transfers(self, steps):
|
||||
transit_count = sum(1 for step in steps if step['travel_mode'] == 'TRANSIT')
|
||||
return max(0, transit_count - 1)
|
||||
|
||||
def calculate_score(self, origin_address):
|
||||
now = datetime.now()
|
||||
# Next Monday 8:00 AM
|
||||
next_monday = self._get_next_weekday(now, 0)
|
||||
morning_departure = datetime.combine(next_monday.date(), dt_time(8, 0))
|
||||
# Next Sunday 2:00 AM
|
||||
next_sunday = self._get_next_weekday(now, 6)
|
||||
night_departure = datetime.combine(next_sunday.date(), dt_time(2, 0))
|
||||
|
||||
total_morning_minutes = 0
|
||||
total_morning_transfers = 0
|
||||
total_night_minutes = 0
|
||||
total_night_transfers = 0
|
||||
dest_count = 0
|
||||
|
||||
for key, dest_address in self.DESTINATIONS.items():
|
||||
# Morning: Flat -> Center
|
||||
routes_morning = self.gmaps.directions(
|
||||
origin=origin_address,
|
||||
destination=dest_address,
|
||||
mode="transit",
|
||||
departure_time=morning_departure
|
||||
)
|
||||
|
||||
# Night: Center -> Flat
|
||||
routes_night = self.gmaps.directions(
|
||||
origin=dest_address,
|
||||
destination=origin_address,
|
||||
mode="transit",
|
||||
departure_time=night_departure
|
||||
)
|
||||
|
||||
if routes_morning:
|
||||
leg = routes_morning[0]['legs'][0]
|
||||
total_morning_minutes += leg['duration']['value'] / 60
|
||||
total_morning_transfers += self._calculate_transfers(leg['steps'])
|
||||
|
||||
if routes_night:
|
||||
leg = routes_night[0]['legs'][0]
|
||||
total_night_minutes += leg['duration']['value'] / 60
|
||||
total_night_transfers += self._calculate_transfers(leg['steps'])
|
||||
|
||||
dest_count += 1
|
||||
|
||||
avg_m_time = total_morning_minutes / dest_count if dest_count else 0
|
||||
avg_m_trans = total_morning_transfers / dest_count if dest_count else 0
|
||||
avg_n_time = total_night_minutes / dest_count if dest_count else 0
|
||||
avg_n_trans = total_night_transfers / dest_count if dest_count else 0
|
||||
|
||||
return {
|
||||
'morning_time': avg_m_time,
|
||||
'morning_transfers': avg_m_trans,
|
||||
'night_time': avg_n_time,
|
||||
'night_transfers': avg_n_trans
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue