BO4E.Extensions/BusinessObjects/Energiemenge/EnergiemengeExtensionCompleteness.cs
/// <summary>
///     Generate a <see cref="CompletenessReport" /> for the given parameters.
/// </summary>
/// <param name="em">Energiemenge</param>
/// <param name="reference">reference time frame</param>
/// <param name="wev">Wertermittlungsverfahren</param>
/// <param name="obiskennzahl">OBIS Kennzahl</param>
/// <param name="einheit">Mengeneinheit</param>
/// <returns>the completeness report</returns>
Generate a  for the given parameters.
Generate a for the given parameters .
public static CompletenessReport GetCompletenessReport(this BO.Energiemenge em, ITimeRange reference,
            Wertermittlungsverfahren? wev, string obiskennzahl, Mengeneinheit einheit)
        {
            CompletenessReport result;
            using (MiniProfiler.Current.Step("create completeness report skeleton + find the coverage"))
            {
                result = new CompletenessReport
                {
                    LokationsId = em.LokationsId,
                    Einheit = einheit,
                    Coverage = GetCoverage(em, reference, wev, obiskennzahl, einheit),
                    Wertermittlungsverfahren = wev,
                    Obiskennzahl = obiskennzahl,
                    ReferenceTimeFrame = new Zeitraum
                    {
                        Startdatum = new DateTimeOffset(DateTime.SpecifyKind(reference.Start, DateTimeKind.Utc)),
                        Enddatum = new DateTimeOffset(DateTime.SpecifyKind(reference.End, DateTimeKind.Utc))
                    }
                };
            }
            if (em.Energieverbrauch != null && em.Energieverbrauch.Any())
            {
                using (MiniProfiler.Current.Step("Setting aggregated gaps"))
                {
                    var nonNullValues =
                        new TimePeriodCollection(
                            em.Energieverbrauch.Select(v => new TimeRange((v.Startdatum ?? DateTimeOffset.MinValue).DateTime, (v.Enddatum ?? DateTimeOffset.MinValue).DateTime)));
                    ITimeRange limits;
                    if (result.ReferenceTimeFrame != null && result.ReferenceTimeFrame.Startdatum.HasValue)
                        limits = new TimeRange(result.ReferenceTimeFrame.Startdatum.Value.UtcDateTime,
                            result.ReferenceTimeFrame.Enddatum.Value.UtcDateTime);
                    else
                        limits = null;
                    var gaps = new TimeGapCalculator<TimeRange>().GetGaps(nonNullValues, limits);
                    result.Gaps = gaps.Select(gap => new CompletenessReport.BasicVerbrauch
                    {
                        Startdatum = DateTime.SpecifyKind(gap.Start, DateTimeKind.Utc),
                        Enddatum = DateTime.SpecifyKind(gap.End, DateTimeKind.Utc),
                        Wert = null
                    }).ToList();
                }
                if (em.IsPure(true))
                    try
                    {
                        foreach (var kvp in em.Energieverbrauch.Where(v => v.UserProperties != null)
                            .SelectMany(v => v.UserProperties))
                        {
                            if (result.UserProperties == null) result.UserProperties = new Dictionary<string, object>();
                            if (!result.UserProperties.ContainsKey(kvp.Key))
                                result.UserProperties.Add(kvp.Key, kvp.Value);
                        }
                    }
                    catch (InvalidOperationException)
                    {
                    }
            }
            return result;
        }
public static CompletenessReport GetCompletenessReport ( this BO . Energiemenge em , ITimeRange reference , Wertermittlungsverfahren ? wev , string obiskennzahl , Mengeneinheit einheit ) { CompletenessReport result ; using ( MiniProfiler . Current . Step ( " " ) ) { result = new CompletenessReport { LokationsId = em . LokationsId , Einheit = einheit , Coverage = GetCoverage ( em , reference , wev , obiskennzahl , einheit ) , Wertermittlungsverfahren = wev , Obiskennzahl = obiskennzahl , ReferenceTimeFrame = new Zeitraum { Startdatum = new DateTimeOffset ( DateTime . SpecifyKind ( reference . Start , DateTimeKind . Utc ) ) , Enddatum = new DateTimeOffset ( DateTime . SpecifyKind ( reference . End , DateTimeKind . Utc ) ) } } ; } if ( em . Energieverbrauch != null && em . Energieverbrauch . Any ( ) ) { using ( MiniProfiler . Current . Step ( " " ) ) { var nonNullValues = new TimePeriodCollection ( em . Energieverbrauch . Select ( v => new TimeRange ( ( v . Startdatum ?? DateTimeOffset . MinValue ) . DateTime , ( v . Enddatum ?? DateTimeOffset . MinValue ) . DateTime ) ) ) ; ITimeRange limits ; if ( result . ReferenceTimeFrame != null && result . ReferenceTimeFrame . Startdatum . HasValue ) limits = new TimeRange ( result . ReferenceTimeFrame . Startdatum . Value . UtcDateTime , result . ReferenceTimeFrame . Enddatum . Value . UtcDateTime ) ; else limits = null ; var gaps = new TimeGapCalculator < TimeRange > ( ) . GetGaps ( nonNullValues , limits ) ; result . Gaps = gaps . Select ( gap => new CompletenessReport . BasicVerbrauch { Startdatum = DateTime . SpecifyKind ( gap . Start , DateTimeKind . Utc ) , Enddatum = DateTime . SpecifyKind ( gap . End , DateTimeKind . Utc ) , Wert = null } ) . ToList ( ) ; } if ( em . IsPure ( true ) ) try { foreach ( var kvp in em . Energieverbrauch . Where ( v => v . UserProperties != null ) . SelectMany ( v => v . UserProperties ) ) { if ( result . UserProperties == null ) result . UserProperties = new Dictionary < string , object > ( ) ; if ( ! result . UserProperties . ContainsKey ( kvp . Key ) ) result . UserProperties . Add ( kvp . Key , kvp . Value ) ; } } catch ( InvalidOperationException ) { } } return result ; }
Generate a  for the given parameters.
Generate a for the given parameters .
/*using (MiniProfiler.Current.Step("populating time slices of/with missing/null values"))
                {
                    result.values = em.GetMissingTimeRanges(reference, wev, obis, einheit)
                        .Select(mtr => new CompletenessReport.BasicVerbrauch
                        {
                            startdatum = DateTime.SpecifyKind(mtr.Start, DateTimeKind.Utc),
                            enddatum = DateTime.SpecifyKind(mtr.End, DateTimeKind.Utc),
                            wert = null
                        }).ToList<CompletenessReport.BasicVerbrauch>();
                }
                using (MiniProfiler.Current.Step("populating time slices existing values"))
                {
                    result.values.AddRange(
                    em.energieverbrauch
                    //.AsParallel<Verbrauch>()
                    .Where(v => v.obiskennzahl == obis && v.einheit == einheit && v.wertermittlungsverfahren == wev)
                    .Select(v => new CompletenessReport.BasicVerbrauch
                    {
                        startdatum = DateTime.SpecifyKind(v.startdatum, DateTimeKind.Utc),
                        enddatum = DateTime.SpecifyKind(v.enddatum, DateTimeKind.Utc),
                        wert = v.wert
                    })
                    .ToList<CompletenessReport.BasicVerbrauch>());
                }*/ /*using (MiniProfiler.Current.Step("sorting result"))
                {
                    result.values.Sort(new BasicVerbrauchDateTimeComparer());
                }*/ // ok, there's no Verbrauch with user properties. /*else
            {
                result.coverage = null;
                result._errorMessage = "energieverbrauch is empty";
            }*/
the completeness report
the completeness report
BO.Energiemenge
this
reference
ITimeRange
reference time frame
reference time frame
wev
Wertermittlungsverfahren?
None
obiskennzahl
string
None
einheit
Mengeneinheit
None
em
None