production

This commit is contained in:
2026-08-28 11:13:15 +05:30
parent d7348e253f
commit 5723d373b2
162 changed files with 17924 additions and 7026 deletions

View File

@@ -10,11 +10,22 @@ class SummaryProvider {
Future<PickupStats?> fetchSummaryStats(int userId) => _fetchSummaryStatsNew();
/// NEW API: GET /miler/earnings?period=daily|weekly|monthly
/// -> data:{ completed_stops, total_kms, total_earnings, total_bonus }.
/// PickupStats is stop COUNTS per period; map completed_stops for each.
/// `GET /miler/earnings?period=daily|weekly|monthly`
///
/// → `data: { completed_stops, cancelled_stops, total_stops, total_kms,
/// total_earnings, total_bonus }`.
///
/// ── The success rate is read, not derived ──
///
/// `cancelled_stops` and `total_stops` did not exist, so the page computed a
/// success rate from `completed_stops` alone — which is a rate with no
/// denominator, and it read 100% on a day with three cancellations. Both
/// counts ship now and the figures come off the response.
///
/// The three period calls stay three calls: the endpoint answers for one
/// period at a time, and the page shows all three.
Future<PickupStats?> _fetchSummaryStatsNew() async {
Future<int> stops(String period) async {
Future<({int done, int cancelled, int total})> stops(String period) async {
try {
final uri = Uri.parse(
ApiConfig.url('/miler/earnings'),
@@ -25,25 +36,34 @@ class SummaryProvider {
final d = (decoded is Map && decoded['data'] is Map)
? decoded['data'] as Map
: {};
return int.tryParse('${d['completed_stops'] ?? 0}') ?? 0;
int n(String key) => int.tryParse('${d[key] ?? 0}') ?? 0;
final done = n('completed_stops');
final cancelled = n('cancelled_stops');
// A server that has not shipped `total_stops` yet answers 0, and a
// total below the completed count is not a total — fall back to what
// is certainly true rather than printing a rate over nothing.
final reported = n('total_stops');
final total = reported >= done + cancelled
? reported
: done + cancelled;
return (done: done, cancelled: cancelled, total: total);
}
} catch (_) {}
return 0;
return (done: 0, cancelled: 0, total: 0);
}
final today = await stops('daily');
final week = await stops('weekly');
final month = await stops('monthly');
ApiConfig.logGap(
'summaryStats',
'v1 earnings has no cancelled/total count; derived from completed_stops.',
);
return PickupStats(
today: today,
week: week,
month: month,
total: month,
cancelled: 0,
today: today.done,
week: week.done,
month: month.done,
total: month.total,
// Was hardcoded to zero because nothing reported it. It is the month's
// figure, to match `total` — the two are one fraction and must come from
// one period or the rate is nonsense.
cancelled: month.cancelled,
);
}
}