global-context/services/domain/aggregation-validation.service.ts
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:
Validation Rules:
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)
Methods |
| 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 :
Parameters :
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 :
Parameters :
Returns :
boolean
True if the aggregation is valid for the time range, false if disabled |