GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - ParaOrg/ParaOrganization: Powering the data and routing models behind Para PH. This repository handles real-world commute tracking, GTFS data processing, and ML model development to build better transit routing systems.

BranchesTags
Open more actions menu

Latest commit

 

History

29 Commits
29 Commits

Folders and files

NameName
Last commit message
Last commit date
geojson_data
geojson_data
 
 
.env.example
.env.example
 
 
.gitignore
.gitignore
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
admin_routes.py
admin_routes.py
 
 
api_routes.py
api_routes.py
 
 
biyahe_score.py
biyahe_score.py
 
 
config.py
config.py
 
 
database.py
database.py
 
 
debug_snap.py
debug_snap.py
 
 
diagnose_paths.py
diagnose_paths.py
 
 
filter_pedestrian_roads.py
filter_pedestrian_roads.py
 
 
graph_engine.py
graph_engine.py
 
 
ingest_pois.py
ingest_pois.py
 
 
llm_engine.py
llm_engine.py
 
 
main.py
main.py
 
 
models.py
models.py
 
 
requirements.txt
requirements.txt
 
 
smart_cache.py
smart_cache.py
 
 
tasks.py
tasks.py
 
 
telemetry_engine.py
telemetry_engine.py
 
 

Repository files navigation

Para PH — Backend

Multi-modal transit routing engine for Metro Manila, Philippines. Powers the Para PH commuting app with the Sakay Algorithm — a composite scoring system that ranks transit routes based on time, cost, hassle, safety, reliability, and community preference.


šŸ“‘ Table of Contents

  • šŸš€ Quick Start
  • 🧠 The Sakay Algorithm
  • šŸ“Š Graph Engine
  • šŸ—„ļø Database Schema
  • šŸ”Œ API Reference
  • šŸ“ File Structure
  • šŸŒ Location Resolution
  • šŸ› ļø Setup
  • šŸ“ License

šŸš€ Quick Start

pip install -r requirements.txt
cp .env.example .env  # Add your Supabase credentials
python main.py

API runs on http://localhost:8000. Docs at http://localhost:8000/docs.


🧠 The Sakay Algorithm

Why Not Just Dijkstra?

Dijkstra finds the shortest path by time. But Filipino commuters care about more than just speed — they balance cost, safety, familiarity, number of transfers, and reliability. A "faster" route with 4 transfers might be worse than a slightly slower route with 0 transfers.

How It Works

User types "from UPD to UST"
        │
        ā–¼
ā”Œā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”
│ llm_engine.py                │
│ parse_chat_intent()          │  → { origin: "upd", destination: "ust" }
│ normalize_location()         │  → GPS coordinates via gazetteer/Supabase/Nominatim
ā””ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”˜
        │
        ā–¼
ā”Œā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”
│ graph_engine.py              │
│ find_k_routes()              │  → Up to 3 candidate paths through transit graph
│                              │  → K-shortest paths using Yen's algorithm variant
ā””ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”˜
        │
        ā–¼
ā”Œā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”
│ biyahe_score.py              │
│ rank_routes()                │  → Scores each path on 6 factors
│                              │  → Returns ranked list with explanations
ā””ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”˜
        │
        ā–¼
ChatResponse with route_data + alternatives + Biyahe Scores

Biyahe Score Factors

Factor Weight (Default) What It Measures
Time 30% Total travel minutes
Cost 25% Total fare in pesos
Hassle 25% Number of transfers + walk distance
Safety 10% Route safety rating
Reliability 5% Route frequency/availability
Community 5% User ratings from tracked commutes

Preset Profiles

Users can choose weight profiles:

  • Balanced (default): Equal weight on time/cost/hassle
  • Budget: 50% cost, 10% time
  • Fastest: 60% time, 10% cost
  • Safest: 50% safety, 10% time
  • Comfort: 50% hassle (fewest transfers), 15% time

šŸ“Š Graph Engine

Transit Graph Structure

  • Nodes: Transit stops (coordinates like JeepneyRoute::14.656_121.069)
  • Edges: Directed connections between consecutive stops
  • Weight: time_min + (distance_km Ɨ 0.5) — optimizes for speed with slight distance penalty
  • Transfer edges: Walking connections between nearby stops on different routes (< 500m)

Directionality Rules

Vehicle Type Default Notes
Loop routes ONE-WAY Circles back to start
Train/LRT/MRT BIDIRECTIONAL Dedicated tracks
Jeep/Bus/UV BIDIRECTIONAL Unless marked is_oneway=true
Walking BIDIRECTIONAL Between transfer points

Walk Path Enhancement

Walk segments use OSRM (Open Source Routing Machine) to generate actual walking paths along roads and sidewalks — not just straight lines. Falls back to straight-line if OSRM is unavailable.


šŸ—„ļø Database Schema

Key tables managed via Supabase:

Table Purpose
ph_routes Route metadata (name, mode, directionality)
ph_route_shapes Route geometry (PostGIS LineString)
ph_places Points of interest with PostGIS location
ph_place_aliases Alternative names for places
ph_geocode_cache Cached geocoding results
ph_route_reference CSV-imported reference route names
session_messages Chat history
gas_stations Gas price tracking

šŸ”Œ API Reference

Core Endpoints

Method Endpoint Description
GET /health Server health + graph stats
POST /chat Natural language route finding
POST /route Programmatic lat/lng route calculation

Admin Endpoints

Method Endpoint Description
GET /admin/routes/list All routes
GET /admin/routes/geojson?route_id=X Single route geometry
GET /admin/routes/verified Approved routes only
GET /admin/routes/reference CSV reference routes
GET /admin/routes/compare Match reference vs verified routes
POST /admin/routes/rename Rename a route
POST /admin/routes/verify Mark route as verified
DELETE /admin/routes/{id} Delete route
POST /admin/routes/save Save community-submitted route
GET /admin/pending/list Pending approval routes
POST /admin/pending/approve Approve pending route
POST /admin/pending/reject Reject pending route

POI Endpoints

Method Endpoint Description
GET /poi/list All points of interest
POST /poi/add Add new POI

šŸ“ File Structure

File Purpose
main.py FastAPI app entry, lifespan, CORS, graph initialization
api_routes.py Chat endpoint, route calculation, POI endpoints
admin_routes.py Admin CRUD for routes, approvals
graph_engine.py Transit graph builder, Dijkstra pathfinding, K-shortest paths
llm_engine.py NLP intent parsing, location normalization, geocoding
biyahe_score.py Sakay Algorithm scoring engine with user profiles
models.py Pydantic data models for API
config.py Environment variable loading and validation
database.py Supabase REST client + connection management
smart_cache.py Caching layer for frequently accessed data
telemetry_engine.py GPS telemetry processing
tasks.py Background task definitions
ingest_pois.py POI data ingestion utilities

šŸŒ Location Resolution

normalize_location() resolves place names using a 4-tier system:

  1. In-memory gazetteer — 60+ Metro Manila landmarks (instant)
  2. Supabase ph_places — User-contributed POIs with PostGIS
  3. Supabase ph_place_aliases — Alternative names
  4. Nominatim — OpenStreetMap geocoding fallback

All successful resolutions are cached to ph_geocode_cache for future lookups.


šŸ› ļø Setup

Requirements

pip install -r requirements.txt

Environment Variables (.env)

SUPABASE_URL=https://your-project.supabase.co
SUPABASE_SERVICE_KEY=eyJ...your-service-role-key
DATABASE_URL=postgresql://postgres:[email protected]:5432/postgres
OLLAMA_HOST=http://localhost:11434  # Optional
ENV=development

Run the Server

python main.py

šŸ“ License

AGPL-3.0 — Open source. Built for Metro Manila commuters. šŸ‡µšŸ‡­

About

Powering the data and routing models behind Para PH. This repository handles real-world commute tracking, GTFS data processing, and ML model development to build better transit routing systems.

para-commute.org

Topics

commutecommute-timescommutingcommuting-patternsmachine-learningmachine-learning-algorithmsmachinelearning-pythonmobilitymobility-as-a-servicemobility-datamobility-modelingphilippines

Resources

Readme
AGPL-3.0 license
Activity
Custom properties

Stars

1 star

Watchers

0 watching

Forks

0 forks
Report repository

Releases

Packages

Contributors

Languages

You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800Ɨ600. No cookies required.