Metadata-Version: 2.4
Name: tako_alerts_system
Version: 0.2.13
Summary: Read PyPI package information
Home-page: https://github.com/melius/itsTako_alerts_library
Author: Gabriel González
Author-email: gabriel.gonzalez@meliusid.com
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Requires-Python: >=3.10
Description-Content-Type: text/markdown
Requires-Dist: loguru==0.7.2
Requires-Dist: pyproj==3.7.0
Requires-Dist: pytz==2024.2
Requires-Dist: redis==5.2.0
Requires-Dist: requests==2.32.3
Requires-Dist: shapely==2.0.7
Requires-Dist: twilio==9.4.6
Dynamic: author
Dynamic: author-email
Dynamic: classifier
Dynamic: description
Dynamic: description-content-type
Dynamic: home-page
Dynamic: requires-dist
Dynamic: requires-python
Dynamic: summary

# itsTako_alerts_library

refer to Melius I+D

## Speed alert driver notifications

Driver lookup and Telegram delivery are opt-in. Pass `driver_notification_config`
to `SpeedAlerts` to enable them; omit it to retain the existing synchronous
WhatsApp flow.

```python
SpeedAlerts(
    redis_client=redis_client,
    whatsapp_config=whatsapp_config,
    time_window=60,
    alert_threshold=2,
    driver_notification_config={
        "api_key": os.getenv("TAKO_API_KEY"),
        "telegram_bot_token": os.getenv("TELEGRAM_TOKEN_EMASIVO"),
        "max_workers": 2,
        "request_timeout": 5,
    },
)
```

The trips API URL defaults to the Emasivo external trips endpoint and can be
overridden with `trips_api_url`. The API key is sent as `x-api-key`. Bus IDs
matching `ZXX2222` are normalized to `ZXX-2222` for lookup only. Background
workers perform driver lookup, WhatsApp/Telegram delivery, reverse geocoding,
and alert persistence without blocking the queue consumer.

Telegram messages include the alert bus and local time. When valid coordinates
are available, they also include a **Ver ubicación** button that opens the
alert location in Google Maps.

Behavior alert code `4` (distracted driving) is disabled. Codes `1`, `2`, and
`3` remain enabled.

## Speed alerts inside KML zones

Create a `SpeedZoneLookup` with a KML file or folder and a dictionary that maps
each KML placemark name to its speed limit in km/h. Pass the lookup to
`SpeedAlerts`. Samples outside all configured zones are ignored. Samples inside
a zone use that zone's speed limit.

```python
from its_system_alerts.system.alerts.speed_alerts import SpeedAlerts
from its_system_alerts.system.alerts.speed_zones import SpeedZoneLookup

zones = SpeedZoneLookup(
    kml_path="app/speed_zones",
    speed_limits={"Polígono1": 30, "Polígono2": 40},
)

speed_alerts = SpeedAlerts(
    redis_client=redis_client,
    whatsapp_config=whatsapp_config,
    time_window=60,
    alert_threshold=2,
    speed_zones=zones,
    alert_source="speed_zone",
)
```

Each consumer can create its own lookup from its KML files and speed dictionary.
Set a different `alert_source` for each stream when each stream needs separate
Redis counters and cooldowns. The database alert type remains the standard
speed alert type.
