A real-time monitoring system for detecting discrepancies in potion collection data. The system analyzes cauldron drain events and compares them with official transport tickets to identify potential theft or leakage.
- Frontend: Next.js (TypeScript, App Router)
- Backend: Flask (Python)
- Mapping: Leaflet / React-Leaflet
- Data Analysis: Pandas, NumPy
- Interactive Map: Visualizes cauldron locations with detailed popup information
- Discrepancy Detection: Identifies volume discrepancies between actual drains and reported tickets
- Time Playback: Allows time-travel through historical data with 6-hour intervals
- Real-time Statistics: Displays total cauldrons, loss incidents, and total volume lost
- Overflow Forecasting: Predicts when cauldrons will reach capacity using EWMA fill rate estimation
- Route Optimization: Generates optimal collection routes for witches to prevent overflows
cd backend
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt
flask --app app run --debugThe backend server will start on http://127.0.0.1:5000
cd frontend
npm install
npm run devThe frontend will be available at http://localhost:3000
app.py: Main Flask server with API endpoints- Pass-through endpoints:
/api/cauldrons,/api/tickets,/api/historical-data - Computed endpoints:
/api/discrepancies,/drains,/bootstrap - Bonus endpoints:
/api/forecast,/api/optimized-routes
- Pass-through endpoints:
analysis/discrepancy_detector.py: Core analysis logiccalculate_fill_rates(): Determines fill rate for each cauldrondetect_all_drains_from_records(): Identifies drain events and calculates true volumesmatch_tickets(): Compares calculated drains with official tickets
app/page.tsx: Main dashboard page with state managementapp/components/Map.tsx: Interactive Leaflet map displaying cauldron locationsapp/components/DiscrepancyTable.tsx: Table showing theft and leakage incidentsapp/components/PlaybackSlider.tsx: Time-travel slider with auto-play functionalityapp/lib/apiClient.ts: API client for backend communication
Analyzes time-series data to find periods where cauldron levels are only increasing, then calculates the median fill rate (L/min) to avoid outliers.
Scans through data to identify drain events where cauldron levels drop, recording start time, end time, and level changes.
Applies compensation formula to account for continued filling during drains:
TRUE_VOLUME = (Level_Before - Level_After) + (Fill_Rate × Drain_Time)
Groups drains and tickets by date and cauldron, then compares expected (tickets) vs actual (calculated drains) to identify discrepancies.
GET /api/cauldrons- Cauldron information and locationsGET /api/tickets- Official transport ticketsGET /api/historical-data?start_date=<unix>&end_date=<unix>- Time-series cauldron levelsGET /api/discrepancies- Computed discrepancies with theft detection
GET /api/forecast- Overflow predictions using EWMAPOST /api/optimized-routes- Optimal collection routes for witches