@tmlmobilidade/export-data 20260421.1523.13 → 20260421.1529.44
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,58 +1,68 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
1
|
+
// ! THIS IS NOT WORKING, BECAUSE THE @tmlmobilidade/go-performance-pckg-dates is not a published package yet.
|
|
2
|
+
// import { type TaskProps } from '../../types.js';
|
|
3
|
+
// import { Dates } from '@tmlmobilidade/dates';
|
|
4
|
+
// import { type CalendarEntry, fetchCalendarData } from '@tmlmobilidade/go-performance-pckg-dates';
|
|
5
|
+
// import { rides } from '@tmlmobilidade/interfaces';
|
|
6
|
+
export {};
|
|
7
|
+
// export interface AgencyAverageRidesByDayTypeResult {
|
|
8
|
+
// agencyId: string
|
|
9
|
+
// averageRides: number
|
|
10
|
+
// dayType: string
|
|
11
|
+
// }
|
|
12
|
+
// export async function calculateAverageRidesByAgencyByDayType(
|
|
13
|
+
// { context, message }: TaskProps,
|
|
14
|
+
// ): Promise<AgencyAverageRidesByDayTypeResult[]> {
|
|
15
|
+
// message('Calculating average rides per agency by day type...');
|
|
16
|
+
// const ridesCollection = await rides.getCollection();
|
|
17
|
+
// const startDateStr = Dates.fromOperationalDate(context.dates.start, 'Europe/Lisbon').unix_timestamp;
|
|
18
|
+
// const endDateStr = Dates.fromOperationalDate(context.dates.end, 'Europe/Lisbon').unix_timestamp;
|
|
19
|
+
// // Load calendar JSON
|
|
20
|
+
// const calendarJson = await fetchCalendarData();
|
|
21
|
+
// // Build calendar map: operational_date -> CalendarEntry
|
|
22
|
+
// const calendarMap = new Map<string, CalendarEntry>();
|
|
23
|
+
// for (const day of calendarJson) {
|
|
24
|
+
// calendarMap.set(day.date.toString(), day);
|
|
25
|
+
// }
|
|
26
|
+
// // Mongo aggregation: count total rides per agency and date
|
|
27
|
+
// const aggCursor = ridesCollection.aggregate([
|
|
28
|
+
// {
|
|
29
|
+
// $match: {
|
|
30
|
+
// agency_id: { $exists: true },
|
|
31
|
+
// start_time_scheduled: { $gte: startDateStr, $lte: endDateStr },
|
|
32
|
+
// system_status: 'complete',
|
|
33
|
+
// },
|
|
34
|
+
// },
|
|
35
|
+
// {
|
|
36
|
+
// $group: {
|
|
37
|
+
// _id: { agencyId: '$agency_id', operationalDate: '$operational_date' },
|
|
38
|
+
// totalTrips: { $sum: 1 },
|
|
39
|
+
// },
|
|
40
|
+
// },
|
|
41
|
+
// ]);
|
|
42
|
+
// // Map in-memory: (agencyId + dayType) -> totalRides / totalDays
|
|
43
|
+
// const aggregationMap = new Map<string, { agencyId: string, dayType: string, totalDays: number, totalRides: number }>();
|
|
44
|
+
// for await (const doc of aggCursor) {
|
|
45
|
+
// const agencyId = doc._id.agencyId;
|
|
46
|
+
// const operationalDate = doc._id.operationalDate;
|
|
47
|
+
// const calendarProps = calendarMap.get(operationalDate);
|
|
48
|
+
// const dayType = calendarProps?.day_type ?? '1';
|
|
49
|
+
// const key = `${agencyId}:${dayType}`;
|
|
50
|
+
// if (!aggregationMap.has(key)) {
|
|
51
|
+
// aggregationMap.set(key, { agencyId, dayType, totalDays: 0, totalRides: 0 });
|
|
52
|
+
// }
|
|
53
|
+
// const entry = aggregationMap.get(key);
|
|
54
|
+
// entry.totalRides += doc.totalTrips;
|
|
55
|
+
// entry.totalDays += 1;
|
|
56
|
+
// }
|
|
57
|
+
// // Build final results
|
|
58
|
+
// const results: AgencyAverageRidesByDayTypeResult[] = [];
|
|
59
|
+
// for (const value of aggregationMap.values()) {
|
|
60
|
+
// results.push({
|
|
61
|
+
// agencyId: value.agencyId,
|
|
62
|
+
// averageRides: parseFloat((value.totalRides / value.totalDays).toFixed(2)),
|
|
63
|
+
// dayType: value.dayType,
|
|
64
|
+
// });
|
|
65
|
+
// }
|
|
66
|
+
// message(`Processed ${results.length} agency/day-type combinations`);
|
|
67
|
+
// return results;
|
|
68
|
+
// }
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { log } from 'node:console';
|
|
2
2
|
import fs from 'node:fs';
|
|
3
|
-
import { calculateAverageRidesByAgencyByDayType } from './avg-trips-day.js';
|
|
3
|
+
// import { calculateAverageRidesByAgencyByDayType } from './avg-trips-day.js';
|
|
4
4
|
import { calculateObservedTrips } from './empty-runs.js';
|
|
5
5
|
import { calculateSupplyMetrics } from './km.js';
|
|
6
6
|
import { calculateMedianSpeed } from './median-speed.js';
|
|
@@ -225,14 +225,13 @@ export async function exportExecutiveSummary({ context, message }) {
|
|
|
225
225
|
}
|
|
226
226
|
}
|
|
227
227
|
// Add avg_trips_day_type
|
|
228
|
-
const avgRidesByDayType = await calculateAverageRidesByAgencyByDayType({ context, message });
|
|
229
|
-
for (const row of avgRidesByDayType) {
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
}
|
|
228
|
+
// const avgRidesByDayType = await calculateAverageRidesByAgencyByDayType({ context, message });
|
|
229
|
+
// for (const row of avgRidesByDayType) {
|
|
230
|
+
// const agencyTotals = totalsByAgency[row.agencyId];
|
|
231
|
+
// if (!agencyTotals) continue;
|
|
232
|
+
// const dayTypeKey = `avg_trips_day_type ${row.dayType}` as const;
|
|
233
|
+
// agencyTotals[dayTypeKey] = row.averageRides;
|
|
234
|
+
// }
|
|
236
235
|
// Build final output
|
|
237
236
|
const finalOutput = {
|
|
238
237
|
timestamp: Date.now(),
|