Skip to content

#9 Weekly earnings summary for drivers - #39

Open
anishsingla2910 wants to merge 1 commit into
wncc:mainfrom
anishsingla2910:issue-009-driver-weekly-earnings
Open

anishsingla2910 wants to merge 1 commit into
wncc:mainfrom
anishsingla2910:issue-009-driver-weekly-earnings

Conversation

@anishsingla2910

Copy link
Copy Markdown

Closes #9

What changed

Backend

  • GET /drivers/me/earnings?days=7 (days 1–31, drivers only): total earnings, trip count and a per-day list for completed rides, with a row for every day (0 when idle) so the app can draw each bar.
  • Days are counted in IST, not UTC (routing.IST): a ride finished at 00:30 in Mumbai belongs to that day, although it is still the previous evening in UTC. Grouping happens in Python, so SQLite and PostgreSQL behave the same.
  • New backend/app/services/earnings.py; response models EarningsOut / EarningsDayOut in schemas.py; endpoint documented in docs/BACKEND.md.

Driver app

  • api.earnings(days) and the Earnings types.
  • Earnings screen: under today's figure, "Last 7 days · ₹X · N trips" and a bar per day (Mon…Sun, "Today" last), with accessibility labels. Weekday names come from the calendar date, not from the phone's timezone (src/lib/earnings.ts).
  • Today's figure is unchanged for now (still from ride history on the phone's clock); happy to switch it to the endpoint's IST "today" in this PR or a follow-up, whichever you prefer.

Tests

  • backend/tests/test_api.py::test_driver_earnings_count_days_in_india_time: 23:30 IST stays on its day; 00:30 IST (19:00 UTC the previous evening) counts for the new day; a ride 7 days ago is outside days=7 and inside days=8; cancelled rides are not counted; empty days are 0; days=0/32 → 422; riders → 403.
  • Jest: earnings.test.ts (weekday label, bar scaling) and the api.earnings URL.
  • The e2e ride (e2e/run_e2e.py) now also checks "Last 7 days" and "1 trip" on the driver's Earnings screen.
  • python test_all.py passes: 124 Python tests, 34 Jest tests, typecheck, lint, and the 11-step browser ride.

Screenshot

Driver app after two rides (real phone, backend in straight-line mode):

1

Drivers saw only today's cash. Add GET /drivers/me/earnings?days=7 (1-31),
drivers only: completed rides summed per calendar day in India time, with
a row for every day so the app can draw each bar, plus the total and trip
count. Days are bucketed in IST, not UTC, so a ride finished at 00:30 in
Mumbai belongs to that day even though it is still the previous evening in
UTC.

Driver app: under today's figure, the week total and trip count and a bar
per day (Mon..Sun, "Today" last), with accessibility labels. Weekday names
are derived from the calendar date, not from the phone's timezone.

Tests: IST day boundaries (23:30 and 00:30), the window edge (days=7 vs 8),
cancelled rides not counted, empty days as 0, 422 outside 1-31, 403 for
riders; Jest for the API call and the label/bar helpers; the e2e ride now
also checks the week block on the Earnings screen.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Weekly earnings summary for drivers

1 participant