private string PrintHtmlReport(TimeRange r, string siteID, string parameter) { var s = db.GetSeriesFromTableName("daily_" + siteID + "_" + parameter); if (s == null) { return("Error: no data found: " + siteID + "/" + parameter); } var startYear = r.StartDate.Year; var endYear = r.EndDate.Year; DateTime t1 = r.StartDate; StringBuilder sb = new StringBuilder(); for (int i = startYear; i < endYear; i++) { s.Read(t1, t1.AddMonths(12)); DataTable wyTable = Usgs.WaterYearTable(s); var header = GetHeader(i + 1, siteID, parameter); var html = DataTableOutput.ToHTML(wyTable, true, "", header); sb.Append(html); sb.AppendLine(); t1 = t1.AddMonths(12); } return(sb.ToString()); }
private async Task ProcessMessage(IModel channel, BasicDeliverEventArgs args) { using (metrics.Measure.Timer.Time(this.queueProcessTimer)) { string gaugeId = null; var sw = Stopwatch.StartNew(); try { var json = Encoding.UTF8.GetString(args.Body); this.logger.LogTrace("Received river flow request:{0}{1}", Environment.NewLine, json); var request = JsonConvert.DeserializeObject <RiverFlowRequest>(json); gaugeId = Usgs.FormatGaugeId(request.UsgsGaugeId); await this.riverFlowProcessor.Process(gaugeId); channel.BasicAck(args.DeliveryTag, this.queueConfig.MultipleAck); } catch (Exception ex) { this.logger.LogError(ex, "Error processing gauge {gauge}", gaugeId ?? "unknown"); channel.BasicNack( args.DeliveryTag, multiple: this.queueConfig.MultipleAck, requeue: this.queueConfig.FailureRequeue); this.metrics.Measure.Counter.Increment(this.failureCounter); throw; } finally { sw.Stop(); this.logger.LogInformation("Processed gauge {gauge} in {time}", gaugeId, sw.Elapsed.Humanize()); } } }
public void Publish(int?top = null) { this.logger.LogDebug("Initializing connection to {host}", this.queueConnectionFactory.HostName); using (var queueConn = this.queueConnectionFactory.CreateConnection()) using (var queueChannel = queueConn.CreateModel()) { InitializeQueue(queueConn, queueChannel); var type = typeof(QueuePublisher).GetTypeInfo(); var resource = $"{type.Namespace}.usgs-sitecodes-filtered.csv"; this.logger.LogInformation("Reading {resource}", resource); using (var resourceStream = type.Assembly.GetManifestResourceStream(resource)) using (var streamReader = new StreamReader(resourceStream)) using (var csv = new CsvReader(streamReader)) { csv.Read(); csv.ReadHeader(); var read = 0; while (csv.Read() && (top == null || read < top)) { var usgsGaugeId = Usgs.FormatGaugeId(csv["UsgsGaugeId"]); PublishOne(queueChannel, usgsGaugeId); read++; } } } }
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); } } }
private void PrintHtmlReport(TimeRange r, string siteID, string parameter) { Console.Write("Content-type: text/html\n\n"); var s = new HydrometDailySeries(siteID, parameter, HydrometHost.PNLinux); var startYear = r.StartDate.Year; var endYear = r.EndDate.Year; DateTime t1 = r.StartDate; for (int i = startYear; i < endYear; i++) { s.Read(t1, t1.AddMonths(12)); DataTable wyTable = Usgs.WaterYearTable(s); var header = GetHeader(i + 1, siteID, parameter); var html = DataTableOutput.ToHTML(wyTable, true, "", header); Console.WriteLine(html); t1 = t1.AddMonths(12); } }
internal void Run() { Console.Write("Content-type: text/html\n\n"); if (query == "") { query = HydrometWebUtility.GetQuery(); } var collection = HttpUtility.ParseQueryString(query); TimeRange r = GetDateRange(collection); var siteID = ""; if (collection.AllKeys.Contains("site")) { siteID = collection["site"]; } var parameter = ""; if (collection.AllKeys.Contains("parameter")) { parameter = collection["parameter"]; } var s = new HydrometDailySeries(siteID, parameter); var startYear = r.StartDate.Year; var endYear = r.EndDate.Year; DateTime t1 = r.StartDate; for (int i = startYear; i < endYear; i++) { s.Read(t1, t1.AddMonths(12)); DataTable wyTable = Usgs.WaterYearTable(s); var header = GetHeader(i + 1, siteID, parameter); var html = DataTableOutput.ToHTML(wyTable, true, "", header); Console.WriteLine(html); t1 = t1.AddMonths(12); } }
public void FormatGaugeId_Empty_ThrowsArgumentException() { Action act = () => Usgs.FormatGaugeId(string.Empty); act.Should().Throw <ArgumentException>(); }
public void FormatGaugeId_Null_ThrowsArgumentNullException() { Action act = () => Usgs.FormatGaugeId(null); act.Should().Throw <ArgumentNullException>(); }
public void FormatGaugeId_MoreThan8Characters_NoChange() { Usgs.FormatGaugeId("013539600").Should().Be("013539600"); }
public void FormatGaugeId_LessThan8Characters_PadLeftZeros() { Usgs.FormatGaugeId("3539600").Should().Be("03539600"); }