Skip to content

Latest commit

Β 

History

243 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸš† Klimaticket Calculator

A complete web app to track trips, calculate costs, and visualize statistics for the Austrian Klimaticket.

Live Demo: https://jhoelzl.github.io/klimaticket-rechner/


✨ Features

πŸ“Š Analytics & Reporting

  • πŸ”₯ Heatmap calendar – Visualize trips per day with intensity levels.
  • πŸ“… 12-month year overview – All months at a glance with stats.
  • πŸ“ˆ Monthly trends – Trips and costs by month.
  • πŸ—ΊοΈ States overview – Emoji cards for all 9 Austrian states.
  • πŸ“‹ Top 10 routes – Your most frequent routes.
  • πŸ“„ PDF export – Professional summary with all statistics.
  • πŸ† Achievements system – 12 Austria-themed badges (Obus Fan, S-Bahn Pro, State Hopper, etc.)

πŸ’Ύ Data Management

  • ☁️ Cloud sync with Supabase – Multi-device synchronization.
  • πŸ“± Offline support – Works without internet (PWA).
  • πŸ’Ύ Local fallback – localStorage for anonymous users.
  • πŸ“₯ JSON/CSV export & import – Data portability.
  • πŸ” Authentication – Email-based login via Supabase Auth.

🎨 UX/UI

  • 🌐 Multilingual – English and German with:
    • πŸ”„ Automatic browser language detection
    • πŸŽ›οΈ Manual language switching in settings
    • πŸ’Ύ Language preference storage (cloud & local)
    • ✨ Full UI translation support
  • πŸŒ“ Dark mode – Fully implemented with:
    • πŸ”„ Automatic system detection (prefers-color-scheme)
    • πŸŽ›οΈ Manual toggle in settings
    • πŸ’Ύ User preference storage
    • ✨ Smooth transitions between themes
    • 🎨 Optimized colors for better readability
  • ⚑ Quick-add buttons – Add frequent trips instantly (pre-configured routes)
  • πŸ–±οΈ Trip tooltip – Hover on calendar days for trip details
  • πŸ” Filters & search – Filter by route, state, date
  • βœ• Modal UX – Close via X button or ESC key
  • πŸ“± Responsive design – Mobile-first, works on all devices

πŸ”§ Configuration

  • 🌐 Language setting – Choose between English and German
  • πŸ’Ά Adjust ticket cost – Dynamic savings calculation
  • πŸ“… Set validity period – Start/end dates for ticket validity
  • ⏰ Automatic countdown – Days remaining until expiry
  • πŸŒ“ Dark mode – Toggle with automatic system detection

πŸš€ Quick Start

Installation

# Clone the repository
git clone https://github.com/jhoelzl/klimaticket-rechner.git
cd klimaticket_rechner

# Start locally with Python
python3 -m http.server 8000

# Open in browser
# http://localhost:8000

Install as PWA (iPhone/Android)

  1. iPhone: Safari β†’ Share button β†’ "Add to Home Screen"
  2. Android: Chrome β†’ Menu β†’ "Install app"
  3. App works offline with automatic cloud sync!

πŸ—„οΈ Database Structure (Supabase)

trips table

CREATE TABLE trips (
  id BIGINT PRIMARY KEY GENERATED ALWAYS AS IDENTITY,
  user_id UUID NOT NULL DEFAULT auth.uid(),
  date TEXT NOT NULL,                    -- ISO: YYYY-MM-DD
  route TEXT NOT NULL,                   -- e.g. "Salzburg - Vienna"
  cost DECIMAL(10,2) NOT NULL,           -- Cost in EUR
  distance DECIMAL(10,1),                -- Distance in kilometers (optional)
  bundeslaender TEXT[] DEFAULT '{}',     -- States array
  notes TEXT,
  created_at TIMESTAMP DEFAULT NOW(),
  updated_at TIMESTAMP DEFAULT NOW(),
  CONSTRAINT fk_user FOREIGN KEY (user_id) 
    REFERENCES auth.users(id) ON DELETE CASCADE
);

CREATE INDEX idx_user_date ON trips(user_id, date);
CREATE INDEX idx_user_route ON trips(user_id, route);
CREATE INDEX idx_distance ON trips(distance);

users table

CREATE TABLE users (
  user_id UUID PRIMARY KEY REFERENCES auth.users(id) ON DELETE CASCADE,
  ticket_cost DECIMAL(10,2) DEFAULT 1400.00,
  start_date DATE,
  end_date DATE,
  language VARCHAR(5) DEFAULT 'en',      -- Language preference: 'en', 'de'
  created_at TIMESTAMP DEFAULT NOW(),
  updated_at TIMESTAMP DEFAULT NOW()
);

Row Level Security (RLS)

ALTER TABLE trips ENABLE ROW LEVEL SECURITY;
ALTER TABLE users ENABLE ROW LEVEL SECURITY;

-- Trips: Users can only view/modify their own trips
CREATE POLICY "Users can view own trips" ON trips FOR SELECT
  USING (auth.uid() = user_id);
CREATE POLICY "Users can insert own trips" ON trips FOR INSERT
  WITH CHECK (auth.uid() = user_id);
CREATE POLICY "Users can update own trips" ON trips FOR UPDATE
  USING (auth.uid() = user_id);
CREATE POLICY "Users can delete own trips" ON trips FOR DELETE
  USING (auth.uid() = user_id);

-- Users: Users can only view/modify their own settings
CREATE POLICY "Users can manage own settings" ON users
  FOR ALL USING (auth.uid() = user_id);

πŸ” Authentication

With Login (Cloud)

1. Click "πŸ“§ Sign in" button
2. Enter email address
3. Open confirmation link from email
4. βœ… Done! Data stored in Supabase
5. πŸ“± Multi-device sync enabled

Anonymous (Local)

1. Open the app
2. Data stored directly in browser storage (localStorage)
3. Export/Import available for backup
4. ⚠️ No sync across devices

πŸ› οΈ Supabase Setup (for Developers)

1. Create a project

https://supabase.com β†’ Sign Up β†’ New Project
Region: Frankfurt (closest to Austria)
Password: Choose securely!

2. Create tables

Supabase Dashboard β†’ SQL Editor β†’ Copy-paste the SQL above

3. Environment Variables

# .env.local (NOT pushed to git)
VITE_SUPABASE_URL=https://YOUR-PROJECT.supabase.co
VITE_SUPABASE_ANON_KEY=YOUR-ANON-KEY

Find these at: Supabase Settings β†’ API β†’ Project URL + Publishable Key

4. Email templates (optional)

Supabase Dashboard β†’ Email Templates β†’ Customize branding


πŸ“ Project Structure

klimaticket_rechner/
β”œβ”€β”€ index.html              # Main HTML with embedded CSS/JS
β”œβ”€β”€ manifest.json           # PWA manifest
β”œβ”€β”€ sw.js                   # Service Worker (offline support)
β”œβ”€β”€ README.md               # This file
β”œβ”€β”€ docs/
β”‚   β”œβ”€β”€ FEATURES.md         # Feature roadmap
β”‚   β”œβ”€β”€ TEST_ANALYSIS.md    # Test analysis
β”‚   └── COVERAGE.md         # Coverage report
β”œβ”€β”€ .gitignore              # Git ignore file
└── .env.example            # Environment variables template

Tech Stack

  • Frontend: Vanilla HTML/CSS/JavaScript (no frameworks!)
  • Backend: Supabase (PostgreSQL + Auth)
  • Deployment: GitHub Pages
  • PWA: Service Worker + Web Manifest

πŸ“Š Features Overview

Homepage

  • πŸ”₯ Heatmap calendar (current month)
  • πŸ“… Year overview (all 12 months)
  • πŸ—ΊοΈ States overview with statistics
  • πŸ† Achievements with progress tracking
  • πŸ“‹ Trip list with filtering

Achievements System

The achievement system rewards frequent public transport usage with 12 Austria-themed badges:

Transit & Location Achievements:

  • 🚎 Obus Fan – 20 trips with the Obus
  • 🚈 S-Bahn Pro – 50 trips with the S-Bahn
  • πŸ”οΈ Salzburg Local Hero – 100 trips in Salzburg
  • πŸ‡¦πŸ‡Ή Austria Explorer – Visit 5 different states
  • πŸ‘‘ Austria Master – Visit all 9 states
  • πŸ—ΊοΈ State Hopper – 10 cross-state trips

Variety & Consistency:

  • 🧭 Route Collector – 15 unique routes
  • πŸ—“οΈ Monthly Champion – Trips in 6 different months
  • πŸŽ‰ Weekend Warrior – 20 weekend trips

Savings Achievements:

  • πŸ’° First Break-Even – Ticket paid off!
  • 🌱 Climate Champion – €500 in savings
  • πŸ’― Transit Pro – 100 trips total

Each badge shows your progress and unlocks with a toast notification!

Additional Features

  • ⚑ Quick-add buttons (frequent routes)
  • ✏️ Edit trip modal for adjustments
  • πŸ“Š PDF export (complete summary)
  • πŸ“₯ JSON/CSV import & export
  • βš™οΈ Settings for ticket configuration

🎯 Usage Examples

Scenario 1: Quick trip entry

1. Click "⚑ Quick Buttons"
2. E.g. "S-Bahn Sbg (€3.60)"
3. βœ… Done – Trip added with today's date

Scenario 2: Edit a trip

1. Click trip in trip list
2. ✏️ Edit trip modal opens
3. Modify data β†’ Save

Scenario 3: View statistics

1. πŸ”₯ Heatmap β†’ See daily trips
2. πŸ“… Year overview β†’ Monthly trends
3. πŸ—ΊοΈ States β†’ Which states visited most?

Scenario 4: Export to PDF

1. Bottom β†’ "πŸ“„ PDF Summary"
2. PDF with all stats is generated
3. Download or print

πŸ”„ Synchronization

Cloud Sync (with login)

Local Changes β†’ Supabase β†’ All Devices
Automatic on changes

Offline Mode

Without internet β†’ Changes buffered locally
β†’ Auto-sync when back online

Manual Sync

- JSON Export β†’ Backup
- CSV Export β†’ Spreadsheet-compatible
- Import from file supported

πŸ› Troubleshooting

Problem Solution
Supabase Connection Error Check .env.local – URL & key correct?
Data won't load Supabase Dashboard β†’ trips table exists?
Auth not working Supabase β†’ Email Templates β†’ SMTP correct?
Offline not working Browser Service Workers enabled?
PDF text cut off Set browser zoom to 100%, then 1 month per line

πŸš€ Deployment

GitHub Pages (Automatic)

git push origin main
# Automatically deploys to:
# https://jhoelzl.github.io/klimaticket-rechner/

Local Deployment

# Python SimpleHTTPServer
python3 -m http.server 8000
# or
npx http-server

πŸ“‹ Planned Features

See docs/FEATURES.md for complete roadmap with 50+ feature ideas:

  • Advanced filtering & search
  • Excel export (.xlsx)
  • COβ‚‚ tracking

πŸ’‘ Best Practices

Entering Data

  • πŸ“… Always use correct date
  • 🏘️ Add all states involved in trip
  • πŸ’¬ Notes help with tracking later

Security

  • πŸ” Use strong password
  • ☁️ With login = cloud backup
  • πŸ’Ύ Export backups regularly

Performance

  • πŸ”‹ Use offline mode when needed
  • πŸ“± Install PWA for faster access
  • πŸ—‘οΈ Archive old data if too much

🀝 Contributing

Contributions welcome!

# 1. Fork the repo
# 2. Create feature branch
git checkout -b feature/my-feature

# 3. Commit your changes
git commit -m "Add: my awesome feature"

# 4. Push to branch
git push origin feature/my-feature

# 5. Create pull request

πŸ“ License

MIT License – Free to use!


🎯 Support

  • Issues: Use GitHub Issues
  • Features: Check docs/FEATURES.md + create issue
  • Bugs: Report with screenshot/stacktrace

πŸ”— Links

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages