BO4E.Extensions/BusinessObjects/Energiemenge/EnergiemengeExtension.cs
/// <summary>
///     Test, if the single entries/intervals of the energieverbrauch array share the same duration and spacing in time.
/// </summary>
/// <param name="em">Energiemenge</param>
/// <param name="reference">reference time frame</param>
/// <param name="wev">Wertermittlungsverfahren</param>
/// <param name="obis">OBIS-Kennzahl</param>
/// <param name="me">Mengeneinheit</param>
/// <param name="allowGaps">set true to allow gaps</param>
/// <returns>
///     True, if all energieverbrauch entries have the same length and their start and enddatum are evenly spaced.
///     Also true, if there less than 2 entries in the energieverbrauch array.
/// </returns>
Test, if the single entries/intervals of the energieverbrauch array share the same duration and spacing in time.
Test if the single entries / intervals of the energieverbrauch array share the same duration and spacing in time .
public static bool IsEvenlySpaced(this BO.Energiemenge em, ITimeRange reference, Wertermittlungsverfahren? wev,
            string obis, Mengeneinheit me, bool allowGaps = false)
        {
            HashSet<TimeSpan> startEndDatumPeriods;
            using (MiniProfiler.Current.Step("finding time spans"))
            {
                startEndDatumPeriods = GetTimeSpans(em, wev, obis, me);
            }
            if (startEndDatumPeriods.Count < 2) return true;
            if (allowGaps)
            {
                using (MiniProfiler.Current.Step("Iterating over all time spans"))
                {
                    var minDiff = startEndDatumPeriods.Min().TotalSeconds;
                    foreach (var ts in startEndDatumPeriods)
                        if (Math.Abs(ts.TotalSeconds % minDiff) != 0)
                            using (MiniProfiler.Current.Step(
                                $"Found TimeSpan {ts} with a duration of {ts.TotalSeconds}. This is no multiple of {minDiff} => not evenly spaced."))
                            {
                                return false;
                            }
                }
                return true;
            }
            return startEndDatumPeriods.Count <= 1;
        }
public static bool IsEvenlySpaced ( this BO . Energiemenge em , ITimeRange reference , Wertermittlungsverfahren ? wev , string obis , Mengeneinheit me , bool allowGaps = false ) { HashSet < TimeSpan > startEndDatumPeriods ; using ( MiniProfiler . Current . Step ( " " ) ) { startEndDatumPeriods = GetTimeSpans ( em , wev , obis , me ) ; } if ( startEndDatumPeriods . Count < 2 ) return true ; if ( allowGaps ) { using ( MiniProfiler . Current . Step ( " " ) ) { var minDiff = startEndDatumPeriods . Min ( ) . TotalSeconds ; foreach ( var ts in startEndDatumPeriods ) if ( Math . Abs ( ts . TotalSeconds % minDiff ) != 0 ) using ( MiniProfiler . Current . Step ( $" Found TimeSpan  { ts }  with a duration of  { ts . TotalSeconds } . This is no multiple of  { minDiff }  => not evenly spaced. " ) ) { return false ; } } return true ; } return startEndDatumPeriods . Count <= 1 ; }
Test, if the single entries/intervals of the energieverbrauch array share the same duration and spacing in time.
Test if the single entries / intervals of the energieverbrauch array share the same duration and spacing in time .
// each time difference must be a multiple of the smallest difference. // use profiler as logger: // there must be only 1 time difference between all the elements
True, if all energieverbrauch entries have the same length and their start and enddatum are evenly spaced.
Also true, if there less than 2 entries in the energieverbrauch array.
True if all energieverbrauch entries have the same length and their start and enddatum are evenly spaced . Also true if there less than 2 entries in the energieverbrauch array .
BO.Energiemenge
this
<not_specific>
reference
ITimeRange
reference time frame
reference time frame
wev
Wertermittlungsverfahren?
None
obis
string
None
me
Mengeneinheit
None
allowGaps
bool
set true to allow gaps
set true to allow gaps
em
<not_specific>
None