Commit 0f6c1277 authored by Konstantinos Poulakakis's avatar Konstantinos Poulakakis
Browse files

Make static thresholds for testing purposes.

parent 890dbe11
Loading
Loading
Loading
Loading
+43 −0
Original line number Diff line number Diff line
@@ -15,6 +15,7 @@
import logging
from enum import Enum
import pandas as pd
from collections import defaultdict

logger = logging.getLogger(__name__)

@@ -134,3 +135,45 @@ def aggregation_handler(
            return results
        else:
            return []

def find(data , type , value):
    return next((item for item in data if item[type] == value), None)


def aggregation_handler_total_latency(
        batch_type_name, key, batch, input_kpi_list, output_kpi_list, thresholds
):
    """
      Process a batch of data and calculate aggregated values for each input KPI
      and maps them to the output KPIs. """

    # Group and sum
    # Track sum and count
    sum_dict = defaultdict(int)
    count_dict = defaultdict(int)

    for item in batch:
        kpi_id = item["kpi_id"]
        if kpi_id in input_kpi_list:
            sum_dict[kpi_id] += item["kpi_value"]
            count_dict[kpi_id] += 1

    # Compute average
    avg_dict = {kpi_id: sum_dict[kpi_id] / count_dict[kpi_id] for kpi_id in sum_dict}

    total_kpi_lat = 0
    for kpi_id, total_value in avg_dict.items():
        total_kpi_lat += total_value

    result = {
        "kpi_id": output_kpi_list[0],
        "avg": total_kpi_lat,
        "THRESHOLD_RAISE": bool(total_kpi_lat > 2600),
        "THRESHOLD_FALL": bool(total_kpi_lat < 699)
    }
    results = []

    results.append(result)
    logger.warning(f"result : {result}.")

    return results