예제 #1
0
        public async Task RecordFlow(RiverFlowSnapshot snapshot)
        {
            if (snapshot == null)
            {
                throw new ArgumentNullException(nameof(snapshot));
            }

            string gaugeId = null;

            try
            {
                gaugeId = snapshot.Site.UsgsGaugeId;
                var client = GetHttpClient();
                var uri    = this.apiBaseUri ?? (apiBaseUri = this.GetApiBaseUri());
                this.logger.LogInformation(
                    "Posting to '{recordFlowUrl}' ({uri}) for gauge '{gaugeId}'",
                    RecordFlowUrl,
                    uri,
                    gaugeId);

                var response = await client.PostAsync(RecordFlowUrl, new JsonContent(snapshot));

                response.EnsureSuccessStatusCode();
            }
            catch (Exception ex)
            {
                this.logger.LogWarning(ex, "Error posting flow values for gauge {gauge}", gaugeId);
                throw;
            }
        }
예제 #2
0
        public static RiverFlowSnapshot MapFlowData(string usgsGaugeId, StreamFlow usgsStreamFlow)
        {
            // Current assumptions for simplicity
            // 1) One site at a time though API supports multiple
            // 2) One parameter value at a time (most recent) though API supports time period

            var timeSeries = usgsStreamFlow.Value.GetTimeSeriesForSite(usgsGaugeId);

            var snapshot = new RiverFlowSnapshot
            {
                AsOfUTC = DateTime.UtcNow,
                Site    = GetSiteInfo(timeSeries.FirstOrDefault()?.SourceInfo)
            };

            foreach (var ts in timeSeries)
            {
                var dataValue = GetDataValue(ts);

                if (dataValue != null)
                {
                    snapshot.Values.Add(dataValue);
                }
            }

            if (!snapshot.Values.Any())
            {
                return(null);
            }

            return(snapshot);
        }
        public async Task Process(string usgsGaugeId)
        {
            usgsGaugeId = Usgs.FormatGaugeId(usgsGaugeId);
            RiverFlowSnapshot flowData = null;

            using (metrics.Measure.Timer.Time(this.requestTimer))
            {
                flowData = await this.GetRiverFlowData(usgsGaugeId);
            }

            if (flowData != null)
            {
                using (metrics.Measure.Timer.Time(this.recordTimer))
                {
                    await this.flowClient.RecordFlow(flowData);
                }
            }
        }