Skip to content

Commit

Permalink
Refactor MetricMonitorCriteria to improve type safety and enhance ali…
Browse files Browse the repository at this point in the history
…as handling in data processing
  • Loading branch information
simlarsen committed Dec 10, 2024
1 parent f575afa commit 397231f
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions Common/Server/Utils/Monitor/Criteria/MetricMonitorCriteria.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import AggregateModel from "../../../../Types/BaseDatabase/AggregatedModel";
import AggregatedResult from "../../../../Types/BaseDatabase/AggregatedResult";
import MetricQueryConfigData from "../../../../Types/Metrics/MetricQueryConfigData";
import MetricMonitorResponse from "../../../../Types/Monitor/MetricMonitor/MetricMonitorResponse";
import DataToProcess from "../DataToProcess";
import CompareCriteria from "./CompareCriteria";
Expand Down Expand Up @@ -30,19 +32,21 @@ export default class MetricMonitorCriteria {

if (metricAlias) {
// find the index of the alias in the dataToProcess.
const indexOfAlias = (
const indexOfAlias: number = (
input.dataToProcess as MetricMonitorResponse
).metricViewConfig.queryConfigs.findIndex((queryConfig) => {
return queryConfig.metricAliasData?.metricVariable === metricAlias;
});
).metricViewConfig.queryConfigs.findIndex(
(queryConfig: MetricQueryConfigData) => {
return queryConfig.metricAliasData?.metricVariable === metricAlias;
},
);

// now get the aggregated result for that alias
if (indexOfAlias !== -1) {
const aggregatedResultForAlias: AggregatedResult | undefined =
metricAggregaredResult[indexOfAlias];
if (aggregatedResultForAlias) {
const numbers: Array<number> = aggregatedResultForAlias.data.map(
(data) => {
(data: AggregateModel) => {
return data.value;
},
);
Expand All @@ -58,9 +62,11 @@ export default class MetricMonitorCriteria {

// if there's no alias then this is the default case
if (aggregatedResult) {
const numbers: Array<number> = aggregatedResult.data.map((data) => {
return data.value;
});
const numbers: Array<number> = aggregatedResult.data.map(
(data: AggregateModel) => {
return data.value;
},
);

return CompareCriteria.compareCriteriaNumbers({
value: numbers,
Expand Down

0 comments on commit 397231f

Please sign in to comment.