File

global-context/services/domain/aggregation-validation.service.ts

Description

AggregationValidationService handles the validation of time ranges against aggregation type requirements in the global context system.

This service determines which aggregation types (MINUTELY, HOURLY, DAILY) are valid for a given time range based on predefined business rules. It provides the core validation logic that determines UI state and aggregation availability.

Key responsibilities:

  • Validate time ranges against minimum aggregation requirements
  • Calculate time range durations in milliseconds
  • Transform validation results into UI-friendly disabled state maps
  • Provide consistent validation logic across the application

Validation Rules:

  • MINUTELY: Disabled for time ranges <= 1 minute
  • HOURLY: Disabled for time ranges <= 1 hour
  • DAILY: Disabled for time ranges <= 1 day
Example :
const validationService = inject(AggregationValidationService);


// Validate a 2-hour time range
const dateRange: [Date, Date] = [
  new Date('2024-01-01T10:00:00Z'),
  new Date('2024-01-01T12:00:00Z')
];


const disabledAggregations = validationService.getDisabledAggregations(dateRange);
console.log(disabledAggregations);
// { DAILY: true, HOURLY: false, MINUTELY: false }


// Check if specific aggregation is valid
const isHourlyValid = validationService.isAggregationValid(dateRange, aggregationType.HOURLY);
console.log(isHourlyValid); // true (2 hours > 1 hour requirement)

Index

Methods

Methods

getDisabledAggregations
getDisabledAggregations(undefined: [Date, Date])

Determines which aggregation types should be disabled for a given time range.

This method validates the time range against all aggregation type requirements and returns a map indicating which aggregations should be disabled in the UI.

Example :
const shortRange: [Date, Date] = [
  new Date('2024-01-01T12:00:00Z'),
  new Date('2024-01-01T12:30:00Z') // 30 minutes
];


const disabled = validationService.getDisabledAggregations(shortRange);
// { DAILY: true, HOURLY: true, MINUTELY: false }
Parameters :
Name Type Optional
[Date, Date] No
Returns : Partial<Record<aggregationType, boolean>>

Map of aggregation types to their disabled boolean state

getTimeRangeInMs
getTimeRangeInMs(dateFrom: Date, dateTo: Date)

Calculates the time range duration in milliseconds.

This method provides a standardized way to calculate time range durations that can be used for validation and threshold comparisons.

Example :
const duration = validationService.getTimeRangeInMs(
  new Date('2024-01-01T10:00:00Z'),
  new Date('2024-01-01T12:00:00Z')
);
console.log(duration); // 7200000 (2 hours in milliseconds)
Parameters :
Name Type Optional Description
dateFrom Date No
  • Start date of the range
dateTo Date No
  • End date of the range
Returns : number

Duration in milliseconds between the two dates

isAggregationValid
isAggregationValid(undefined: [Date, Date], aggregation: aggregationType)

Checks if a specific aggregation type is valid for the given time range.

This method provides a convenient way to check if a single aggregation type meets the minimum time range requirements without needing to validate all types.

Example :
const oneHourRange: [Date, Date] = [
  new Date('2024-01-01T12:00:00Z'),
  new Date('2024-01-01T13:00:00Z')
];


const isMinutelyValid = validationService.isAggregationValid(oneHourRange, aggregationType.MINUTELY);
// true (1 hour > 1 minute requirement)


const isDailyValid = validationService.isAggregationValid(oneHourRange, aggregationType.DAILY);
// false (1 hour <= 1 day requirement)
Parameters :
Name Type Optional Description
[Date, Date] No
aggregation aggregationType No
  • The aggregation type to validate
Returns : boolean

True if the aggregation is valid for the time range, false if disabled

results matching ""

    No results matching ""