Skip to content

if-else-repeat/ecolens_tracker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🌿 EcoLens — Personal Carbon Footprint Awareness Platform

Carbon Footprint Awareness Platform
Helping individuals understand, track, and reduce their carbon footprint through simple actions and personalized AI insights.


📌 Chosen Vertical

Individual Climate Action — A smart, dynamic assistant that takes personal lifestyle inputs, computes a scientifically-grounded carbon footprint, benchmarks it against global data, and delivers AI-powered, personalized reduction strategies.


✨ Features

1. 🧮 Carbon Calculator

  • 5 categories: Transport · Diet · Home Energy · Flights · Shopping
  • Inputs are validated, sanitised, and constrained to safe ranges
  • All math runs client-side — pure functions, no server needed
  • Emission factors sourced from IPCC AR6, DEFRA 2023, IEA 2023

2. 📊 Results Dashboard

  • Score card with colour-coded grade (A / B / C)
  • Benchmark comparison — vs. Paris 2°C target, India avg, World avg, US avg, EU avg
  • Per-category breakdown chips — see exactly where your emissions come from
  • Radar chart — visual impact profile across all 5 dimensions

3. 🤖 AI-Powered Insights (Claude API)

  • Calls claude-sonnet-4-20250514 with your exact footprint data
  • Returns 3 specific, ranked, actionable insights — personalised to your inputs
  • Focuses on highest-impact categories first
  • Graceful error fallback if API is unavailable

4. ✅ Action Pledge Tracker

  • 10 curated high-impact actions with verified CO₂ savings (IPCC-cited)
  • Toggle pledges — see real-time projected savings
  • Shows new footprint after pledged reductions

5. 🌍 World Climate Data Page

  • Accessible via the globe icon (🌍) in the nav
  • Live-representative stats: atmospheric CO₂ (ppm), global temp anomaly, annual emissions
  • CO₂ trend chart — 12-month Mauna Loa data (NOAA)
  • Country emissions bar chart — per-capita comparison
  • 6 curated editorial articles with filterable tags — real data, cited sources
  • Designed as a "why it matters" context layer

🧠 Approach & Logic

Emission Calculation (Pure Functions)

Each category is a standalone pure function — deterministic, side-effect free, independently testable:

// Example: Transport
function calcTransportEmissions(data) {
  const factor = EMISSION_FACTORS.transport[data.transport_mode] ?? 0;
  const annualKm = (data.daily_km || 0) * 365;
  return factor * annualKm; // returns kg CO₂e
}

All results are converted to tonnes CO₂e/year for display.

Emission Factors (Sources)

Category Factor Source
Petrol car 0.192 kg CO₂e/km DEFRA 2023
Electric car 0.053 kg CO₂e/km IEA 2023
Vegan diet 1.5 kg CO₂e/day Nature Food 2021
Heavy meat 7.5 kg CO₂e/day Nature Food 2021
Grid electricity 0.233 kg CO₂e/kWh IEA Global Avg 2023
Short-haul flight 255 kg CO₂e/flight IPCC AR6
Long-haul flight 1,950 kg CO₂e/flight IPCC AR6

AI Insight Generation

The AI prompt includes:

  • All 5 category values (labelled with the user's actual inputs)
  • Total vs. Paris target, global avg, India avg
  • Instruction to prioritise highest-impact categories
  • Hard constraint: plain text, under 200 words, 3 insights

This produces specific, honest, non-generic advice — not "use public transport" if transport is already zero.


⚡ Performance & Efficiency

  • Client-side calc — zero latency, no server round-trip for core functionality
  • AI called once per calculation — not on every keystroke
  • Conditional rendering — results section only mounts after calculation
  • Recharts — SVG-based, lightweight, no canvas overhead
  • Single bundle — entire app is one JSX file, ~600 lines, minimal dependencies
  • CSS-in-JS via template literal — no runtime CSS-in-JS library overhead

🧪 Testing Strategy

Because all calculation logic is pure functions, they are trivially unit-testable:

// Example test (Jest / Vitest)
import { calcTotalFootprint } from './EcoLens';

test('vegan cyclist has near-zero transport + low diet', () => {
  const result = calcTotalFootprint({
    transport_mode: 'bicycle',
    daily_km: 10,
    diet_type: 'vegan',
    electricity_kwh: 200,
    gas_kwh: 0,
    short_flights: 0,
    medium_flights: 0,
    long_flights: 0,
    shopping_habit: 'minimal',
  });
  expect(result.transport).toBe(0);
  expect(result.diet).toBeCloseTo(0.55, 1);
  expect(result.total).toBeLessThan(2.0); // below Paris target
});

test('heavy meat eater with daily car commute exceeds world avg', () => {
  const result = calcTotalFootprint({
    transport_mode: 'car_petrol',
    daily_km: 40,
    diet_type: 'heavy_meat',
    electricity_kwh: 500,
    gas_kwh: 200,
    short_flights: 4,
    medium_flights: 2,
    long_flights: 1,
    shopping_habit: 'heavy',
  });
  expect(result.total).toBeGreaterThan(4.8); // above world avg
});

To run tests:

npm install
npx vitest run

📐 Assumptions

  1. Grid electricity factor — uses global average (0.233 kg CO₂e/kWh). In India this is ~0.71; globally varies 0.02 (Norway hydro) to 0.9 (coal grids). A region selector could refine this.
  2. Diet values — daily averages based on Nature Food 2021 meta-analysis across multiple countries. Individual variation is high.
  3. Flights — uses IPCC radiative forcing multiplier of ~2x for non-CO₂ effects (contrails, NOₓ) already baked into the per-flight figures.
  4. Shopping — a coarse proxy. Covers clothing, electronics, furniture. Does not separate categories (future: itemised shopping inputs).
  5. AI insights — require a valid API key. App is fully functional without it — only the insight panel degrades gracefully.
  6. "Live" climate data — the World page displays representative 2023–2024 values from published sources (NOAA, IEA, GCP). They are not polled in real-time from an API (no API key required for the world page).

🏗️ Future Roadmap

  • Region-specific grid emission factors
  • Historical tracking (localStorage) — footprint over months
  • Social sharing — "I pledged to save X tonnes"
  • Offset marketplace integration
  • Itemised shopping calculator
  • Multi-language support (Hindi, Tamil, etc.)

📚 Data Sources

About

Personal Carbon Footprint Tracker

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors