/// <summary> /// Check if the MeasuringRange object is empty /// </summary> /// <param name="range">The object to be checked.</param> /// <returns>True if the MeasuringRange object is empty.</returns> public bool IsRangeEmpty(MeasuringRange range) { if (range.Start == range.End && range.Amount == 0) { return(true); } return(false); }
public void Add(MeasuringRange range, ObisId obisId) { this.measuringRanges.Add(range); this.summaryRegister.First(r => r.TariffId == range.TariffId && obisId.C == r.ObisCode.C).Amount = this.summaryRegister.First(r => r.TariffId == range.TariffId && obisId.C == r.ObisCode.C).Amount + range.Amount; }
/// <summary> /// Calculates the next valid range for the current day /// </summary> /// <param name="reading">The IntervalReading at the end of the new range.</param> /// <param name="endCurrentReading">The end date of the current range.</param> /// <param name="startReading">The IntervalReading at the start of the new range.</param> /// <param name="start">The start date of the current range.</param> /// <param name="end">The global end date of the current day.</param> /// <param name="dayTimeProfiles">The dayTimeProfiles for the current day.</param> /// <param name="meterReading">The meterReading object of the current original value list.</param> /// <param name="profile">The current SpecialDayProfile.</param> /// <param name="currentDay">The current AccountingDay object.</param> /// <param name="i">The current index value of the parent loop.</param> /// <param name="latestReading">The current meterReading value.</param> /// <param name="latestTariffId">The last valid tariff id.</param> /// <returns>The rangeData of the found range</returns> public (IntervalReading reading, MeasuringRange range, int index, long latestReading) GetNextRange(IntervalReading reading, DateTime endCurrentReading, IntervalReading startReading, DateTime start, DateTime end, List <DayTimeProfile> dayTimeProfiles, MeterReading meterReading, SpecialDayProfile profile, AccountingDay currentDay, int i, long latestReading, ushort latestTariffId) { var endReading = SetConcreteIntervalReading(reading, endCurrentReading); var range = new MeasuringRange(); // Normal situation: reading is valid. if (endReading.reading != null && IsStatusValid(endReading.reading)) { range = new MeasuringRange(start, endReading.end, (ushort)dayTimeProfiles[i - 1].TariffNumber, (endReading.reading.Value.Value - startReading.Value.Value)); } else // A gap was found { // Looking for the next valid IntervalReading var result = FindLastValidTime(start, end, profile, dayTimeProfiles, meterReading, i - 1); endReading = SetIntervalReading(meterReading, result.end, result.index, dayTimeProfiles.Count); if (result.end < end && endReading.reading != null) // An IntervalReading was found which is bigger than startReading but smaller than the detected gap. { range = new MeasuringRange(start, endReading.end, (ushort)dayTimeProfiles[result.index].TariffNumber, (endReading.reading.Value.Value - startReading.Value.Value)); } else { // Count in error register if (endReading.reading != null && IsStatusValid(endReading.reading)) { range = new MeasuringRange(start, endReading.end, (endReading.reading.Value.Value - startReading.Value.Value)); } else { // No closing valid IntervalReading for the current day was found (There was a gap at the last tariff change) latestTariffId = 63; endReading.reading = startReading; // No valid IntervalReading was found. Reset range to mark it as invalid. } } // 1 Measurement period at tariff change is missing if ((i - 1) == result.index) { latestReading = this.GetLatestReading(latestReading, endReading.reading); latestTariffId = range.TariffId; currentDay.Add(range, new ObisId(meterReading.ReadingType.ObisCode)); var j = result.index; var nextDate = ModelExtensions.GetDateTimeFromSpecialDayProfile(profile, dayTimeProfiles[j + 1]); var nextReading = SetIntervalReading(meterReading, nextDate, j + 1, dayTimeProfiles.Count); while (nextReading.reading == null || !IsStatusValid(nextReading.reading)) { j++; if (j < dayTimeProfiles.Count - 1) { nextDate = ModelExtensions.GetDateTimeFromSpecialDayProfile(profile, dayTimeProfiles[j + 1]); nextReading = SetIntervalReading(meterReading, nextDate, j + 1, dayTimeProfiles.Count); } else { nextDate = ModelExtensions.GetDateTimeFromSpecialDayProfile(profile, dayTimeProfiles[j]); nextReading = SetIntervalReading(meterReading, nextDate, j, dayTimeProfiles.Count); if (nextReading.reading == null || !IsStatusValid(endReading.reading)) { nextReading = endReading; break; } } } // Count in error register range = new MeasuringRange(endReading.end, nextReading.end, (nextReading.reading.Value.Value - endReading.reading.Value.Value)); endReading = nextReading; result.index = j + 1; } // Protect for the special case i == dayTimeProfiles.Count -1 because it could lead to an endless loop. if (i != dayTimeProfiles.Count - 1) { i = result.index; } } // Check if the range object is empty if (this.IsRangeEmpty(range)) { range.TariffId = latestTariffId; } return(endReading.reading, range, i, latestReading); }