Exemplo n.º 1
0
        public List <CalculatedMetricsModel> makeRawDevicesCalculation(List <CalculatedMetricsModel> calculatedMetrics, List <RawMetric> rawMetricsToCalculate)
        {
            // average calculation
            CalculatedMetricsModel calculatedMetric = new CalculatedMetricsModel();

            calculatedMetric.DeviceId      = rawMetricsToCalculate[0].DeviceId;
            calculatedMetric.DateTimeStart = metricsLowestDate(rawMetricsToCalculate);
            calculatedMetric.DateTimeEnd   = metricsHighestDate(rawMetricsToCalculate);
            calculatedMetric.Value         = calcAverageValue(getRawMetricsValues(rawMetricsToCalculate));
            calculatedMetric.DataType      = "Average";
            calculatedMetrics.Add(calculatedMetric);
            // median calculation
            calculatedMetric               = new CalculatedMetricsModel();
            calculatedMetric.DeviceId      = rawMetricsToCalculate[0].DeviceId;
            calculatedMetric.DateTimeStart = metricsLowestDate(rawMetricsToCalculate);
            calculatedMetric.DateTimeEnd   = metricsHighestDate(rawMetricsToCalculate);
            calculatedMetric.Value         = calcMedianValue(getRawMetricsValues(rawMetricsToCalculate));
            calculatedMetric.DataType      = "Median";
            calculatedMetrics.Add(calculatedMetric);
            // highest value
            calculatedMetric               = new CalculatedMetricsModel();
            calculatedMetric.DeviceId      = rawMetricsToCalculate[0].DeviceId;
            calculatedMetric.DateTimeStart = metricsLowestDate(rawMetricsToCalculate);
            calculatedMetric.DateTimeEnd   = metricsHighestDate(rawMetricsToCalculate);
            calculatedMetric.Value         = calcHighestValue(getRawMetricsValues(rawMetricsToCalculate));
            calculatedMetric.DataType      = "HighestValue";
            calculatedMetrics.Add(calculatedMetric);
            // lowest value
            calculatedMetric               = new CalculatedMetricsModel();
            calculatedMetric.DeviceId      = rawMetricsToCalculate[0].DeviceId;
            calculatedMetric.DateTimeStart = metricsLowestDate(rawMetricsToCalculate);
            calculatedMetric.DateTimeEnd   = metricsHighestDate(rawMetricsToCalculate);
            calculatedMetric.Value         = calcLowestValue(getRawMetricsValues(rawMetricsToCalculate));
            calculatedMetric.DataType      = "LowestValue";
            calculatedMetrics.Add(calculatedMetric);
            return(calculatedMetrics);
        }
Exemplo n.º 2
0
        public List <CalculatedMetricsModel> Calculation(List <RawMetric> rawMetrics)
        {
            List <CalculatedMetricsModel> calculatedMetrics = new List <CalculatedMetricsModel>();
            CalculatedMetricsModel        calculatedMetric  = new CalculatedMetricsModel();
            List <RawMetric> rawMetricsToCalculate          = new List <RawMetric>(); // List of the values we want to make calculations on

            if (!(rawMetrics.Count <= 1))
            {
                for (int i = 0; i < rawMetrics.Count(); i++)
                {
                    if (i != (rawMetrics.Count() - 1))
                    {
                        // we also check here if we're not on the last item of the list
                        if (rawMetrics[i].DeviceId.Equals(rawMetrics[i + 1].DeviceId))
                        {
                            rawMetricsToCalculate.Add(rawMetrics[i]);
                        }
                        else
                        {
                            // do calculation
                            rawMetricsToCalculate.Add(rawMetrics[i]);
                            calculatedMetrics     = makeRawDevicesCalculation(calculatedMetrics, rawMetricsToCalculate);
                            rawMetricsToCalculate = new List <RawMetric>();
                        }
                    }
                    else
                    {
                        // do calculation
                        rawMetricsToCalculate.Add(rawMetrics[i]);
                        calculatedMetrics     = makeRawDevicesCalculation(calculatedMetrics, rawMetricsToCalculate);
                        rawMetricsToCalculate = new List <RawMetric>();
                    }
                }
            }
            return(calculatedMetrics);
        }