power-compare/scripts/seed_sample_data.py
dlawler489 84c4922bbc Initial commit: solar usage vs AER plan comparison app
FastAPI app that pulls interval usage from Sungrow iSolarCloud (OAuth2),
caches AER Consumer Data Right electricity plan data, and compares actual
metered usage against every available plan to estimate real annual cost
(TOU, tiered feed-in, and flat tariffs).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-09-09 11:07:01 +10:00

38 lines
1.2 KiB
Python

"""One-off CLI: backfill N days of synthetic usage data immediately, so the
dashboard/plan comparison can be demoed without waiting for the scheduler to
accumulate real-time polls. Always uses the mock client, regardless of
USE_MOCK_ISOLARCLOUD, since this is for local demoing/testing only.
Usage: python scripts/seed_sample_data.py --days 365
"""
from __future__ import annotations
import argparse
from datetime import datetime, timedelta, timezone
from app.db.repositories import upsert_interval_readings
from app.db.session import get_session, init_db
from app.isolarcloud.mock_client import MockISolarCloudClient
def main() -> None:
parser = argparse.ArgumentParser()
parser.add_argument("--days", type=int, default=365)
args = parser.parse_args()
init_db()
client = MockISolarCloudClient()
until = datetime.now(timezone.utc)
since = until - timedelta(days=args.days)
points = client.fetch_interval_data(since, until)
rows = [p.as_row("mock") for p in points]
with get_session() as session:
inserted = upsert_interval_readings(session, rows)
print(f"Generated {len(points)} points, inserted {inserted} new rows.")
if __name__ == "__main__":
main()