Exemple #1
0
        private static ComponentData GetDelta(ComponentData currentData, ComponentData previousData)
        {
            var delta = new ComponentData
            {
                Name     = currentData.Name,
                Guid     = currentData.Guid,
                Duration = currentData.Duration
            };

            var commonMetricNames = currentData.Metrics.Select(m => m.Key).Intersect(previousData.Metrics.Select(m => m.Key));

            commonMetricNames.ForEach(mn =>
            {
                var currentVal  = currentData.Metrics[mn];
                var previousVal = previousData.Metrics[mn];

                if (!MetricMapper.IsMetricNumeric(currentVal))
                {
                    //Simply add the latest value
                    delta.Metrics.Add(mn, currentVal);
                }

                //Add metric as Positive Change, if negative add 0 as value
                if (currentVal is decimal)
                {
                    var currentValDecimal  = (decimal)currentVal;
                    var previousValDecimal = (decimal)previousVal;

                    var val = 0.0m;
                    if (currentValDecimal >= previousValDecimal)
                    {
                        val = currentValDecimal - previousValDecimal;
                    }

                    _VerboseMetricsLogger.InfoFormat("Generated Delta for Component: {0}; Metric: {1}; Value: {2}", currentData.Name, mn, val);

                    delta.Metrics.Add(mn, val);
                }
                else if (currentVal is int)
                {
                    var currentValInt  = (int)currentVal;
                    var previousValInt = (int)previousVal;

                    var val = 0;
                    if (currentValInt >= previousValInt)
                    {
                        val = currentValInt - previousValInt;
                    }

                    _VerboseMetricsLogger.InfoFormat("Generated Delta for Component: {0}; Metric: {1}; Value: {2}", currentData.Name, mn, val);
                    delta.Metrics.Add(mn, val);
                }
            });

            return(delta);
        }
Exemple #2
0
        private static ComponentData GetZeroedComponentData(ComponentData componentData)
        {
            var zeroedData = new ComponentData
            {
                Name     = componentData.Name,
                Guid     = componentData.Guid,
                Duration = componentData.Duration
            };

            componentData.Metrics.ForEach(m =>
            {
                var val = m.Value;
                if (MetricMapper.IsMetricNumeric(val))
                {
                    val = 0;
                }

                _VerboseMetricsLogger.InfoFormat("Zeroing Component: {0}; Metric: {1}; Value: {2}", zeroedData.Name, m.Key, val);
                zeroedData.Metrics.Add(m.Key, val);
            });
            return(zeroedData);
        }