Beispiel #1
0
        public static TimeSeriesDescription GetTimeSeriesDescription(this IAquariusClient client, string identifier)
        {
            var locationIdentifier = TimeSeriesIdentifierParser.ParseLocationIdentifier(identifier);

            var response = client.Publish.Get(new TimeSeriesDescriptionServiceRequest
            {
                LocationIdentifier = client.FindLocationDescription(locationIdentifier).Identifier
            });

            var caseInsensitiveMatches = response
                                         .TimeSeriesDescriptions
                                         .Where(t => t.Identifier.Equals(identifier, StringComparison.InvariantCultureIgnoreCase))
                                         .ToList();

            if (!caseInsensitiveMatches.Any())
            {
                throw new ExpectedException($"Can't find '{identifier}' at location '{locationIdentifier}'");
            }

            if (caseInsensitiveMatches.Count == 1)
            {
                return(caseInsensitiveMatches.Single());
            }

            var exactMatch = caseInsensitiveMatches
                             .FirstOrDefault(t => t.Identifier == identifier);

            if (exactMatch != null)
            {
                return(exactMatch);
            }

            throw new ExpectedException($"{caseInsensitiveMatches.Count} ambiguous matches for '{identifier}': {string.Join(", ", caseInsensitiveMatches.Select(t => t.Identifier))}");
        }
Beispiel #2
0
        public void CreateMissingTimeSeries(string timeSeriesIdentifier)
        {
            var locationIdentifier = TimeSeriesIdentifierParser.ParseLocationIdentifier(timeSeriesIdentifier);

            var location = GetOrCreateLocation(locationIdentifier);

            GetOrCreateTimeSeries(location, timeSeriesIdentifier);
        }
Beispiel #3
0
        public static TimeSeriesDescription GetTimeSeriesDescription(this IAquariusClient client, string identifier)
        {
            var location = TimeSeriesIdentifierParser.ParseLocationIdentifier(identifier);

            var response = client.Publish.Get(new TimeSeriesDescriptionServiceRequest {
                LocationIdentifier = location
            });

            var timeSeriesDescription = response.TimeSeriesDescriptions.FirstOrDefault(t => t.Identifier == identifier);

            if (timeSeriesDescription == null)
            {
                throw new ExpectedException($"Can't find '{identifier}' at location '{location}'");
            }

            return(timeSeriesDescription);
        }
Beispiel #4
0
        private TimeSeriesIdentifier CreateTimeSeriesIdentifier()
        {
            if (Context.SourceTimeSeries != null)
            {
                return(Context.SourceTimeSeries);
            }

            if (!string.IsNullOrEmpty(Context.TimeSeries))
            {
                return(TimeSeriesIdentifierParser.ParseExtendedIdentifier(Context.TimeSeries));
            }

            string parameter;
            var    label = "Points";
            var    locationIdentifier = "PointZilla";

            if (Context.Command == CommandType.DeleteAllPoints)
            {
                parameter = "Deleted";
            }

            else if (Context.ManualPoints.Any())
            {
                parameter = "ManuallyEntered";
            }
            else if (Context.CsvFiles.Any())
            {
                parameter = "OtherCsvFile";
            }
            else
            {
                parameter = Context.WaveformType.ToString();
            }

            return(new TimeSeriesIdentifier
            {
                Parameter = parameter,
                Label = label,
                LocationIdentifier = locationIdentifier,
                Identifier = $"{parameter}.{label}@{locationIdentifier}"
            });
        }
        public static bool TryParse(string text, out TimeSeriesIdentifier timeSeriesIdentifier)
        {
            timeSeriesIdentifier = TimeSeriesIdentifierParser.ParseExtendedIdentifier(text);

            return(timeSeriesIdentifier != null);
        }
Beispiel #6
0
        private void GetOrCreateTimeSeries(Location location, string timeSeriesIdentifier)
        {
            var existingTimeSeries = Client.Provisioning.Get(new GetLocationTimeSeries {
                LocationUniqueId = location.UniqueId
            })
                                     .Results
                                     .FirstOrDefault(ts => ts.Identifier == timeSeriesIdentifier);

            if (existingTimeSeries != null)
            {
                return;
            }

            var timeSeriesExtendedAttributes = Client.Provisioning.Get(new GetTimeSeriesExtendedAttributes())
                                               .Results;

            var timeSeriesInfo = TimeSeriesIdentifierParser.ParseExtendedIdentifier(timeSeriesIdentifier);

            var parameter = Client.Provisioning.Get(new GetParameters())
                            .Results
                            .FirstOrDefault(p => p.Identifier.Equals(timeSeriesInfo.Parameter, StringComparison.InvariantCultureIgnoreCase));

            if (parameter == null)
            {
                throw new ExpectedException($"Parameter '{timeSeriesInfo.Parameter}' does not exist in the system.");
            }

            var interpolationType = Context.InterpolationType ?? parameter.InterpolationType;

            var gapTolerance = InterpolationTypesWithNoGaps.Contains(interpolationType)
                ? DurationExtensions.MaxGapDuration
                : Context.GapTolerance;

            var defaultMonitoringMethod = Client.Provisioning.Get(new GetMonitoringMethods())
                                          .Results
                                          .Single(monitoringMethod => monitoringMethod.ParameterUniqueId == Guid.Empty);

            PostBasicTimeSeries     basicTimeSeries     = null;
            PostReflectedTimeSeries reflectedTimeSeries = null;
            TimeSeriesBase          request;

            if (Context.CreateMode == CreateMode.Reflected)
            {
                reflectedTimeSeries = new PostReflectedTimeSeries {
                    GapTolerance = gapTolerance
                };
                request = reflectedTimeSeries;
            }
            else
            {
                basicTimeSeries = new PostBasicTimeSeries {
                    GapTolerance = gapTolerance
                };
                request = basicTimeSeries;
            }

            request.LocationUniqueId            = location.UniqueId;
            request.UtcOffset                   = Context.UtcOffset ?? location.UtcOffset;
            request.Label                       = timeSeriesInfo.Label;
            request.Parameter                   = parameter.ParameterId;
            request.Description                 = Context.Description;
            request.Comment                     = Context.Comment;
            request.Unit                        = Context.Unit ?? parameter.UnitIdentifier;
            request.InterpolationType           = interpolationType;
            request.Publish                     = Context.Publish;
            request.Method                      = Context.Method ?? defaultMonitoringMethod.MethodCode;
            request.ComputationIdentifier       = Context.ComputationIdentifier;
            request.ComputationPeriodIdentifier = Context.ComputationPeriodIdentifier;
            request.SubLocationIdentifier       = Context.SubLocationIdentifier;
            request.ExtendedAttributeValues     = MergeExtendedAttributesWithMandatoryExtendedAttributes(timeSeriesExtendedAttributes).ToList();

            Log.Info($"Creating '{timeSeriesIdentifier}' time-series ...");

            var timeSeries = Context.CreateMode == CreateMode.Reflected
                ? Client.Provisioning.Post(reflectedTimeSeries)
                : Client.Provisioning.Post(basicTimeSeries);

            Log.Info($"Created '{timeSeries.Identifier}' ({timeSeries.TimeSeriesType}) successfully.");
        }