Skip to content

Commit

Permalink
Refactor videowallValidations to use getOperationalDate for operation…
Browse files Browse the repository at this point in the history
…al date calculations
  • Loading branch information
joao-vasconcelos committed Jan 29, 2025
1 parent e0b6cf0 commit ef863ed
Showing 1 changed file with 23 additions and 7 deletions.
30 changes: 23 additions & 7 deletions apps/sync-metrics/src/tasks/videowall-validations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import LOGGER from '@helperkits/logger';
import TIMETRACKER from '@helperkits/timer';
import { apexT11 } from '@tmlmobilidade/services/interfaces';
import { ALLOWED_VALIDATION_STATUSES, createOperationalDate, OPERATIONAL_DATE_FORMAT } from '@tmlmobilidade/services/types';
// import { getOperationalDate } from '@tmlmobilidade/services/utils';
import { getOperationalDate } from '@tmlmobilidade/services/utils';
import { DateTime } from 'luxon';

/* * */
Expand All @@ -23,7 +23,18 @@ export const videowallValidations = async () => {
// This takes in consideration the current time, as we want to compare today so far with the previous day so far, also.
// For example, today is monday 10h49. We want to compare the number of validations until 10h49 of today with the number of validations until 10h49 of last monday.

const todayOperationalDate = createOperationalDate('20250128'); // getOperationalDate();
const todayOperationalDate = getOperationalDate();

const yesterdayOperationalDate = createOperationalDate(
DateTime
.fromFormat(todayOperationalDate, OPERATIONAL_DATE_FORMAT)
.minus({ days: 1 })
.toFormat(OPERATIONAL_DATE_FORMAT),
);

const yesterdayUntilNow = DateTime
.now()
.minus({ days: 1 });

const lastWeekOperationalDate = createOperationalDate(
DateTime
Expand Down Expand Up @@ -70,7 +81,8 @@ export const videowallValidations = async () => {
// For Area 1
responseResult._41_today_valid_count = await apexT11.count({
agency_id: '41',
operational_date: todayOperationalDate,
created_at: { $lte: yesterdayUntilNow.toJSDate() },
operational_date: yesterdayOperationalDate,
validation_status: { $in: ALLOWED_VALIDATION_STATUSES },
});
responseResult._41_last_week_valid_count = await apexT11.count({
Expand All @@ -82,7 +94,8 @@ export const videowallValidations = async () => {
// For Area 2
responseResult._42_today_valid_count = await apexT11.count({
agency_id: '42',
operational_date: todayOperationalDate,
created_at: { $lte: yesterdayUntilNow.toJSDate() },
operational_date: yesterdayOperationalDate,
validation_status: { $in: ALLOWED_VALIDATION_STATUSES },
});
responseResult._42_last_week_valid_count = await apexT11.count({
Expand All @@ -94,7 +107,8 @@ export const videowallValidations = async () => {
// For Area 3
responseResult._43_today_valid_count = await apexT11.count({
agency_id: '43',
operational_date: todayOperationalDate,
created_at: { $lte: yesterdayUntilNow.toJSDate() },
operational_date: yesterdayOperationalDate,
validation_status: { $in: ALLOWED_VALIDATION_STATUSES },
});
responseResult._43_last_week_valid_count = await apexT11.count({
Expand All @@ -106,7 +120,8 @@ export const videowallValidations = async () => {
// For Area 4
responseResult._44_today_valid_count = await apexT11.count({
agency_id: '44',
operational_date: todayOperationalDate,
created_at: { $lte: yesterdayUntilNow.toJSDate() },
operational_date: yesterdayOperationalDate,
validation_status: { $in: ALLOWED_VALIDATION_STATUSES },
});
responseResult._44_last_week_valid_count = await apexT11.count({
Expand All @@ -118,7 +133,8 @@ export const videowallValidations = async () => {
// For the whole CM
responseResult._cm_today_valid_count = await apexT11.count({
agency_id: { $in: ['41', '42', '43', '44'] },
operational_date: todayOperationalDate,
created_at: { $lte: yesterdayUntilNow.toJSDate() },
operational_date: yesterdayOperationalDate,
validation_status: { $in: ALLOWED_VALIDATION_STATUSES },
});
responseResult._cm_last_week_valid_count = await apexT11.count({
Expand Down

0 comments on commit ef863ed

Please sign in to comment.