Ejemplo n.º 1
0
 public static IEnumerable <T> GetManyMetadata <TMetadata, T>(this MetadataLookup <TMetadata> lookup, DateTimeOffset time, Func <TMetadata, T> func)
     where TMetadata : TimeRange
 {
     return(lookup
            .GetMany(time)
            .Select(func));
 }
Ejemplo n.º 2
0
        public static T GetFirstMetadata <TMetadata, T>(this MetadataLookup <TMetadata> lookup, DateTimeOffset time, Func <TMetadata, T> func)
            where TMetadata : TimeRange
        {
            var metadata = lookup.FirstOrDefault(time);

            return(metadata == null ? default : func(metadata));
        }
        private List <TimeSeriesPoint> LoadPointsFromNg(IAquariusClient client)
        {
            var timeSeriesInfo = client.GetTimeSeriesInfo(Context.SourceTimeSeries.Identifier);

            Log.Info($"Loading points from '{timeSeriesInfo.Identifier}' ...");

            var timeSeriesData = client.Publish.Get(new TimeSeriesDataCorrectedServiceRequest
            {
                TimeSeriesUniqueId = timeSeriesInfo.UniqueId,
                QueryFrom          = Context.SourceQueryFrom?.ToDateTimeOffset(),
                QueryTo            = Context.SourceQueryTo?.ToDateTimeOffset()
            });

            var gradesLookup     = new MetadataLookup <PublishGrade>(timeSeriesData.Grades);
            var qualifiersLookup = new MetadataLookup <PublishQualifier>(timeSeriesData.Qualifiers);

            if (!Context.IgnoreNotes)
            {
                Notes.AddRange(LoadAllNotes(client, timeSeriesInfo, timeSeriesData.Notes));
            }

            var points = timeSeriesData
                         .Points
                         .Select(p => new TimeSeriesPoint
            {
                Time       = Instant.FromDateTimeOffset(p.Timestamp.DateTimeOffset),
                Value      = p.Value.Numeric,
                GradeCode  = gradesLookup.GetFirstMetadata(p.Timestamp.DateTimeOffset, g => int.Parse(g.GradeCode)),
                Qualifiers = qualifiersLookup.GetManyMetadata(p.Timestamp.DateTimeOffset, q => q.Identifier).ToList()
            })
                         .ToList();

            var gapToleranceInMinutes = timeSeriesData.GapTolerances.Last().ToleranceInMinutes;
            var gapTolerance          = gapToleranceInMinutes.HasValue
                ? Duration.FromMinutes((long)gapToleranceInMinutes.Value)
                : DurationExtensions.MaxGapDuration;
            var interpolationType = (InterpolationType)Enum.Parse(typeof(InterpolationType), timeSeriesData.InterpolationTypes.Last().Type, true);

            SetTimeSeriesCreationProperties(
                timeSeriesInfo,
                timeSeriesData.Methods.LastOrDefault()?.MethodCode,
                gapTolerance,
                interpolationType);

            Log.Info($"Loaded {PointSummarizer.Summarize(points)} and {"note".ToQuantity(Notes.Count)} from {timeSeriesInfo.Identifier}");

            return(points);
        }