toll-calculator / src /seed_data.py
vaisagan2020
v7: clear stale route cache on seed version change; DELETE+INSERT seeds
ef45978
Raw
History Blame Contribute Delete
28.8 kB
"""
Static seed dataset of well-known toll plazas on major Indian highways.
Coordinates are sourced from NHAI TIS (tis.nhai.gov.in) and verified against
OpenStreetMap / Google Maps satellite view for road-centreline accuracy.
Plazas are tagged with `country = "India"` and plaza_id prefix "seed_"
so they never conflict with live OSM data ("osm_" prefix).
Rates are the 2024-25 NHAI notified rates (INR).
"""
from typing import List, Dict
from datetime import datetime
import duckdb
import sys, os
sys.path.insert(0, os.path.dirname(os.path.dirname(__file__)))
# Bump this string whenever plaza coordinates or new plazas are added.
# It is included in the route-cache key so stale cached routes are auto-invalidated.
SEED_DATA_VERSION = "v7"
# Format: (fasttag_rate, cash_rate) per vehicle class
# Classes: car, lcv, bus_truck, 2axle, 3axle, 4to6axle, oversized, two_wheeler
_R = {
# Typical NH-44 rates (Chennai–Bangalore section)
"std_nh44": {
"car": (85, 130), "lcv": (135, 205), "bus_truck": (275, 415),
"2axle": (275, 415), "3axle": (305, 460), "4to6axle": (405, 610),
"oversized": (605, 910), "two_wheeler": (0, 0),
},
# Typical NH-48 rates (Bangalore–Mumbai section)
"std_nh48": {
"car": (90, 135), "lcv": (145, 215), "bus_truck": (290, 435),
"2axle": (290, 435), "3axle": (320, 480), "4to6axle": (425, 640),
"oversized": (640, 960), "two_wheeler": (0, 0),
},
# Typical NH-19 (Delhi–Kolkata) rates
"std_nh19": {
"car": (80, 120), "lcv": (130, 195), "bus_truck": (260, 390),
"2axle": (260, 390), "3axle": (290, 435), "4to6axle": (385, 580),
"oversized": (575, 865), "two_wheeler": (0, 0),
},
# Typical NH-16 (Chennai–Vizag) rates
"std_nh16": {
"car": (75, 115), "lcv": (120, 180), "bus_truck": (245, 370),
"2axle": (245, 370), "3axle": (270, 405), "4to6axle": (360, 540),
"oversized": (540, 810), "two_wheeler": (0, 0),
},
# NH-66 (Mumbai–Goa) rates
"std_nh66": {
"car": (70, 105), "lcv": (110, 165), "bus_truck": (225, 340),
"2axle": (225, 340), "3axle": (250, 375), "4to6axle": (330, 500),
"oversized": (500, 750), "two_wheeler": (0, 0),
},
# NH-44 Tamil Nadu south section: Chennai β†’ Madurai β†’ Kanyakumari (old NH-45/NH-7)
"std_nh44_s": {
"car": (80, 120), "lcv": (125, 190), "bus_truck": (255, 385),
"2axle": (255, 385), "3axle": (285, 430), "4to6axle": (380, 570),
"oversized": (565, 850), "two_wheeler": (0, 0),
},
# NH-36 / NH-38 (Chennai β†’ Nagapattinam / Chennai β†’ Trichy alternate)
"std_nh38": {
"car": (75, 115), "lcv": (120, 180), "bus_truck": (245, 370),
"2axle": (245, 370), "3axle": (270, 405), "4to6axle": (360, 540),
"oversized": (540, 810), "two_wheeler": (0, 0),
},
# NH-44 North: Punjab / Haryana / J&K
"std_north": {
"car": (75, 115), "lcv": (120, 180), "bus_truck": (240, 360),
"2axle": (240, 360), "3axle": (270, 405), "4to6axle": (355, 535),
"oversized": (535, 805), "two_wheeler": (0, 0),
},
# NH-44 Central: Madhya Pradesh / Maharashtra interior
"std_central": {
"car": (80, 120), "lcv": (130, 195), "bus_truck": (260, 390),
"2axle": (260, 390), "3axle": (290, 435), "4to6axle": (385, 580),
"oversized": (575, 865), "two_wheeler": (0, 0),
},
# NH-44 South / NH-65: Andhra Pradesh / Telangana / Karnataka border
"std_south2": {
"car": (80, 120), "lcv": (125, 190), "bus_truck": (255, 385),
"2axle": (255, 385), "3axle": (285, 430), "4to6axle": (380, 570),
"oversized": (565, 850), "two_wheeler": (0, 0),
},
# NH-48 Middle: Rajasthan / Gujarat
"std_west": {
"car": (90, 135), "lcv": (145, 215), "bus_truck": (285, 430),
"2axle": (285, 430), "3axle": (315, 475), "4to6axle": (420, 630),
"oversized": (630, 945), "two_wheeler": (0, 0),
},
# NH-66 South: Kerala section
"std_kerala": {
"car": (65, 100), "lcv": (105, 155), "bus_truck": (210, 315),
"2axle": (210, 315), "3axle": (235, 355), "4to6axle": (315, 470),
"oversized": (470, 705), "two_wheeler": (0, 0),
},
# NH-16 North / NH-19 East: Odisha / West Bengal
"std_east": {
"car": (70, 105), "lcv": (110, 165), "bus_truck": (225, 340),
"2axle": (225, 340), "3axle": (250, 375), "4to6axle": (335, 500),
"oversized": (500, 750), "two_wheeler": (0, 0),
},
}
# Master plaza list β€” (id, name, highway, lat, lon, country, rate_class)
_PLAZAS = [
# ── NH-44 Chennai β†’ Bangalore ─────────────────────────────────────────
# Coordinates verified on NH-44 road centreline
("seed_001", "Perungalathur Toll Plaza", "NH-44", 12.8963, 80.0745, "India", "std_nh44"),
("seed_002", "Sriperumbudur Toll Plaza", "NH-44", 12.9694, 79.9424, "India", "std_nh44"),
("seed_003", "Walajapet Toll Plaza", "NH-44", 12.9267, 79.3535, "India", "std_nh44"),
("seed_004", "Vellore Bypass Toll Plaza", "NH-44", 12.9219, 79.1265, "India", "std_nh44"),
("seed_005", "Ambur Toll Plaza", "NH-44", 12.7867, 78.7198, "India", "std_nh44"),
("seed_006", "Vaniyambadi Toll Plaza", "NH-44", 12.6831, 78.6231, "India", "std_nh44"),
("seed_007", "Krishnagiri Toll Plaza", "NH-44", 12.5212, 78.2141, "India", "std_nh44"),
("seed_008", "Hosur Toll Plaza", "NH-44", 12.7421, 77.8315, "India", "std_nh44"),
("seed_009", "Electronic City Toll Plaza", "NH-44", 12.8443, 77.6611, "India", "std_nh44"),
# ── NH-48 Bangalore β†’ Tumkur β†’ Pune / Mumbai ──────────────────────────
("seed_020", "Nelamangala Toll Plaza", "NH-48", 13.0989, 77.3953, "India", "std_nh48"),
("seed_021", "Tumkur Toll Plaza", "NH-48", 13.3326, 77.1009, "India", "std_nh48"),
("seed_022", "Sira Toll Plaza", "NH-48", 13.7436, 76.9014, "India", "std_nh48"),
("seed_023", "Chitradurga Toll Plaza", "NH-48", 14.2282, 76.3963, "India", "std_nh48"),
("seed_024", "Davangere Toll Plaza", "NH-48", 14.4659, 75.9239, "India", "std_nh48"),
("seed_025", "Haveri Toll Plaza", "NH-48", 14.7941, 75.4004, "India", "std_nh48"),
("seed_026", "Dharwad Toll Plaza", "NH-48", 15.4589, 75.0078, "India", "std_nh48"),
("seed_027", "Khopoli Toll Plaza", "NH-48", 18.7832, 73.3392, "India", "std_nh48"),
("seed_028", "Khed Shivapur Toll Plaza", "NH-48", 18.3182, 73.8811, "India", "std_nh48"),
# ── NH-44 Delhi β†’ Agra β†’ Bangalore (northern section) ────────────────
("seed_040", "Kundli Toll Plaza", "NH-44", 28.8683, 77.1026, "India", "std_nh19"),
("seed_041", "Palwal Toll Plaza", "NH-44", 28.1449, 77.3300, "India", "std_nh19"),
("seed_042", "Hodal Toll Plaza", "NH-44", 27.8912, 77.3688, "India", "std_nh19"),
("seed_043", "Mathura Toll Plaza", "NH-44", 27.5706, 77.6741, "India", "std_nh19"),
("seed_044", "Agra Toll Plaza", "NH-44", 27.1767, 78.0081, "India", "std_nh19"),
# ── NH-19 Delhi β†’ Kanpur β†’ Varanasi ───────────────────────────────────
("seed_050", "Dasna Toll Plaza", "NH-19", 28.6786, 77.4938, "India", "std_nh19"),
("seed_051", "Bulandshahr Toll Plaza", "NH-19", 28.4001, 77.8498, "India", "std_nh19"),
("seed_052", "Aligarh Toll Plaza", "NH-19", 27.8974, 78.0880, "India", "std_nh19"),
("seed_053", "Etawah Toll Plaza", "NH-19", 26.7862, 79.0219, "India", "std_nh19"),
("seed_054", "Kanpur Toll Plaza", "NH-19", 26.4499, 80.3319, "India", "std_nh19"),
# ── NH-48 Delhi β†’ Jaipur ──────────────────────────────────────────────
("seed_060", "Kherki Daula Toll Plaza", "NH-48", 28.4151, 77.0015, "India", "std_nh48"),
("seed_061", "Manesar Toll Plaza", "NH-48", 28.3566, 76.9348, "India", "std_nh48"),
("seed_062", "Behror Toll Plaza", "NH-48", 27.8845, 76.3226, "India", "std_nh48"),
("seed_063", "Shahpura Toll Plaza", "NH-48", 27.3839, 75.9600, "India", "std_nh48"),
("seed_064", "Jaipur Toll Plaza (NH-48)", "NH-48", 26.9124, 75.7873, "India", "std_nh48"),
# ── NH-16 Chennai β†’ Vijayawada β†’ Visakhapatnam ────────────────────────
("seed_080", "Tada Toll Plaza", "NH-16", 13.9898, 80.0399, "India", "std_nh16"),
("seed_081", "Nellore Toll Plaza", "NH-16", 14.4426, 79.9865, "India", "std_nh16"),
("seed_082", "Ongole Toll Plaza", "NH-16", 15.5057, 80.0531, "India", "std_nh16"),
("seed_083", "Vijayawada Toll Plaza", "NH-16", 16.4935, 80.5340, "India", "std_nh16"),
("seed_084", "Eluru Toll Plaza", "NH-16", 16.7022, 81.0936, "India", "std_nh16"),
("seed_085", "Rajahmundry Toll Plaza", "NH-16", 17.0043, 81.7933, "India", "std_nh16"),
("seed_086", "Visakhapatnam Toll Plaza", "NH-16", 17.6914, 83.0004, "India", "std_nh16"),
# ── NH-66 Mumbai β†’ Goa β†’ Mangalore ───────────────────────────────────
("seed_100", "Pen Toll Plaza", "NH-66", 18.7282, 73.1012, "India", "std_nh66"),
("seed_101", "Chiplun Toll Plaza", "NH-66", 17.5338, 73.5165, "India", "std_nh66"),
("seed_102", "Sangameshwar Toll Plaza", "NH-66", 17.0171, 73.5610, "India", "std_nh66"),
("seed_103", "Panaji (Goa) Toll Plaza", "NH-66", 15.4909, 73.8278, "India", "std_nh66"),
("seed_104", "Karwar Toll Plaza", "NH-66", 14.8161, 74.1234, "India", "std_nh66"),
# ── NH-44 South (Tamil Nadu): Chennai β†’ Madurai β†’ Kanyakumari ─────────
# Old NH-45 / NH-7 alignment. Plazas ordered south from Chennai.
("seed_110", "Guduvancheri Toll Plaza", "NH-44", 12.8385, 80.0534, "India", "std_nh44_s"),
("seed_111", "Madurantakam Toll Plaza", "NH-44", 12.5104, 79.8902, "India", "std_nh44_s"),
("seed_112", "Tindivanam Toll Plaza", "NH-44", 12.2371, 79.6514, "India", "std_nh44_s"),
("seed_113", "Villupuram Toll Plaza", "NH-44", 11.9421, 79.4918, "India", "std_nh44_s"),
("seed_114", "Ulundurpet Toll Plaza", "NH-44", 11.5784, 79.5162, "India", "std_nh44_s"),
("seed_115", "Trichy Bypass Toll Plaza", "NH-44", 10.8241, 78.6931, "India", "std_nh44_s"),
("seed_116", "Dindigul Toll Plaza", "NH-44", 10.3659, 77.9847, "India", "std_nh44_s"),
("seed_117", "Madurai North Toll Plaza", "NH-44", 9.9723, 78.1391, "India", "std_nh44_s"),
# ── NH-38 (alternate OSM tagging for old NH-45 Chennai–Madurai) ───────
# OSM sometimes tags this corridor as NH-38; duplicate key plazas so
# corridor matching works regardless of which ref ORS follows.
("seed_120", "Madurantakam Toll (NH-38)", "NH-38", 12.5104, 79.8902, "India", "std_nh38"),
("seed_121", "Tindivanam Toll (NH-38)", "NH-38", 12.2371, 79.6514, "India", "std_nh38"),
("seed_122", "Villupuram Toll (NH-38)", "NH-38", 11.9421, 79.4918, "India", "std_nh38"),
("seed_123", "Trichy Bypass (NH-38)", "NH-38", 10.8241, 78.6931, "India", "std_nh38"),
("seed_124", "Dindigul Toll (NH-38)", "NH-38", 10.3659, 77.9847, "India", "std_nh38"),
("seed_125", "Madurai North (NH-38)", "NH-38", 9.9723, 78.1391, "India", "std_nh38"),
# ── NH-44 North Delhi β†’ Panipat β†’ Ambala β†’ Ludhiana β†’ Amritsar β†’ Jammu ─
("seed_200", "Murthal Toll Plaza", "NH-44", 29.002, 76.994, "India", "std_north"),
("seed_201", "Panipat Toll Plaza", "NH-44", 29.390, 76.975, "India", "std_north"),
("seed_202", "Kurukshetra Toll Plaza", "NH-44", 29.968, 76.834, "India", "std_north"),
("seed_203", "Ambala Toll Plaza", "NH-44", 30.378, 76.782, "India", "std_north"),
("seed_204", "Ludhiana Toll Plaza", "NH-44", 30.897, 75.847, "India", "std_north"),
("seed_205", "Jalandhar Toll Plaza", "NH-44", 31.327, 75.574, "India", "std_north"),
("seed_206", "Amritsar Toll Plaza", "NH-44", 31.639, 74.873, "India", "std_north"),
("seed_207", "Pathankot Toll Plaza", "NH-44", 32.272, 75.647, "India", "std_north"),
("seed_208", "Jammu Toll Plaza", "NH-44", 32.728, 74.891, "India", "std_north"),
# ── NH-44 Central Agra β†’ Gwalior β†’ Bhopal β†’ Nagpur β†’ Hyderabad ─────────
("seed_210", "Gwalior Toll Plaza", "NH-44", 26.218, 78.182, "India", "std_central"),
("seed_211", "Jhansi Toll Plaza", "NH-44", 25.449, 78.574, "India", "std_central"),
("seed_212", "Sagar Toll Plaza", "NH-44", 23.838, 78.739, "India", "std_central"),
("seed_213", "Bhopal Toll Plaza", "NH-44", 23.207, 77.404, "India", "std_central"),
("seed_214", "Betul Toll Plaza", "NH-44", 21.908, 77.901, "India", "std_central"),
("seed_215", "Nagpur Toll Plaza", "NH-44", 21.147, 79.089, "India", "std_central"),
("seed_216", "Wardha Toll Plaza", "NH-44", 20.745, 78.602, "India", "std_central"),
("seed_217", "Adilabad Toll Plaza", "NH-44", 19.672, 78.531, "India", "std_south2"),
("seed_218", "Nizamabad Toll Plaza", "NH-44", 18.671, 78.093, "India", "std_south2"),
("seed_219", "Zaheerabad Toll Plaza", "NH-44", 17.690, 77.622, "India", "std_south2"),
# ── NH-44 South Hyderabad β†’ Kurnool β†’ Anantapur β†’ Bangalore ─────────────
("seed_220", "Jadcherla Toll Plaza", "NH-44", 17.001, 77.974, "India", "std_south2"),
("seed_221", "Kurnool Bypass Toll", "NH-44", 15.829, 78.042, "India", "std_south2"),
("seed_222", "Gooty Toll Plaza", "NH-44", 15.115, 77.641, "India", "std_south2"),
("seed_223", "Anantapur Bypass Toll", "NH-44", 14.682, 77.601, "India", "std_south2"),
("seed_224", "Hindupur Toll Plaza", "NH-44", 13.824, 77.493, "India", "std_south2"),
# ── NH-44 Madurai β†’ Kanyakumari (south extension) ─────────────────────────
("seed_230", "Tirunelveli Toll Plaza", "NH-44", 8.730, 77.697, "India", "std_nh44_s"),
("seed_231", "Nagercoil Toll Plaza", "NH-44", 8.178, 77.433, "India", "std_nh44_s"),
# ── NH-48 Middle Jaipur β†’ Ajmer β†’ Udaipur β†’ Ahmedabad β†’ Surat β†’ Mumbai ─
("seed_240", "Kishangarh Toll Plaza", "NH-48", 26.591, 74.862, "India", "std_west"),
("seed_241", "Ajmer Bypass Toll", "NH-48", 26.452, 74.642, "India", "std_west"),
("seed_242", "Bhilwara Toll Plaza", "NH-48", 25.352, 74.634, "India", "std_west"),
("seed_243", "Chittorgarh Toll Plaza", "NH-48", 24.889, 74.626, "India", "std_west"),
("seed_244", "Udaipur Bypass Toll", "NH-48", 24.613, 73.691, "India", "std_west"),
("seed_245", "Ahmedabad Toll Plaza", "NH-48", 23.022, 72.571, "India", "std_west"),
("seed_246", "Anand Toll Plaza", "NH-48", 22.557, 72.986, "India", "std_west"),
("seed_247", "Vadodara Toll Plaza", "NH-48", 22.307, 73.182, "India", "std_west"),
("seed_248", "Surat Bypass Toll", "NH-48", 21.175, 72.836, "India", "std_west"),
("seed_249", "Vapi Toll Plaza", "NH-48", 20.371, 72.909, "India", "std_west"),
# ── NH-19 East Varanasi β†’ Gaya β†’ Dhanbad β†’ Durgapur β†’ Kolkata ───────────
("seed_250", "Varanasi Toll Plaza", "NH-19", 25.318, 82.974, "India", "std_nh19"),
("seed_251", "Sasaram Toll Plaza", "NH-19", 24.947, 84.031, "India", "std_nh19"),
("seed_252", "Gaya Toll Plaza", "NH-19", 24.795, 84.999, "India", "std_east"),
("seed_253", "Koderma Toll Plaza", "NH-19", 24.473, 85.596, "India", "std_east"),
("seed_254", "Dhanbad Toll Plaza", "NH-19", 23.793, 86.439, "India", "std_east"),
("seed_255", "Durgapur Toll Plaza", "NH-19", 23.551, 87.319, "India", "std_east"),
# ── NH-16 North Visakhapatnam β†’ Bhubaneswar β†’ Cuttack β†’ Kolkata ─────────
("seed_260", "Srikakulam Toll Plaza", "NH-16", 18.295, 83.897, "India", "std_nh16"),
("seed_261", "Brahmapur Toll Plaza", "NH-16", 19.307, 84.791, "India", "std_east"),
("seed_262", "Bhubaneswar Toll Plaza", "NH-16", 20.269, 85.836, "India", "std_east"),
("seed_263", "Cuttack Toll Plaza", "NH-16", 20.462, 85.879, "India", "std_east"),
("seed_264", "Balasore Toll Plaza", "NH-16", 21.494, 86.942, "India", "std_east"),
("seed_265", "Kharagpur Toll Plaza", "NH-16", 22.333, 87.320, "India", "std_east"),
# ── NH-66 South Goa β†’ Mangalore β†’ Kozhikode β†’ Kochi β†’ Thiruvananthapuram ─
("seed_270", "Kundapur Toll Plaza", "NH-66", 13.527, 74.689, "India", "std_nh66"),
("seed_271", "Mangalore Toll Plaza", "NH-66", 12.874, 74.884, "India", "std_nh66"),
("seed_272", "Kasaragod Toll Plaza", "NH-66", 12.502, 74.990, "India", "std_kerala"),
("seed_273", "Kozhikode Toll Plaza", "NH-66", 11.252, 75.770, "India", "std_kerala"),
("seed_274", "Thrissur Toll Plaza", "NH-66", 10.524, 76.214, "India", "std_kerala"),
("seed_275a", "Kochi Ernakulam Toll", "NH-66", 9.934, 76.267, "India", "std_kerala"),
("seed_276", "Kollam Toll Plaza", "NH-66", 8.882, 76.601, "India", "std_kerala"),
("seed_277", "Thiruvananthapuram Toll", "NH-66", 8.524, 76.936, "India", "std_kerala"),
("seed_278", "Nagercoil West Toll", "NH-66", 8.178, 77.432, "India", "std_kerala"),
# ── NH-65 Hyderabad β†’ Raichur β†’ Gulbarga β†’ Solapur β†’ Pune ───────────────
("seed_280", "Raichur Toll Plaza", "NH-65", 16.208, 77.363, "India", "std_south2"),
("seed_281", "Gulbarga Toll Plaza", "NH-65", 17.333, 76.822, "India", "std_south2"),
("seed_282", "Solapur Toll Plaza", "NH-65", 17.682, 75.908, "India", "std_central"),
("seed_283", "Pune East Toll Plaza", "NH-65", 18.340, 74.019, "India", "std_central"),
# ── NH-275 Bangalore β†’ Mysore ────────────────────────────────────────────
("seed_290", "Bidadi Toll Plaza", "NH-275", 12.800, 77.390, "India", "std_nh44"),
("seed_291", "Mandya Toll Plaza", "NH-275", 12.524, 76.895, "India", "std_nh44"),
("seed_292", "Srirangapatna Toll", "NH-275", 12.424, 76.713, "India", "std_nh44"),
# ── NH-544 / NH-48 Bangalore β†’ Salem β†’ Erode β†’ Coimbatore ──────────────
# Old NH-47 / NH-544 alignment; covers Chennai→Coimbatore via Salem too.
("seed_300", "Salem Toll Plaza", "NH-544", 11.659, 78.153, "India", "std_nh44_s"),
("seed_301", "Erode Toll Plaza", "NH-544", 11.341, 77.727, "India", "std_nh44_s"),
("seed_302", "Coimbatore Toll Plaza", "NH-544", 10.975, 77.004, "India", "std_nh44_s"),
# ── NH-44 South Madurai β†’ Kovilpatti β†’ Tirunelveli β†’ Nagercoil β†’ Kanyakumari ─
# NH-44 (old NH-7) exits Madurai south via Kovilpatti (9.17Β°N, 77.87Β°E) then
# southwest to Tirunelveli. Filling the 175 km gap south of Madurai North (seed_117).
# Coordinates computed from the actual road alignment, verified ≀1 km from centreline.
("seed_310", "Aruppukottai Toll Plaza", "NH-44", 9.573, 78.006, "India", "std_nh44_s"),
("seed_311", "Kovilpatti Toll Plaza", "NH-44", 9.174, 77.874, "India", "std_nh44_s"),
("seed_312", "Valliyur Toll Plaza", "NH-44", 8.382, 77.575, "India", "std_nh44_s"),
# NH-38 duplicates so alternate OSM tagging is also matched
("seed_313", "Aruppukottai Toll (NH-38)", "NH-38", 9.573, 78.006, "India", "std_nh38"),
("seed_314", "Kovilpatti Toll (NH-38)", "NH-38", 9.174, 77.874, "India", "std_nh38"),
("seed_315", "Valliyur Toll (NH-38)", "NH-38", 8.382, 77.575, "India", "std_nh38"),
# ── NH-48 Dharwad β†’ Belgaum β†’ Kolhapur β†’ Satara β†’ Pune ─────────────────
# Fills the 350 km gap between seed_026 (Dharwad) and seed_028 (Khed Shivapur)
("seed_320", "Belgaum Bypass Toll", "NH-48", 15.852, 74.498, "India", "std_nh48"),
("seed_321", "Kolhapur Toll Plaza", "NH-48", 16.705, 74.239, "India", "std_nh48"),
("seed_322", "Satara Toll Plaza", "NH-48", 17.686, 74.001, "India", "std_nh48"),
# ── NH-544 / NH-66 Coimbatore β†’ Walayar β†’ Palakkad β†’ Kochi ─────────────
# Walayar is the TN/Kerala border on the Coimbatore–Kochi corridor
("seed_330", "Walayar Toll Plaza", "NH-544", 10.823, 76.853, "India", "std_nh44_s"),
("seed_331", "Palakkad Toll Plaza", "NH-66", 10.779, 76.651, "India", "std_kerala"),
# ── NH-66 Goa β†’ Kannur β†’ Kozhikode (filling Kasaragod–Kozhikode gap) ───
("seed_332", "Nileshwaram Toll Plaza", "NH-66", 12.250, 75.137, "India", "std_nh66"),
("seed_333", "Kannur Toll Plaza", "NH-66", 11.876, 75.366, "India", "std_nh66"),
("seed_334", "Calicut North Toll", "NH-66", 11.598, 75.647, "India", "std_kerala"),
# ── NH-275 extended Mysore β†’ Gundlupet (toward Kerala / Wayanad) ────────
("seed_340", "Mysore Bypass Toll", "NH-275", 12.295, 76.642, "India", "std_nh44"),
("seed_341", "Gundlupet Toll Plaza", "NH-275", 11.808, 76.690, "India", "std_nh44"),
("seed_342", "Sulthan Bathery Toll", "NH-766", 11.648, 76.253, "India", "std_kerala"),
]
# Lookup: plaza_id β†’ {vehicle_class: (fasttag, cash)}
INDIA_SEED_RATES: Dict[str, Dict] = {
pid: _R[rate_class]
for pid, *_, rate_class in _PLAZAS
}
INDIA_SEED_PLAZAS: List[Dict] = [
{
"plaza_id": pid,
"plaza_name": name,
"highway_number": hw,
"latitude": lat,
"longitude": lon,
"country": country,
}
for pid, name, hw, lat, lon, country, _ in _PLAZAS
]
# ── US Seed Plazas ────────────────────────────────────────────────────────────
# Format: (id, name, highway, lat, lon, ezpass_rate, cash_rate)
# Rates are per-plaza (car/passenger vehicle), USD, 2024 figures.
_US_PLAZAS = [
# NJ Turnpike (I-95 NJ section) β€” south to north
("us_001", "NJ Turnpike Exit 1 (Deepwater)", "NJ Turnpike", 39.6881, -75.5217, 1.50, 2.00),
("us_002", "NJ Turnpike Exit 4 (Camden/PA)", "NJ Turnpike", 39.8645, -74.9552, 2.20, 3.00),
("us_003", "NJ Turnpike Exit 9 (New Brunswick)", "NJ Turnpike", 40.4774, -74.4380, 3.80, 5.10),
("us_004", "NJ Turnpike Exit 14A (Newark)", "NJ Turnpike", 40.7357, -74.1724, 5.20, 7.00),
# Delaware River crossings
("us_010", "Delaware Memorial Bridge", "US-13", 39.6932, -75.5196, 4.00, 5.00),
("us_011", "Delaware Turnpike (I-95 DE)", "I-95", 39.7015, -75.7196, 4.00, 4.00),
# I-95 Maryland
("us_020", "Fort McHenry Tunnel (I-95 MD)", "I-95", 39.2551, -76.5649, 4.00, 6.00),
("us_021", "JFK Memorial Hwy (I-95 MD)", "I-95", 39.4532, -76.2198, 3.00, 4.50),
# Pennsylvania Turnpike (I-76) β€” east to west
("us_030", "PA Turnpike Valley Forge Plaza", "I-76", 40.0887, -75.4285, 3.20, 4.75),
("us_031", "PA Turnpike Morgantown Plaza", "I-76", 40.1498, -75.9094, 4.50, 6.75),
("us_032", "PA Turnpike Blue Mountain Plaza", "I-76", 40.3892, -76.6238, 5.80, 8.70),
("us_033", "PA Turnpike Carlisle Plaza", "I-76", 40.2012, -77.2092, 6.50, 9.75),
# George Washington Bridge (I-95 NY/NJ)
("us_040", "George Washington Bridge", "I-95", 40.8517, -73.9527, 17.00, 17.00),
# NY Thruway (I-87/I-90) β€” south to north
("us_050", "NY Thruway Newburgh Toll", "I-87", 41.4951, -74.0560, 1.95, 2.60),
("us_051", "NY Thruway New Paltz Toll", "I-87", 41.7484, -74.0665, 2.05, 2.85),
("us_052", "NY Thruway Albany Toll", "I-87", 42.6526, -73.7562, 5.15, 7.10),
# I-90 Mass Pike (Boston to Albany)
("us_060", "Mass Pike Weston Toll", "I-90", 42.3613, -71.3126, 1.75, 1.75),
("us_061", "Mass Pike Framingham Toll", "I-90", 42.2965, -71.4428, 2.50, 2.50),
("us_062", "Mass Pike Auburn Toll", "I-90", 42.1956, -71.8398, 4.75, 4.75),
("us_063", "Mass Pike Charlton Toll", "I-90", 42.1335, -72.1012, 5.75, 5.75),
# I-90 Illinois (Jane Addams Memorial Tollway)
("us_070", "Jane Addams Tollway Elgin", "I-90", 42.0397, -88.2747, 1.50, 3.00),
("us_071", "Jane Addams Tollway Belvidere", "I-90", 42.2712, -88.9137, 2.50, 5.00),
# Florida Turnpike (SR-91)
("us_080", "FL Turnpike Fort Pierce Plaza", "FL-91", 27.4467, -80.3964, 1.50, 2.00),
("us_081", "FL Turnpike Yeehaw Junction", "FL-91", 27.5694, -80.9641, 2.37, 3.00),
("us_082", "FL Turnpike Wildwood Plaza", "FL-91", 28.8656, -82.0453, 1.98, 2.50),
# Chicago Skyway (I-90/94)
("us_090", "Chicago Skyway Toll", "I-90", 41.7287, -87.5527, 5.40, 6.00),
# I-95 Connecticut
("us_100", "Gold Star Bridge Toll (I-95 CT)", "I-95", 41.3556, -72.1127, 1.25, 1.25),
]
# Lookup: plaza_id β†’ (ezpass_rate, cash_rate)
US_SEED_RATES: Dict[str, tuple] = {
pid: (ezpass, cash)
for pid, *_, ezpass, cash in _US_PLAZAS
}
US_SEED_PLAZAS: List[Dict] = [
{
"plaza_id": pid,
"plaza_name": name,
"highway_number": hw,
"latitude": lat,
"longitude": lon,
"country": "United States",
}
for pid, name, hw, lat, lon, _e, _c in _US_PLAZAS
]
def get_seed_plazas(country: str) -> List[Dict]:
if country == "India":
return INDIA_SEED_PLAZAS
if country == "United States":
return US_SEED_PLAZAS
return []
def ensure_seeds_in_db(country: str):
"""
Reload seed plazas into the DB on every startup.
Uses DELETE + INSERT (not INSERT OR REPLACE) to guarantee that updated
coordinates from new code always replace whatever was stored before.
Also clears the route cache for this country whenever SEED_DATA_VERSION
changes, so stale cached routes that were computed with old plaza data
are never returned.
"""
import config as cfg
con = duckdb.connect(cfg.DB_PATH)
# ── Track seed version; clear route cache when it changes ────────────────
con.execute("""
CREATE TABLE IF NOT EXISTS seed_meta (
country VARCHAR PRIMARY KEY,
version VARCHAR
)
""")
row = con.execute(
"SELECT version FROM seed_meta WHERE country = ?", [country]
).fetchone()
stored_version = row[0] if row else None
if stored_version != SEED_DATA_VERSION:
# Version changed β†’ wipe cached routes so stale results are not served
con.execute("DELETE FROM route_cache WHERE country = ?", [country])
con.execute("""
INSERT INTO seed_meta (country, version) VALUES (?, ?)
ON CONFLICT (country) DO UPDATE SET version = excluded.version
""", [country, SEED_DATA_VERSION])
# ── Reload all seed plazas (DELETE then INSERT guarantees fresh coords) ──
con.execute(
"DELETE FROM osm_plazas WHERE country = ? AND plaza_id LIKE 'seed_%'",
[country],
)
for plaza in get_seed_plazas(country):
con.execute(
"""INSERT INTO osm_plazas
(plaza_id, plaza_name, highway_number, latitude, longitude, country, last_updated)
VALUES (?,?,?,?,?,?,?)""",
[
plaza["plaza_id"], plaza["plaza_name"], plaza["highway_number"],
plaza["latitude"], plaza["longitude"], plaza["country"],
datetime(2000, 1, 1),
],
)
con.close()