Пример #1
0
        public static NormalizedValuesResult ComputeNormalizedValues(NormalizedValuesParameters request)
        {
            var result = new NormalizedValuesResult
            {
                NewReferenceReading = request.StartMeterReading
            };

            var startBucketNumber = request.StartDate.BucketNumber();
            var endBucketNumber   = request.CurrentMessage.Timestamp.BucketNumber();

            for (int bucket = startBucketNumber + 1; bucket <= endBucketNumber; bucket++)
            {
                var normalizedValue = GetIntermediateValue(request, bucket.BucketDate());

                result.NormalizedValues.Add(normalizedValue);

                result.NewReferenceDate    = normalizedValue.Timestamp;
                result.NewReferenceReading = normalizedValue.MeterReading;
            }

            return(result);
        }
Пример #2
0
        private static NormalizedMeterReading GetIntermediateValue(NormalizedValuesParameters request, DateTime bucketDate)
        {
            if (bucketDate == request.CurrentMessage.Timestamp)
            {
                return(new NormalizedMeterReading(
                           bucketDate,
                           request.CurrentMessage.MeterReading - request.StartMeterReading,
                           request.CurrentMessage.MeterReading));
            }

            var millisecondsBetweenMessages     = (decimal)(request.CurrentMessage.Timestamp - request.PreviousMessage.Timestamp).TotalMilliseconds;
            var millisecondsFromPreviousMessage = (decimal)(bucketDate - request.PreviousMessage.Timestamp).TotalMilliseconds;

            var totalConsumption   = request.CurrentMessage.MeterReading - request.PreviousMessage.MeterReading;
            var messageConsumption = totalConsumption * (millisecondsFromPreviousMessage / millisecondsBetweenMessages);

            var bucketReading     = request.PreviousMessage.MeterReading + messageConsumption;
            var bucketConsumption = bucketReading - request.StartMeterReading;

            return(new NormalizedMeterReading(
                       bucketDate,
                       bucketConsumption,
                       bucketReading));
        }