Skip to content

feat: add /api/stats analytics endpoint#66

Open
AdityaAsopa wants to merge 2 commits intoisro:masterfrom
AdityaAsopa:feat/stats-endpoint
Open

feat: add /api/stats analytics endpoint#66
AdityaAsopa wants to merge 2 commits intoisro:masterfrom
AdityaAsopa:feat/stats-endpoint

Conversation

@AdityaAsopa
Copy link

Summary

Adds a new /api/stats endpoint that returns aggregate statistics computed at runtime across all five data collections.

Response shape

{
  "totals": {
    "spacecrafts": 113,
    "launchers": 81,
    "customer_satellites": 75,
    "centres": 44,
    "spacecraft_missions": 64
  },
  "spacecraft_missions": {
    "by_status": { "active": 3, "decommissioned": 44, "failed": 3, "unknown": 14 },
    "by_orbit_type": { "GEO": 22, "SSO": 12, ... },
    "by_mission_type": { "Communication": 15, ... }
  },
  "spacecrafts": {
    "by_status": { ... },
    "by_orbit_type": { ... }
  },
  "customer_satellites": {
    "by_country": { "USA": 10, ... },
    "total_mass_kg": 84235.2
  },
  "launchers": {
    "by_vehicle_family": { "PSLV": 30, ... }
  }
}

Design decisions

  • Nothing hardcoded — every number is derived by iterating the JSON arrays at request time. The response stays accurate automatically as data files are updated.
  • Null fields counted as "unknown" — consistent with the normalization approach in Normalize data schemas, enrich datasets, and fix API handler quality #65; no silent drops.
  • No new data — purely aggregates what already exists in the five data files.

Notes

This endpoint pairs naturally with the data normalization in PR #65 — the structured fields (orbit_type, status, mission_type) are what make these distributions meaningful. If #65 merges first, this PR applies cleanly on top.

Test plan

  • GET /api/stats returns valid JSON with Content-Type: application/json
  • All counts match record counts in the individual collection endpoints
  • total_mass_kg in customer_satellites matches manual sum of mass_kg fields
  • Re-running after a data update reflects new values without code changes

AdityaAsopa and others added 2 commits March 12, 2026 15:17
The spacecraft_missions data had deeply inconsistent schemas — mass appeared
as 'weight', 'lift-off_mass', 'spacecraft_mass', 'mass_at_lift-off' and
5 other variants; dates ranged from 'April 19, 1975' to '22 October 2008'
to '26-05-1999' across 15+ formats; KALPANA-1 had mission_life stored in
the 'mission' field as '7 Years'; and TES appeared as a duplicate entry.
spacecrafts.json had only id+name for 113 records. launchers.json had
only id for 81 records. customer_satellites.json mixed 'GERMANY' with
'Germany' and 'UK' with 'UNITED KINGDOM'.

This commit introduces scripts/normalize_data.py — an idempotent pipeline
that parses all date formats to ISO 8601, extracts numeric mass_kg and
power_watts from free-text fields (handling edge cases like '15 Sq.m Solar
Array generating 1360W'), classifies orbits (LEO/SSO/GEO/Lunar/Failed),
infers mission status from launch date + mission life, and normalizes
country names. The scraper was re-run against isro.gov.in and the fresh
data is merged with existing records — no data is lost, only enriched.

All 5 data files now have consistent, documented schemas. spacecrafts are
enriched with launch date, vehicle, orbit type, and status from missions.
Launchers are classified into 8 vehicle families. All API endpoints remain
backward-compatible — same URLs, same structure, just cleaner data.

API handlers: removed unused 'fs' imports, fixed misleading variable names
(customer_satellites.js loaded data into a var called 'launchers'), added
Content-Type: application/json headers, and sanitized error responses.
Root endpoint now returns a JSON directory of all available endpoints.
Returns aggregate statistics computed at runtime from the five data
collections: record counts, mission status distribution, orbit type
breakdown, mission type breakdown, spacecraft status, customer satellite
country distribution and total mass, and launcher vehicle family counts.

All values derived directly from the JSON data files — nothing hardcoded.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant