@tmlmobilidade/export-data 20260421.1523.13 → 20260422.819.52

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
- import { Dates } from '@tmlmobilidade/dates';
2
- import { fetchCalendarData } from '@tmlmobilidade/go-performance-pckg-dates';
3
- import { rides } from '@tmlmobilidade/interfaces';
4
- export async function calculateAverageRidesByAgencyByDayType({ context, message }) {
5
- message('Calculating average rides per agency by day type...');
6
- const ridesCollection = await rides.getCollection();
7
- const startDateStr = Dates.fromOperationalDate(context.dates.start, 'Europe/Lisbon').unix_timestamp;
8
- const endDateStr = Dates.fromOperationalDate(context.dates.end, 'Europe/Lisbon').unix_timestamp;
9
- // Load calendar JSON
10
- const calendarJson = await fetchCalendarData();
11
- // Build calendar map: operational_date -> CalendarEntry
12
- const calendarMap = new Map();
13
- for (const day of calendarJson) {
14
- calendarMap.set(day.date.toString(), day);
15
- }
16
- // Mongo aggregation: count total rides per agency and date
17
- const aggCursor = ridesCollection.aggregate([
18
- {
19
- $match: {
20
- agency_id: { $exists: true },
21
- start_time_scheduled: { $gte: startDateStr, $lte: endDateStr },
22
- system_status: 'complete',
23
- },
24
- },
25
- {
26
- $group: {
27
- _id: { agencyId: '$agency_id', operationalDate: '$operational_date' },
28
- totalTrips: { $sum: 1 },
29
- },
30
- },
31
- ]);
32
- // Map in-memory: (agencyId + dayType) -> totalRides / totalDays
33
- const aggregationMap = new Map();
34
- for await (const doc of aggCursor) {
35
- const agencyId = doc._id.agencyId;
36
- const operationalDate = doc._id.operationalDate;
37
- const calendarProps = calendarMap.get(operationalDate);
38
- const dayType = calendarProps?.day_type ?? '1';
39
- const key = `${agencyId}:${dayType}`;
40
- if (!aggregationMap.has(key)) {
41
- aggregationMap.set(key, { agencyId, dayType, totalDays: 0, totalRides: 0 });
42
- }
43
- const entry = aggregationMap.get(key);
44
- entry.totalRides += doc.totalTrips;
45
- entry.totalDays += 1;
46
- }
47
- // Build final results
48
- const results = [];
49
- for (const value of aggregationMap.values()) {
50
- results.push({
51
- agencyId: value.agencyId,
52
- averageRides: parseFloat((value.totalRides / value.totalDays).toFixed(2)),
53
- dayType: value.dayType,
54
- });
55
- }
56
- message(`Processed ${results.length} agency/day-type combinations`);
57
- return results;
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
- const agencyTotals = totalsByAgency[row.agencyId];
231
- if (!agencyTotals)
232
- continue;
233
- const dayTypeKey = `avg_trips_day_type ${row.dayType}`;
234
- agencyTotals[dayTypeKey] = row.averageRides;
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(),
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tmlmobilidade/export-data",
3
3
  "description": "CLI tool to export data from GO.",
4
- "version": "20260421.1523.13",
4
+ "version": "20260422.819.52",
5
5
  "author": {
6
6
  "email": "iso@tmlmobilidade.pt",
7
7
  "name": "TML-ISO"
@@ -39,7 +39,6 @@
39
39
  "@clack/prompts": "1.2.0",
40
40
  "@tmlmobilidade/consts": "*",
41
41
  "@tmlmobilidade/dates": "*",
42
- "@tmlmobilidade/go-performance-pckg-dates": "*",
43
42
  "@tmlmobilidade/interfaces": "*",
44
43
  "@tmlmobilidade/strings": "*",
45
44
  "@tmlmobilidade/timer": "*",