A proof-of-concept web app for the WattTime API: create an account, see on a map which grid regions and signals the account includes, then preview and download historical data as CSV. Built with Streamlit and hosted on Streamlit Community Cloud for internal testing.
Uses pixi. From the repo root:
pixi run app # http://localhost:8501
pixi run test # unit tests (HTTP is mocked; no API calls)Testers sign in with their own WattTime API account. The app itself needs no WattTime credentials.
The app reads three optional values with st.secrets. Locally they go in
.streamlit/secrets.toml (git-ignored); on Community Cloud, in the app's
Settings -> Secrets. Same TOML in both places:
UPGRADE_REQUEST_URL = "https://script.google.com/macros/s/<deployment-id>/exec"
UPGRADE_REQUEST_KEY = "<shared key>"
UPGRADE_REQUEST_EMAIL = "<address that receives upgrade requests>"UPGRADE_REQUEST_URL+UPGRADE_REQUEST_KEY: a Google Apps Script web app (scripts/upgrade_request.gs, setup steps at its top; the key must match itsSHARED_KEYproperty). The "Request permissions upgrade" button posts the signed-in username to it, and it emails the request. The same script records usage rows (below).UPGRADE_REQUEST_EMAIL: fallback. If the URL and key aren't set, or a send fails, the button opens a prefilled email to this address instead.- With none of the three set, the button is shown disabled.
Do this when WattTime publishes a new map (new regions, or a signal covering more
regions). It needs an ANALYST or PRO account, because /v3/maps is restricted.
export WATTTIME_USER=... WATTTIME_PASSWORD=...
pixi run fetch-maps # all signals in the account's my-accessThis downloads the full-resolution outlines to data/maps/ (git-ignored, ~34 MB),
writes simplified copies to data/boundaries/ (~4 MB, the files the app draws), and
then checks that every mapped region has a row in data/region_timezone.csv.
- If it lists missing regions, add a row for each to
data/region_timezone.csv: region code and IANA time zone name (e.g.Europe/Paris). The other two columns count the zones the region spans; use1,1for a single-zone region. Updatedata/region_timezone.SOURCE.txtif you re-copy the table from watttime-analysis-util. - Re-run
pixi run fetch-maps --skip-fetchto rebuild from the downloaded files and repeat the check without calling the API again. - Commit
data/boundaries/(and the time zone table if changed) and push tomain; Community Cloud redeploys automatically.
The simplified outlines are for drawing only. The region for a dropped pin comes
from /v3/region-from-loc, which uses the API's full-resolution shapes.
- Repository
WattTime/api-frontend, branchmain, main fileapp.py. - Python 3.13 (chosen under Advanced settings at deploy time).
- Paste the secrets above under Advanced settings -> Secrets, or later under Settings -> Secrets.
- Community Cloud installs from
requirements.txt, notpixi.toml. When you change a dependency, update both. - Each push to
mainredeploys.
Each step a session reaches (landing, sign-in, pin dropped, data downloaded, CSV
downloaded, upgrade requested, ...) is recorded once per session: as a line in the
app log (under Manage app), and as a row in the "usage" tab of the Google Sheet
named by the Apps Script's SHEET_ID property. A row has the UTC time, a random
session id, the username (blank before sign-in), the step, seconds since the
session started, the selected signal and region, and the host (local runs show
localhost). Steps are listed in usage_log.py's callers (grep usage_log.step).
| File | What it does |
|---|---|
app.py, routes.py |
Entry point and page routing |
auth.py, identity_pages.py |
Sign-in state and the sign-in / register / reset screens (simulated account screens; replace both for a real single sign-on) |
main_page.py |
The map, dates, download and preview steps |
wt_api.py |
WattTime API client: raw requests, one token per browser session |
access.py |
Reads /v3/my-access |
geo.py, map_view.py |
Region outlines and the map |
carpet.py |
Unit conversion, time averaging, the heatmap and the CSV |
upgrade.py, scripts/upgrade_request.gs |
Permissions-upgrade request |
boundary_build.py, scripts/fetch_maps.py |
Map outline refresh |
usage_log.py |
Usage rows for usability tests |
app_secrets.py |
Reads optional secrets |