Backend

Боевой бэкенд (пакет app в backend/): принимает поток NDTP-телеметрии от терминалов (и эмулятора), сопоставляет его с расписанием, считает производные признаки, получает прогнозы ML-сервиса в горизонте 10–15 минут, поднимает алерты и отдаёт всё диспетчерскому дашборду.

Поток данных:

терминалы / эмулятор ──TCP:9201──▶ ndtp.server ─┐
traffic.csv (история) ──────────▶ ingest.replay ─┴─▶ ingest.pipeline ──▶ state.fleet
                                                           (unit → ТС, датасетные часы)
state.fleet ──▶ predict.predictor ──HTTP──▶ ML-сервис
                      │
                      ├──▶ alerts ──▶ api.ws (WebSocket) ──▶ дашборд
                      └──▶ db.history (Postgres)

Спецификация HTTP API — Swagger UI бэкенда: https://api.mowtransit.ru/docs (локально http://localhost:8000/docs). Подробности, замеры и инструкции — backend/README.md.

Модули

app.main

FastAPI application: starts telemetry ingest (NDTP listener + dataset replay) and serves the API.

app.config

Runtime settings, read from environment variables (and .env in the working directory, if present).

app.clock

Dataset clock: maps wall-clock time onto the dataset's timeline.

app.ndtp.protocol

NDTP wire codec: stream framing, CRC, and decoding of what the telematics terminals send.

app.ndtp.server

NDTP TCP server: accepts terminal connections and turns their byte streams into navigation fixes.

app.ingest.models

The normalized telemetry point every downstream component works with.

app.ingest.dataset

Loading traffic.csv: the unit → vehicle registry, and the pings the replay source plays back.

app.ingest.pipeline

Ingest pipeline: NDTP fixes and replayed rows become Ping objects on one timeline, in one stream.

app.ingest.replay

Replay source: plays traffic.csv into the ingest pipeline as the dataset clock passes each row.

app.state.schedule

The planned schedule: every vehicle's stop visits for the day, indexed for arrival detection.

app.state.arrivals

Arrival detection from GPS: when did a vehicle actually reach each planned stop.

app.state.fleet

Per-vehicle state: telemetry buffer, arrivals log, and the features derived from them.

app.predict.client

HTTP client for the ML service (ml/src/inference_service.py).

app.predict.payload

Building ML PredictRequest bodies from vehicle state (contract: ml/src/inference_service.py).

app.predict.predictor

The predictor: every tick, finds each vehicle's target stop 10–15 minutes ahead and gets a delay forecast.

app.alerts

Alerts: turns red forecasts into dispatcher alerts and checks them against what actually happened.

app.db.history

Write-behind history store.

app.api.views

Dashboard views: routes, vehicles and schedules in the shapes frontend/js/mock.js defines.

app.api.dashboard

The dashboard's REST API — the calls frontend/js/api.js makes, in the shapes mock.js defines.

app.api.ws

WebSocket push to dashboards: vehicle.update every tick, alert and what-if events as they happen.