Skip to content

ghostkush/Hackathon_02_27

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

AquaCheck NYC πŸ’§

A full-stack web application that provides water quality scores for NYC ZIP codes using official NYC Open Data.

License Next.js FastAPI Python

🌟 Features

  • Real NYC Data: Uses official NYC Open Data from distribution monitoring sites
  • 178 NYC ZIP Codes: Covers all 5 boroughs (Manhattan, Brooklyn, Queens, Bronx, Staten Island)
  • 0-100 Quality Score: Easy-to-understand score based on 5 key water quality metrics
  • Detailed Metrics: Turbidity, chlorine, fluoride, coliform, and E. coli measurements
  • Filter Recommendations: Personalized filtration suggestions based on your water quality
  • Confidence Indicators: Know how recent and reliable the data is

πŸ“Š Data Sources

Dataset Source Description
Water Quality NYC Open Data bkwf-xfky Distribution monitoring measurements
ZIP Boundaries NYC Open Data pri4-ifjk NYC MODZCTA boundaries

πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”      β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”      β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                 β”‚      β”‚                 β”‚      β”‚                 β”‚
β”‚  Next.js 16     β”‚ ───► β”‚  FastAPI        β”‚ ───► β”‚  SQLite         β”‚
β”‚  Frontend       β”‚      β”‚  Backend        β”‚      β”‚  Database       β”‚
β”‚  (Port 3000)    β”‚      β”‚  (Port 8000)    β”‚      β”‚                 β”‚
β”‚                 β”‚      β”‚                 β”‚      β”‚                 β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜      β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜      β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
        β”‚                        β”‚
        β”‚                        β–Ό
        β”‚               β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
        β”‚               β”‚  NYC Open Data  β”‚
        β”‚               β”‚  (Socrata API)  β”‚
        β”‚               β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
        β”‚
        β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  User Browser   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸš€ Quick Start

Prerequisites

  • Node.js 18+ and npm
  • Python 3.10+
  • Git

Option 1: Development Mode

1. Clone the Repository

git clone https://github.com/ghostkush/Hackathon_02_27.git
cd Hackathon_02_27

2. Setup Backend

cd backend

# Create virtual environment
python3 -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate

# Install dependencies
pip install -r requirements.txt

# Run data pipeline (downloads NYC data and builds database)
python -m data_pipeline.ingest_sites
python -m data_pipeline.ingest_zips
python -m data_pipeline.ingest_water
python -m data_pipeline.build_zip_site_map
python -m data_pipeline.build_zip_summary

# Start backend server
uvicorn app.main:app --reload --port 8000

3. Setup Frontend (in a new terminal)

cd Hackathon_02_27

# Install dependencies
npm install

# Start development server
npm run dev

4. Open the App

Option 2: Docker Compose (Recommended for Production)

# Build and start both services
docker-compose up --build

# Or run in detached mode
docker-compose up -d --build

Access the app at http://localhost:3000

πŸ“ Project Structure

Hackathon_02_27/
β”œβ”€β”€ app/                      # Next.js app directory
β”‚   β”œβ”€β”€ api/
β”‚   β”‚   └── water-quality/    # API route (proxies to backend)
β”‚   β”œβ”€β”€ layout.tsx
β”‚   └── page.tsx              # Main page
β”œβ”€β”€ components/               # React components
β”‚   β”œβ”€β”€ water-results.tsx     # Results display
β”‚   β”œβ”€β”€ zip-search.tsx        # ZIP search input
β”‚   β”œβ”€β”€ score-ring.tsx        # Score visualization
β”‚   β”œβ”€β”€ contaminant-card.tsx  # Metric cards
β”‚   └── ui/                   # UI primitives
β”œβ”€β”€ backend/                  # Python FastAPI backend
β”‚   β”œβ”€β”€ app/
β”‚   β”‚   β”œβ”€β”€ main.py           # FastAPI application
β”‚   β”‚   β”œβ”€β”€ config.py         # Configuration
β”‚   β”‚   β”œβ”€β”€ db.py             # Database helpers
β”‚   β”‚   β”œβ”€β”€ models.py         # Pydantic models
β”‚   β”‚   β”œβ”€β”€ parsing.py        # Value parsing
β”‚   β”‚   β”œβ”€β”€ mapping.py        # ZIP-site mapping
β”‚   β”‚   └── scoring.py        # Scoring engine
β”‚   β”œβ”€β”€ data_pipeline/        # Data ingestion scripts
β”‚   β”‚   β”œβ”€β”€ ingest_sites.py
β”‚   β”‚   β”œβ”€β”€ ingest_zips.py
β”‚   β”‚   β”œβ”€β”€ ingest_water.py
β”‚   β”‚   β”œβ”€β”€ build_zip_site_map.py
β”‚   β”‚   └── build_zip_summary.py
β”‚   β”œβ”€β”€ water.db              # SQLite database (generated)
β”‚   β”œβ”€β”€ requirements.txt
β”‚   β”œβ”€β”€ Dockerfile
β”‚   └── README.md
β”œβ”€β”€ docker-compose.yml        # Docker orchestration
β”œβ”€β”€ Dockerfile                # Frontend Docker image
β”œβ”€β”€ package.json
β”œβ”€β”€ .env.local.example        # Environment template
└── README.md                 # This file

πŸ”Œ API Reference

GET /score

Get water quality score for an NYC ZIP code.

Request:

curl "http://localhost:8000/score?zip=10001"

Response:

{
  "zip": "10001",
  "score": 62,
  "confidence": "medium",
  "window": {
    "preferred_days": 30,
    "used_days": 180,
    "min_samples_30d": 10
  },
  "as_of": {
    "start": "2025-09-07",
    "end": "2025-12-28"
  },
  "sites_used": [
    {"sample_site": "33100", "distance_km": 3.12, "weight": 0.31}
  ],
  "metrics": {
    "turbidity": {"mean": 0.64, "min": 0.11, "max": 0.97, "n": 25},
    "residual_free_chlorine": {"mean": 0.70, "min": 0.45, "max": 0.87, "n": 25},
    "fluoride": {"mean": null, "min": null, "max": null, "n": 0},
    "coliform_mpn": {"mean": 0.5, "max": 0.5, "n": 25},
    "e_coli_mpn": {"mean": 0.5, "max": 0.5, "n": 25},
    "sample_count_total": 25
  },
  "recommendations": [
    "This score uses NYC distribution monitoring sites, not building plumbing."
  ],
  "notes": []
}

Other Endpoints

Endpoint Description
GET /health Health check with database stats
GET /stats Overall data statistics
GET /zips List all valid NYC ZIP codes
GET /docs Interactive Swagger UI

βš™οΈ Configuration

Environment Variables

Frontend (.env.local)

BACKEND_URL=http://localhost:8000

Backend

Variable Default Description
HOST 0.0.0.0 Server host
PORT 8000 Server port
CORS_ORIGINS http://localhost:3000 Allowed CORS origins (comma-separated)
SOCRATA_APP_TOKEN `` NYC Open Data API token (optional, increases rate limits)

πŸ“ˆ Scoring Algorithm

Base Score: 100

Penalties are applied based on water quality metrics:

Condition Penalty
E. coli max β‰₯ 1 MPN/100mL -50
E. coli mean β‰₯ 0.5 MPN/100mL -25
Coliform max β‰₯ 10 MPN/100mL -20
Coliform mean β‰₯ 1 MPN/100mL -10
Turbidity max β‰₯ 1.0 NTU -15
Turbidity mean β‰₯ 0.5 NTU -8
Chlorine mean < 0.2 mg/L -8
Medium confidence (stale data) -5
Low confidence (very stale data) -12

Final score: 0-100 (clamped)

Confidence Levels

  • High: Data within 30 days, β‰₯30 samples
  • Medium: Data within 180 days, β‰₯10 samples
  • Low: Older data or fewer samples

🚒 Deployment

Vercel + Railway/Render

  1. Frontend (Vercel):

    • Connect GitHub repo to Vercel
    • Set BACKEND_URL environment variable to your backend URL
  2. Backend (Railway/Render):

    # Railway
    railway init
    railway up
    
    # Or Render
    # Connect repo and set build command: pip install -r requirements.txt
    # Start command: uvicorn app.main:app --host 0.0.0.0 --port $PORT

Docker Production

# Build images
docker-compose build

# Run with custom environment
CORS_ORIGINS=https://your-domain.com docker-compose up -d

πŸ”„ Updating Data

To refresh the water quality data:

cd backend
source venv/bin/activate
python -m data_pipeline.ingest_water
python -m data_pipeline.build_zip_summary

This fetches the latest data from NYC Open Data and recomputes all scores.

πŸ§ͺ Testing

Backend

cd backend
source venv/bin/activate

# Test API endpoints
curl http://localhost:8000/health
curl http://localhost:8000/score?zip=10001

Frontend

npm run build
npm run lint

πŸ“ License

MIT License - see LICENSE for details.

πŸ™ Acknowledgments

  • NYC Open Data for providing water quality monitoring data
  • NYC DEP (Department of Environmental Protection)
  • Hackathon_02_27 team

Built with ❀️ for NYC

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors