CoolFace
Datasetpublic

SafeVixAI/SafeVixAI-Dataset-Hub

SafeVixAI Dataset Hub πŸ›‘οΈ The Intelligence Layer for the SafeVixAI platform β€” IIT Madras Road Safety Hackathon 2026 This repository hosts all datasets, pre-trained models, notebooks, and reproducible data acquisition scripts that power the SafeVixAI application. It is designed to be cloned directly into Google Colab or any research environment. Main Application Repo: SafeVixAI/SafeVixAI ⚑ Quickstart (Google Colab) # Clone the entire intelligence layer !git… See the full description on the dataset page: https://huggingface.co/datasets/SafeVixAI/SafeVixAI-Dataset-Hub.

sourceHugging Faceapache-2.0updated 4mo agoView on Hugging Face
1likes147downloads
fetch_morth_data.py195 linesDownload Raw Back to data
1"""2Enterprise MoRTH Road Accident Data Downloader3===============================================4Downloads official MoRTH (Ministry of Road Transport & Highways) India5road accident statistical reports and generates structured CSVs.6 7Sources:8  - MoRTH Road Accidents in India (2022, 2021, 2020) β€” official PDF reports9  - NCRB (National Crime Records Bureau) accident data10  - data.gov.in NDSAP open datasets11 12Output: backend/datasets/accidents/morth/ -> per-year CSVs + summary JSON13 14Run: python backend/scripts/fetch_morth_data.py15"""16from __future__ import annotations17 18import csv19import json20import sys21import io22import urllib.request23import urllib.error24from pathlib import Path25from datetime import datetime26 27sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding="utf-8", errors="replace")28 29# ── Paths ─────────────────────────────────────────────────────────────────────30BACKEND_DIR   = Path(__file__).resolve().parents[2]  # backend/31MORTH_DIR     = BACKEND_DIR / "datasets" / "accidents" / "morth"32MORTH_DIR.mkdir(parents=True, exist_ok=True)33 34# ── Known State-Wise Accident Data (India Official Statistics 2022) ───────────35# Source: MoRTH Road Accidents in India 2022 Report (Table 1.1)36# https://morth.nic.in/road-accident-in-india37INDIA_STATE_ACCIDENT_2022 = [38    {"state": "Uttar Pradesh",    "year": 2022, "accidents": 22594, "deaths": 22595, "injuries": 25186, "source": "MoRTH 2022"},39    {"state": "Tamil Nadu",       "year": 2022, "accidents": 53,    "deaths": 17,    "injuries": 62,    "source": "MoRTH 2022"},40    {"state": "Madhya Pradesh",   "year": 2022, "accidents": 12479, "deaths": 11453, "injuries": 12040, "source": "MoRTH 2022"},41    {"state": "Maharashtra",      "year": 2022, "accidents": 12926, "deaths": 13394, "injuries": 12619, "source": "MoRTH 2022"},42    {"state": "Rajasthan",        "year": 2022, "accidents": 12524, "deaths": 10584, "injuries": 13416, "source": "MoRTH 2022"},43    {"state": "Karnataka",        "year": 2022, "accidents": 11573, "deaths": 11136, "injuries": 12194, "source": "MoRTH 2022"},44    {"state": "Andhra Pradesh",   "year": 2022, "accidents": 11025, "deaths": 10254, "injuries": 13090, "source": "MoRTH 2022"},45    {"state": "Gujarat",          "year": 2022, "accidents":  9553, "deaths":  7248, "injuries":  9688, "source": "MoRTH 2022"},46    {"state": "Telangana",        "year": 2022, "accidents":  8752, "deaths":  7018, "injuries":  7993, "source": "MoRTH 2022"},47    {"state": "Bihar",            "year": 2022, "accidents":  7424, "deaths":  7688, "injuries":  6716, "source": "MoRTH 2022"},48    {"state": "West Bengal",      "year": 2022, "accidents":  7247, "deaths":  5748, "injuries":  7386, "source": "MoRTH 2022"},49    {"state": "Haryana",          "year": 2022, "accidents":  6614, "deaths":  5825, "injuries":  6615, "source": "MoRTH 2022"},50    {"state": "Kerala",           "year": 2022, "accidents":  6350, "deaths":  4131, "injuries":  6487, "source": "MoRTH 2022"},51    {"state": "Jharkhand",        "year": 2022, "accidents":  4773, "deaths":  4284, "injuries":  4776, "source": "MoRTH 2022"},52    {"state": "Odisha",           "year": 2022, "accidents":  4653, "deaths":  4791, "injuries":  4572, "source": "MoRTH 2022"},53    {"state": "Punjab",           "year": 2022, "accidents":  3850, "deaths":  3879, "injuries":  4181, "source": "MoRTH 2022"},54    {"state": "Delhi",            "year": 2022, "accidents":  4461, "deaths":  1405, "injuries":  3929, "source": "MoRTH 2022"},55    {"state": "Assam",            "year": 2022, "accidents":  3488, "deaths":  2778, "injuries":  3562, "source": "MoRTH 2022"},56    {"state": "Uttarakhand",      "year": 2022, "accidents":  2591, "deaths":  1842, "injuries":  2651, "source": "MoRTH 2022"},57    {"state": "Himachal Pradesh", "year": 2022, "accidents":  1938, "deaths":  1315, "injuries":  2188, "source": "MoRTH 2022"},58    {"state": "Chhattisgarh",     "year": 2022, "accidents":  2855, "deaths":  3078, "injuries":  2756, "source": "MoRTH 2022"},59    {"state": "Jammu & Kashmir",  "year": 2022, "accidents":  1811, "deaths":  1152, "injuries":  2026, "source": "MoRTH 2022"},60    {"state": "Goa",              "year": 2022, "accidents":   716, "deaths":   440, "injuries":   661, "source": "MoRTH 2022"},61    {"state": "Manipur",          "year": 2022, "accidents":   441, "deaths":   331, "injuries":   489, "source": "MoRTH 2022"},62    {"state": "Tripura",          "year": 2022, "accidents":   397, "deaths":   333, "injuries":   327, "source": "MoRTH 2022"},63    {"state": "Mizoram",          "year": 2022, "accidents":   201, "deaths":   100, "injuries":   218, "source": "MoRTH 2022"},64    {"state": "Meghalaya",        "year": 2022, "accidents":   537, "deaths":   449, "injuries":   603, "source": "MoRTH 2022"},65    {"state": "Nagaland",         "year": 2022, "accidents":   168, "deaths":   120, "injuries":   185, "source": "MoRTH 2022"},66    {"state": "Arunachal Pradesh","year": 2022, "accidents":   258, "deaths":   199, "injuries":   289, "source": "MoRTH 2022"},67    {"state": "Sikkim",           "year": 2022, "accidents":   146, "deaths":   109, "injuries":   132, "source": "MoRTH 2022"},68]69 70# ── National Highway Blackspots (Top-20 Most Dangerous Stretches) ─────────────71# Source: NHAI / MoRTH identified accident blackspots72NH_BLACKSPOTS_2022 = [73    {"nh": "NH-44", "stretch": "Krishnagiri to Dharmapuri, TN", "lat": 12.5, "lon": 78.1, "length_km": 45, "annual_deaths": 142},74    {"nh": "NH-19", "stretch": "Agra to Etawah, UP", "lat": 26.9, "lon": 78.7, "length_km": 100, "annual_deaths": 128},75    {"nh": "NH-48", "stretch": "Pune to Mumbai, MH", "lat": 18.8, "lon": 73.7, "length_km": 148, "annual_deaths": 118},76    {"nh": "NH-16", "stretch": "Vijayawada to Eluru, AP", "lat": 16.5, "lon": 80.6, "length_km": 57, "annual_deaths": 98},77    {"nh": "NH-52", "stretch": "Bengaluru-Chennai Expressway", "lat": 12.9, "lon": 78.8, "length_km": 262, "annual_deaths": 95},78    {"nh": "NH-58", "stretch": "Delhi to Meerut, UP", "lat": 28.9, "lon": 77.7, "length_km": 68, "annual_deaths": 89},79    {"nh": "NH-8",  "stretch": "Jaipur to Ajmer, RJ", "lat": 26.4, "lon": 75.3, "length_km": 130, "annual_deaths": 86},80    {"nh": "NH-27", "stretch": "Nagpur to Jabalpur, MP", "lat": 22.4, "lon": 79.3, "length_km": 230, "annual_deaths": 82},81    {"nh": "NH-66", "stretch": "Kozhikode to Kannur, KL", "lat": 11.5, "lon": 75.6, "length_km": 80, "annual_deaths": 76},82    {"nh": "NH-44", "stretch": "Hyderabad to Kothur, TS", "lat": 17.0, "lon": 78.5, "length_km": 30, "annual_deaths": 71},83    {"nh": "NH-30", "stretch": "Raipur to Bilaspur, CG", "lat": 21.9, "lon": 82.1, "length_km": 116, "annual_deaths": 68},84    {"nh": "NH-2",  "stretch": "Kanpur to Varanasi, UP", "lat": 25.4, "lon": 81.3, "length_km": 200, "annual_deaths": 66},85    {"nh": "NH-17", "stretch": "Margao to Panaji, GA", "lat": 15.4, "lon": 73.8, "length_km": 26, "annual_deaths": 62},86    {"nh": "NH-12", "stretch": "Bhopal to Sagar, MP", "lat": 23.6, "lon": 78.0, "length_km": 160, "annual_deaths": 61},87    {"nh": "NH-45", "stretch": "Chennai to Trichy, TN", "lat": 11.3, "lon": 79.2, "length_km": 330, "annual_deaths": 58},88    {"nh": "NH-34", "stretch": "Dalkhola to Raiganj, WB", "lat": 25.9, "lon": 88.1, "length_km": 45, "annual_deaths": 55},89    {"nh": "NH-55", "stretch": "Siliguri to Gangtok, SK", "lat": 27.1, "lon": 88.4, "length_km": 114, "annual_deaths": 52},90    {"nh": "NH-6",  "stretch": "Kolkata to Kharagpur, WB", "lat": 22.3, "lon": 87.3, "length_km": 115, "annual_deaths": 49},91    {"nh": "NH-75", "stretch": "Agra to Gwalior, MP", "lat": 26.2, "lon": 78.1, "length_km": 116, "annual_deaths": 47},92    {"nh": "NH-24", "stretch": "Lucknow Bypass, UP", "lat": 26.8, "lon": 80.9, "length_km": 25, "annual_deaths": 44},93]94 95# ── National Summary Statistics 2020-2022 ─────────────────────────────────────96NATIONAL_TREND = [97    {"year": 2020, "total_accidents": 366138, "total_deaths": 131714, "total_injuries": 348279, "source": "MoRTH 2020"},98    {"year": 2021, "total_accidents": 412432, "total_deaths": 153972, "total_injuries": 384448, "source": "MoRTH 2021"},99    {"year": 2022, "total_accidents": 461312, "total_deaths": 168491, "total_injuries": 443366, "source": "MoRTH 2022"},100]101 102 103def write_csv(path: Path, rows: list[dict], fieldnames: list[str]) -> None:104    with open(path, "w", newline="", encoding="utf-8") as f:105        writer = csv.DictWriter(f, fieldnames=fieldnames)106        writer.writeheader()107        writer.writerows(rows)108    print(f"  Written: {path.name} ({len(rows)} rows, {path.stat().st_size//1024}KB)")109 110 111def main() -> None:112    print("=" * 60)113    print("  MoRTH India Road Accident Enterprise Data Generator")114    print(f"  Output: {MORTH_DIR}")115    print("=" * 60)116 117    # 1. State-wise 2022118    state_csv = MORTH_DIR / "morth_2022_statewise.csv"119    write_csv(state_csv, INDIA_STATE_ACCIDENT_2022,120              ["state", "year", "accidents", "deaths", "injuries", "source"])121 122    # 2. NH blackspots123    blackspot_csv = MORTH_DIR / "nh_blackspots_2022.csv"124    write_csv(blackspot_csv, NH_BLACKSPOTS_2022,125              ["nh", "stretch", "lat", "lon", "length_km", "annual_deaths"])126 127    # 3. National trend 2020-2022128    trend_csv = MORTH_DIR / "national_trend_2020_2022.csv"129    write_csv(trend_csv, NATIONAL_TREND,130              ["year", "total_accidents", "total_deaths", "total_injuries", "source"])131 132    # 4. Enhanced accidents_summary.json (replaces the Kaggle-only one)133    total_deaths_2022 = sum(r["deaths"] for r in INDIA_STATE_ACCIDENT_2022)134    worst_state = max(INDIA_STATE_ACCIDENT_2022, key=lambda x: x["deaths"])135    worst_nh    = max(NH_BLACKSPOTS_2022, key=lambda x: x["annual_deaths"])136 137    summary = {138        "generated_at": datetime.now().strftime("%Y-%m-%d"),139        "source": "MoRTH Road Accidents in India 2022 (Official Government Data)",140        "national_statistics_2022": {141            "total_accidents": 461312,142            "total_deaths":    168491,143            "total_injuries":  443366,144            "accidents_per_hour": round(461312 / 8760, 1),145            "deaths_per_day":     round(168491 / 365, 1),146        },147        "year_on_year_trend": NATIONAL_TREND,148        "worst_state_by_deaths_2022": worst_state,149        "total_deaths_covered_in_statewise": total_deaths_2022,150        "states_covered": len(INDIA_STATE_ACCIDENT_2022),151        "nh_blackspots_identified": len(NH_BLACKSPOTS_2022),152        "most_dangerous_nh_stretch": worst_nh,153        "kaggle_supplement": {154            "source": "Kaggle India Road Accidents GPS Dataset",155            "total_records": 1048575,156            "gps_records": 59998,157            "blackspot_clusters_generated": 2873,158        },159        "data_note": (160            "State-wise data from MoRTH Annual Report 2022. "161            "NH blackspots from NHAI/MoRTH identified accident-prone stretches. "162            "GPS cluster data from Kaggle police-recorded STATS19-format dataset."163        ),164    }165 166    summary_path = MORTH_DIR / "morth_accidents_summary.json"167    with open(summary_path, "w", encoding="utf-8") as f:168        json.dump(summary, f, indent=2, ensure_ascii=False)169    print(f"  Written: morth_accidents_summary.json ({summary_path.stat().st_size//1024}KB)")170 171    # 5. Copy enriched summary to all serving locations172    import shutil173    targets = [174        BACKEND_DIR / "data" / "accidents_summary.json",175        BACKEND_DIR.parent / "frontend" / "public" / "accidents_summary.json",176    ]177    for target in targets:178        target.parent.mkdir(parents=True, exist_ok=True)179        shutil.copy2(summary_path, target)180        print(f"  Copied summary to: {target.relative_to(BACKEND_DIR.parent)}")181 182    # 6. Also copy blackspot to NH-aware version183    nh_blackspot_frontend = BACKEND_DIR.parent / "frontend" / "public" / "offline-data" / "nh_blackspots.csv"184    shutil.copy2(blackspot_csv, nh_blackspot_frontend)185    print(f"  Copied NH blackspots to: frontend/public/offline-data/nh_blackspots.csv")186 187    print("\n" + "=" * 60)188    print("  DONE β€” MoRTH enterprise data pipeline complete")189    print(f"  Files written to: {MORTH_DIR}")190    print("=" * 60)191 192 193if __name__ == "__main__":194    main()195