private void buttonRecomputeCoeficients_Click(object sender, EventArgs e) { // Performance perf = new Performance(); string fn = FileUtility.GetTempFileName(".csv"); xls.SaveSheetToCsv(xls.ActiveSheetName, fn); xls.Save(); // must save to get back to *.xls from *.csv eq = new ForecastEquation(fn); var cache = new HydrometDataCache(); cache.Add(eq.GetCbttPcodeList().ToArray(), new DateTime(eq.StartYear - 1, 10, 1), new DateTime(eq.EndYear, 9, 30)); HydrometMonthlySeries.Cache = cache; var dir = Path.GetDirectoryName(this.textBoxExcelFileName.Text); try { Cursor = Cursors.WaitCursor; Application.DoEvents(); R = new CoefficientCalculator(); var newCoefficients = R.ComputeCoefficients(eq, Path.GetDirectoryName(Application.ExecutablePath)); var dlg = new RegressionResults(); dlg.CompareToHistoryClicked += new EventHandler <EventArgs>(dlg_CompareToHistoryClicked); dlg.Output = R.Output; dlg.DataFile = R.dataFile; dlg.CoeficientsExisting = CoefficientCalculator.FormatCoefficients(eq.coefficients); dlg.CoefficientsComputed = CoefficientCalculator.FormatCoefficients(newCoefficients); if (dlg.ShowDialog() == DialogResult.OK) // save { // save back to excel. xls.UpdateCoeficients(xls.ActiveSheetName, newCoefficients); } } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { Cursor = Cursors.Default; } }
public static void SetupHydrometData(int StartYear, int EndYear, string[] cbttPcodeList, DateTime t, bool cacheAverage, bool allYears = false) { if (UseSQLite()) { return; } var cache = new HydrometDataCache(); if (allYears) { cache.Add(cbttPcodeList, new DateTime(StartYear - 1, 1, 1), new DateTime(EndYear, 12, 31)); } else { Logger.WriteLine("Caching Hydromet Data for a year "); cache.Add(cbttPcodeList, new DateTime(t.Year - 1, 1, 1), new DateTime(t.Year, 12, 31), s_server); } //if (cacheAverage) // get average values (special water year 9999 ) //{ // // TO DO... change pcode to average pcode.... // var avgCodes = new List<string>(); // for (int i = 0; i < cbttPcodeList.Length; i++) // { // string[] tokens = cbttPcodeList[i].Split(); // var pc = HydrometMonthlySeries.LookupAveargePcode(tokens[1]); // if( pc.Trim() != "") // avgCodes.Add(tokens[0] + " " + pc); // } // Logger.WriteLine("Caching Hydromet Data for average years"); // cache.Add(avgCodes.ToArray(), // new DateTime(9998, 10, 1), // new DateTime(9999, 9, 30), HydrometHost.PN); //} HydrometMonthlySeries.Cache = cache; // Anderson forecast without cache 8 seconds. // with cache 4 seconds }
static void Main(string[] args) { if (args.Length != 5 && args.Length != 2) { Console.WriteLine("HydrometForecast.exe basin.csv date level look-ahead output"); Console.WriteLine("Where: "); Console.WriteLine(" basin.csv -- name of csv input file"); Console.WriteLine(" date -- date to run forecaset 2017-01-01"); Console.WriteLine(" level -- subsequent conditions 1.0 normal 0.8 for 80%, etc... "); Console.WriteLine(" look-ahead -- perfect forecast 0 or 1"); Console.WriteLine(" output -- filename for output"); Console.WriteLine("Example: HydrometForecast heise.csv 2016-1-1 1.0 0 output.txt"); Console.WriteLine("HydrometForecast.exe basin.csv output.csv"); return; } var filename = args[0]; ForecastEquation eq = new ForecastEquation(filename); if (args.Length == 2) { var cache = new HydrometDataCache(); cache.Add(eq.GetCbttPcodeList().ToArray(), new DateTime(eq.StartYear - 1, 10, 1), new DateTime(eq.EndYear, 9, 30)); HydrometMonthlySeries.Cache = cache; var tbl = eq.ComputeHistoricalCoefficients(eq.StartYear, eq.EndYear); CsvFile.WriteToCSV(tbl, args[1], false); } else { DateTime t = DateTime.Parse(args[1]); double level = double.Parse(args[2]); int lookAhead = int.Parse(args[3]); string outputFileName = args[4]; ForecastResult result = eq.Evaluate(t, lookAhead == 1, level); File.WriteAllLines(outputFileName, result.Details.ToArray()); } }
public static void PreloadInstantHydrometData(AlarmDataSet.alarm_definitionDataTable alarmdef, DateTime t) { // find all instant data, and largest hours_back, to make a single cache of data var cbttPcodes = (from row in alarmdef.AsEnumerable() where row.database.ToLower() == "i" // instant hydromet data select row.cbtt.ToLower() + " " + row.pcode.ToLower()).Distinct().ToArray(); if (cbttPcodes.Length == 0) { return; } // TO DO. throw error if mixing quality and 'regular' data. //if (MixedQualityData(cbttPcodes)) //{ // throw new ArgumentException("Error: quality and Mixing qual"); //} var hours_back = (from row in alarmdef.AsEnumerable() where row.database.ToLower() == "i" select row.hours_back).Max(); DateTime t1 = t.AddHours(-hours_back); DateTime t2 = t; // HydrometInstantSeries.KeepFlaggedData = true; HydrometHost h = Utility.GetHydrometServer(); var cache = new HydrometDataCache(); cache.Add(String.Join(",", cbttPcodes).Split(','), t1, t2, h, Reclamation.TimeSeries.TimeInterval.Irregular, 0); HydrometInstantSeries.Cache = cache; Console.WriteLine(cbttPcodes); }
private static string Get(string CPstr, DateTime t1, DateTime t2) { string border = "==== ============ ========= ========= ========= ========= ========= ========="; string labels = ""; if ((t2 - t1).TotalDays == 4) { int wy = t2.Year; if (t2.Month >= 10) { wy = t2.Year + 1; } labels = "WY STATION PARAMETER " + t1.ToString("ddd MMMdd") + " " + t1.AddDays(1).ToString("ddd MMMdd") + " " + t1.AddDays(2).ToString("ddd MMMdd") + " " + t1.AddDays(3).ToString("ddd MMMdd") + " " + t1.AddDays(4).ToString("ddd MMMdd"); Console.WriteLine(labels); Console.WriteLine(border); string[] ID = CPstr.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); var cache = new HydrometDataCache(); cache.Add(ID, t1, t2, HydrometHost.PNLinux, Reclamation.TimeSeries.TimeInterval.Irregular); HydrometDailySeries.Cache = cache; for (int j = 0; j < ID.Length; j++) { var c = ID[j].Split(' ')[0]; var p = ID[j].Split(' ')[1]; HydrometDailySeries ts = new HydrometDailySeries(c, p); ts.Read(t1, t2); string t = wy + "," + c + "," + p + "," + ts[t1].Value + "," + ts[t1.AddDays(1)].Value + "," + ts[t1.AddDays(2)].Value + "," + ts[t1.AddDays(3)].Value + "," + ts[t1.AddDays(4)].Value; Console.WriteLine(format(t)); } } return(CPstr = ""); }
public void GraphData(bool showFlows = false) { linkLabelReport.Visible = false; if (comboBoxSite.Text.ToString() == "" || this.comboBoxSite.SelectedItem.ToString().IndexOf("--") != -1) { return; } try { optionalPercents = ParseOptionalPercentages(); Series alternateRequiredContent = new Series(); Series alternateActualContent = new Series(); Series actualContent = new Series(); Series requiredContent = new Series(); SeriesList targets = new SeriesList(); SeriesList hmList = new SeriesList(); SeriesList hmList2 = new SeriesList(); SeriesList ruleCurves = new SeriesList(); var cache = new HydrometDataCache(); var cbttList = new List <string>(); var cbttListAlternate = new List <string>(); var labelDates = new List <DateTime>(); bool showRuleCurve = true; Reclamation.TimeSeries.Hydromet.HydrometHost svr; var hydSvr = UserPreference.Lookup("HydrometServer"); if (hydSvr.ToLower() == "greatplains") { svr = HydrometHost.GreatPlains; } else { svr = HydrometHost.PNLinux; } Cursor = Cursors.WaitCursor; Application.DoEvents(); FloodControlPoint pt = new FloodControlPoint(this.comboBoxSite.Text.ToString()); if (compilePublic) { pt.StationFC = "NA"; pt.StationQU = "NA"; pt.RequiredLegend = "Full Storage"; showRuleCurve = false; } if (pt.DailyStationQU == "NA") { return; } if (showFlows) { this.pcodeInitial.Text = (pt.ResOpsInflow + "," + pt.ResOpsOutflow).ToLower(); hydrometChart1.SetRightLabels("Flows (cfs)"); } checkBoxDashed.Visible = pt.StationFC.ToLower() == "heii"; residForecast = new ResidualForecast(pt, checkBoxDashed.Checked); residForecastCompare = new ResidualForecast(pt, checkBoxDashed.Checked); DateRange requiredRange = GetRequiredRange(); DateRange curveRange = GetRuleCurveRange(); DateRange alternateRange = GetComparisonRange(); //setup cache for required cbttList.AddRange(residForecast.DailyCbttPcodeList()); if (this.pcodeInitial.Text.Length >= 1 && this.textBoxWaterYear.Text.Length >= 1) { cbttList.AddRange(OptionalCbttList(this.pcodeInitial.Text)); } cache.Add(cbttList.ToArray(), requiredRange.DateTime1.AddDays(-1), requiredRange.DateTime2.AddDays(1), svr, TimeInterval.Daily); cache.Add(residForecast.MonthlyCbttPcodeList(), requiredRange.DateTime1, requiredRange.DateTime2, svr, TimeInterval.Monthly); // setup cache for alternate range if (alternateRange.IsValid) { cbttListAlternate.AddRange(residForecast.DailyCbttPcodeList()); if (this.pcodeComparison.Text.Length >= 1) { cbttListAlternate.AddRange(OptionalCbttList(this.pcodeComparison.Text)); } cache.Add(cbttListAlternate.ToArray(), alternateRange.DateTime1.AddDays(-1), alternateRange.DateTime2.AddDays(1), svr, TimeInterval.Daily); cache.Add(residForecast.MonthlyCbttPcodeList(), alternateRange.DateTime1.AddDays(-1), alternateRange.DateTime2.AddDays(1), svr, TimeInterval.Monthly); } //add cache HydrometDailySeries.Cache = cache; HydrometMonthlySeries.Cache = cache; //compute residual forecast residForecast.Compute(requiredRange.DateTime1, requiredRange.DateTime2, svr); requiredContent = -residForecast.SpaceRequired + pt.TotalUpstreamActiveSpace; actualContent = residForecast.TotalContent; requiredContent.Name = this.textBoxWaterYear.Text; actualContent.Name = this.textBoxWaterYear.Text + " Actual"; if (this.pcodeInitial.Text.Length >= 1) { hmList = ReadHydrometOptionalData(Convert.ToInt32(this.textBoxWaterYear.Text), this.pcodeInitial.Text, requiredRange); } //compute comparison year residual forecast if (alternateRange.IsValid) { residForecastCompare.Compute(alternateRange.DateTime1, alternateRange.DateTime2, svr); alternateRequiredContent = -residForecastCompare.SpaceRequired + pt.TotalUpstreamActiveSpace; alternateRequiredContent.Name = this.textBoxAlternateWaterYear.Text; alternateActualContent = residForecastCompare.TotalContent; alternateActualContent.Name = this.textBoxAlternateWaterYear.Text + " Actual"; if (this.pcodeComparison.Text.Length >= 1) { hmList2 = ReadHydrometOptionalData(Convert.ToInt32(this.textBoxAlternateWaterYear.Text), this.pcodeComparison.Text, alternateRange); hmList.AddRange(hmList2); } } if (showGreenLines.Checked == true && !compilePublic) // display flood rule curves for various forecast levels { showRuleCurve = true; // Green lines if (residForecast.RuleCurve.FillType == FillType.Fixed) { ruleCurves = residForecast.RuleCurve.CalculateFixedRuleCurve(curveRange.DateTime1, curveRange.DateTime2, pt.TotalUpstreamActiveSpace); labelDates.Add(curveRange.DateTime1); } else { ruleCurves = residForecast.RuleCurve.CalculateVariableRuleCurves(curveRange.DateTime1, curveRange.DateTime2, pt.TotalUpstreamActiveSpace, pt.PercentSpace / 100.0); labelDates.AddRange(FcPlotDataSet.GetVariableForecastLabelDates(residForecast.RuleCurve.CurveName)); } } else { showRuleCurve = false; } hydrometChart1.SetLabels(pt.Name, "Storage Content (acre-feet)"); bool dashedLines = checkBoxDashed.Checked && pt.StationFC.ToLower() == "heii"; // DEFAULT - Plots daily storage content data if (!checkBoxShowInstantAF.Checked && !checkBoxShowElevation.Checked) { hydrometChart1.Fcplot(residForecast.TotalContent, requiredContent, alternateRequiredContent, alternateActualContent, ruleCurves, labelDates.ToArray(), pt.RequiredLegend, hmList, showRuleCurve, dashedLines); //compute the targets if (pt.FillType == FillType.Variable && (showTarget.Checked == true || checkBoxOverrideFcast.Checked == true)) { if (Convert.ToInt32(this.textBoxWaterYear.Text) == DateTime.Now.WaterYear()) { actualContent.RemoveMissing(); var startPt = actualContent[actualContent.Count - 1]; targets = FloodOperation.ComputeTargets(pt, Convert.ToInt32(this.textBoxWaterYear.Text), startPt, optionalPercents, checkBoxDashed.Checked, this.checkBoxOverrideFcast.Checked, this.textBoxOverrideFcast.Text); var aColors = new Color[] { Color.Black, Color.Maroon, Color.Indigo, Color.DarkSlateGray, Color.SaddleBrown }; for (int i = 0; i < targets.Count; i++) { var s = targets[i]; var c = Color.Black; if (i < aColors.Length) { c = aColors[i]; } hydrometChart1.CreateTarget(c, s.Name, s, "left"); // Add target to datatable residForecast.AddColumnToReportTable(s); } } } } else { string leftPcode = "af";; if (this.checkBoxShowElevation.Checked) { leftPcode = "fb"; hydrometChart1.SetLabels(pt.Name, "Water Level Elevation (feet)"); if (alternateRange.IsValid) { var sAlternate = new Series(); if (checkBoxShowInstantAF.Checked) { sAlternate = new HydrometInstantSeries(pt.UpstreamReservoirs[0], leftPcode, svr); } else { sAlternate = new HydrometDailySeries(pt.UpstreamReservoirs[0], leftPcode, svr); } sAlternate.Read(alternateRange.DateTime1, alternateRange.DateTime2); sAlternate.Name = this.textBoxAlternateWaterYear.Text + " Actual"; sAlternate.Units = residForecast.TotalContent.Units; alternateActualContent = sAlternate; } } if (pt.UpstreamReservoirs.Length == 1) { var s = new Series(); if (checkBoxShowInstantAF.Checked) { var sInstant = new HydrometInstantSeries(pt.UpstreamReservoirs[0], leftPcode, svr); s = sInstant; } else { var sDaily = new HydrometDailySeries(pt.UpstreamReservoirs[0], leftPcode, svr); s = sDaily; } s.Read(residForecast.TotalContent.MinDateTime, residForecast.TotalContent.MaxDateTime.AddDays(1)); s.Name = residForecast.TotalContent.Name; s.Units = residForecast.TotalContent.Units; hydrometChart1.Fcplot(s, requiredContent, alternateRequiredContent, alternateActualContent, ruleCurves, labelDates.ToArray(), pt.RequiredLegend, hmList, showRuleCurve, dashedLines, checkBoxShowElevation.Checked); } } linkLabelReport.Visible = true; labelFlagLegend.Text = pt.FlagLegend; dataGridView1.DataSource = residForecast.ReportTable; } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { Cursor = Cursors.Default; } Cursor = Cursors.Default; }
private void GraphData() { linkLabelReport.Visible = false; if (comboBoxSite.Text.ToString() == "") { return; } try { optionalPercents = ParseOptionalPercentages(); Series alternateRequiredContent = new Series(); Series alternateActualContent = new Series(); Series actualContent = new Series(); Series requiredContent = new Series(); SeriesList targets = new SeriesList(); SeriesList hmList = new SeriesList(); SeriesList hmList2 = new SeriesList(); SeriesList ruleCurves = new SeriesList(); var cache = new HydrometDataCache(); var cbttList = new List <string>(); var cbttListAlternate = new List <string>(); var labelDates = new List <DateTime>(); bool showRuleCurve = true; Cursor = Cursors.WaitCursor; Application.DoEvents(); FloodControlPoint pt = new FloodControlPoint(this.comboBoxSite.Text.ToString()); checkBoxDashed.Visible = pt.StationFC.ToLower() == "heii"; residForecast = new ResidualForecast(pt, checkBoxDashed.Checked); residForecastCompare = new ResidualForecast(pt, checkBoxDashed.Checked); DateRange requiredRange = GetRequiredRange(); DateRange curveRange = GetRuleCurveRange(); DateRange alternateRange = GetComparisonRange(); //setup cache for required cbttList.AddRange(residForecast.DailyCbttPcodeList()); if (this.pcodeInitial.Text.Length >= 1 && this.textBoxWaterYear.Text.Length >= 1) { cbttList.AddRange(OptionalCbttList(this.pcodeInitial.Text)); } cache.Add(cbttList.ToArray(), requiredRange.DateTime1.AddDays(-1), requiredRange.DateTime2.AddDays(1), HydrometHost.PNLinux, TimeInterval.Daily); cache.Add(residForecast.MonthlyCbttPcodeList(), requiredRange.DateTime1, requiredRange.DateTime2, HydrometHost.PNLinux, TimeInterval.Monthly); // setup cache for alternate range if (alternateRange.IsValid) { cbttListAlternate.AddRange(residForecast.DailyCbttPcodeList()); if (this.pcodeComparison.Text.Length >= 1) { cbttListAlternate.AddRange(OptionalCbttList(this.pcodeComparison.Text)); } cache.Add(cbttListAlternate.ToArray(), alternateRange.DateTime1.AddDays(-1), alternateRange.DateTime2.AddDays(1), HydrometHost.PNLinux, TimeInterval.Daily); cache.Add(residForecast.MonthlyCbttPcodeList(), alternateRange.DateTime1.AddDays(-1), alternateRange.DateTime2.AddDays(1), HydrometHost.PNLinux, TimeInterval.Monthly); } //add cache HydrometDailySeries.Cache = cache; HydrometMonthlySeries.Cache = cache; //compute residual forecast residForecast.Compute(requiredRange.DateTime1, requiredRange.DateTime2); requiredContent = -residForecast.SpaceRequired + pt.TotalUpstreamActiveSpace; actualContent = residForecast.TotalContent; requiredContent.Name = this.textBoxWaterYear.Text; actualContent.Name = this.textBoxWaterYear.Text + " Actual"; if (this.pcodeInitial.Text.Length >= 1) { hmList = ReadHydrometOptionalData(Convert.ToInt32(this.textBoxWaterYear.Text), this.pcodeInitial.Text, requiredRange); } //compute comparison year residual forecast if (alternateRange.IsValid) { residForecastCompare.Compute(alternateRange.DateTime1, alternateRange.DateTime2); alternateRequiredContent = -residForecastCompare.SpaceRequired + pt.TotalUpstreamActiveSpace; alternateRequiredContent.Name = this.textBoxAlternateWaterYear.Text; alternateActualContent = residForecastCompare.TotalContent; alternateActualContent.Name = this.textBoxAlternateWaterYear.Text + " Actual"; if (this.pcodeComparison.Text.Length >= 1) { hmList2 = ReadHydrometOptionalData(Convert.ToInt32(this.textBoxAlternateWaterYear.Text), this.pcodeComparison.Text, alternateRange); hmList.AddRange(hmList2); } } if (showGreenLines.Checked == true) // display flood rule curves for various forecast levels { showRuleCurve = true; // Green lines if (residForecast.RuleCurve.FillType == FillType.Fixed) { ruleCurves = residForecast.RuleCurve.CalculateFixedRuleCurve(curveRange.DateTime1, curveRange.DateTime2, pt.TotalUpstreamActiveSpace); labelDates.Add(curveRange.DateTime1); } else { ruleCurves = residForecast.RuleCurve.CalculateVariableRuleCurves(curveRange.DateTime1, curveRange.DateTime2, pt.TotalUpstreamActiveSpace, pt.PercentSpace / 100.0); labelDates.AddRange(FcPlotDataSet.GetVariableForecastLabelDates(residForecast.RuleCurve.CurveName)); } } else { showRuleCurve = false; } hydrometChart1.SetLabels(pt.Name, "Content"); bool dashedLines = checkBoxDashed.Checked && pt.StationFC.ToLower() == "heii"; hydrometChart1.Fcplot(residForecast.TotalContent, requiredContent, alternateRequiredContent, alternateActualContent, ruleCurves, labelDates.ToArray(), pt.RequiredLegend, hmList, showRuleCurve, dashedLines); //compute the targets if (pt.FillType == FillType.Variable && (showTarget.Checked == true || checkBoxOverrideFcast.Checked == true)) { if (Convert.ToInt32(this.textBoxWaterYear.Text) == DateTime.Now.WaterYear()) { actualContent.RemoveMissing(); var startPt = actualContent[actualContent.Count - 1]; targets = FloodOperation.ComputeTargets(pt, Convert.ToInt32(this.textBoxWaterYear.Text), startPt, optionalPercents, checkBoxDashed.Checked, this.checkBoxOverrideFcast.Checked, this.textBoxOverrideFcast.Text); var aColors = new Color[] { Color.Black, Color.Maroon, Color.Indigo, Color.DarkSlateGray, Color.SaddleBrown }; for (int i = 0; i < targets.Count; i++) { var s = targets[i]; var c = Color.Black; if (i < aColors.Length) { c = aColors[i]; } hydrometChart1.CreateTarget(c, s.Name, s, "left"); } } } linkLabelReport.Visible = true; labelFlagLegend.Text = pt.FlagLegend; dataGridView1.DataSource = residForecast.ReportTable; } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { Cursor = Cursors.Default; } Cursor = Cursors.Default; }
/// <summary> /// Creates Daily and Summary Crop Reports /// </summary> /// <param name="cbttList">list of cbtt to create charts for</param> /// <param name="year">year used to filter database of crop dates</param> /// <param name="date">terminate date (or if null use etr terminate date)</param> public static void CreateCropReports(int year, string outputDirectory) { CropDatesDataSet.CropDatesDataTable cropTable = new CropDatesDataSet.CropDatesDataTable(); cropTable = CropDatesDataSet.GetCropDataTable(year, false); var cbttList = (from row in cropTable.AsEnumerable() // get list of cbtt select row.cbtt).Distinct().ToArray(); if (cbttList.Length > 1) {// for performance query hydromet only once. var cache = new HydrometDataCache(); // boii, abei // boii et, abei et var s = String.Join(" ETRS,", cbttList) + " ETRS"; var cbttPcode = s.Split(','); DateTime t1 = new DateTime(year, 1, 1); DateTime t2 = new DateTime(year, 12, 31); if (t2 > DateTime.Now.Date) { t2 = DateTime.Now.Date; } cache.Add(cbttPcode, t1, t2, HydrometHost.PN, TimeSeries.TimeInterval.Daily); HydrometDailySeries.Cache = cache;; } DateTime t = DateTime.Now.Date; for (int i = 0; i < cbttList.Length; i++) { var cropDates = cropTable.Where(x => x.cbtt == cbttList[i] && !x.IsterminatedateNull() && !x.IsstartdateNull() && !x.IsfullcoverdateNull()).ToArray(); if (cropDates.Length == 0) { continue; } ValidateCropDates(cbttList[i], cropDates); var terminateDate = TerminateDate(cbttList[i], cropDates); if (terminateDate < DateTime.Now) { t = terminateDate.AddDays(1); } else { t = DateTime.Now.Date; } // Generates Daily and Summary Crop Charts var dailyChart = CreateDailyReport(cbttList[i], t, cropDates); var sumChart = CreateSummaryReport(cbttList[i], t, cropDates); //string header = "AgriMet is excited to announce a partnership with Washington State University to icorporate AgriMet data into WSU's Irrigation Scheduler. To customize crop consumptive water use specific to your field or fields, visit http://weather.wsu.edu/is/"; var fnDaily = Path.Combine(outputDirectory, cbttList[i].ToLower() + "ch.txt"); var fnSum = Path.Combine(outputDirectory, cbttList[i].ToLower() + t.Year.ToString().Substring(2) + "et.txt"); WriteCropFile(dailyChart, fnDaily); WriteCropFile(sumChart, fnSum); } Console.WriteLine(" Daily and Summary Crop Charts Saved for " + cbttList.Length + " sites"); }
/// <summary> /// Creates and returns the report. /// </summary> /// <returns></returns> public string Create(DateTime t, int year1 = 0, int year2 = 0) // default 8am. { string rval = GetTemplate(); //13-OCT-2016 09:12:35 var fmt = "dd-MMM-yyyy HH:mm:ss"; rval = rval.Replace(fmt, t.ToString(fmt)); rval = rval.Replace("HH:mm", t.ToString("HH:mm")); res_af = Array.ConvertAll(res_af, x => x = double.MinValue); res_af2 = Array.ConvertAll(res_af, x => x = double.MinValue); res_q = Array.ConvertAll(res_af, x => x = double.MinValue); DateTime t1 = t.AddDays(-1); DateTime t2 = t; HydrometDataCache c = new HydrometDataCache(); HydrometInstantSeries.Cache.Add(this.yakima_data, t1, t2, HydrometHost.Yakima, TimeInterval.Irregular); foreach (var cbtt in resList) { rval = ProcessParameter(rval, t, cbtt, "fb"); rval = ProcessParameter(rval, t, cbtt, "af"); rval = ProcessParameter(rval, t, cbtt, "q"); } rval = ReplaceSymbol(rval, "%total_af", total_af); double total_pct = total_af / totalCapacity * 100.0; rval = ReplaceSymbol(rval, "%total_pct", total_pct); rval = ReplaceSymbol(rval, "%total_q", reservoir_total_release); // compute inflows. for (int i = 0; i < resList.Length; i++) { if (resList[i] == "clr") { continue; // no contents } var qu = (res_af[i] - res_af2[i]) / 1.9835 + res_q[i]; rval = ReplaceSymbol(rval, "%" + resList[i] + "_in", qu); total_in += qu; } rval = ReplaceSymbol(rval, "%total_in", total_in); foreach (var canal in DataSubset("qc")) { var cbtt = canal.Substring(0, canal.IndexOf(" ")); rval = ProcessParameter(rval, t, cbtt, "qc"); } double others = ComputeOthersAboveParker(t1); rval = ReplaceSymbol(rval, "%major_qc", major_qc_total); rval = ReplaceSymbol(rval, "%other_qc", others); above_parker_qc += others + major_qc_total; rval = ReplaceSymbol(rval, "%parker_qc", above_parker_qc); foreach (var river in DataSubset("q")) { var cbtt = river.Substring(0, river.IndexOf(" ")); if (!resList.Contains(cbtt)) // reservoir allready processed { rval = ProcessParameter(rval, t, cbtt, "q"); } } // unregulated tributary and return flows above parker. var above_parker = trib_qc_total + others + parw_q - reservoir_total_release; rval = ReplaceSymbol(rval, "%trib_parw", above_parker); rval = rval + "\r\nOPERATIONAL COMMENTS: "; if (year1 > 0 && year2 > 0) { var t1a = new DateTime(year1 - 1, 10, 1); var t2a = new DateTime(year2, 9, 30); double avgPct = MultiYearAvg(t1, t1a, t2a); rval = rval + " Storage is " + avgPct.ToString("F1") + "% of average (" + year1 + ", " + year2 + ")." + "\r\n---------------------"; } return(rval); }
//try to take the code from above and make it into here for the show cmd private static string Get(string s, DateTime t1, DateTime t2) { string[] cbtt = { "" }; string[] pcode = { "" }; string Id = ""; string value = ""; string pc = ""; var cfg = new Config(s, t1, t2); if (s.Trim().ToLower()[0] == 'g') { cbtt = cfg.cbtt; for (int i = 0; i < cbtt.Length; i++) { Id = LoopCBTT(cbtt[i]); if (String.IsNullOrEmpty(Id) == true) { Console.WriteLine("%W-Dayfile, no data found for get request:" + cbtt[i]); } else { string[] ID = Id.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); //improving the speed of the program var cache = new HydrometDataCache(); cache.Add(ID, t1, t2, HydrometHost.PNLinux, Reclamation.TimeSeries.TimeInterval.Irregular); HydrometInstantSeries.Cache = cache; HydrometInstantSeries.KeepFlaggedData = true; if (cfg.IsGetAll) { HydrometInstantSeries ts = new HydrometInstantSeries(ID[0].Split(' ')[0], ID[0].Split(' ')[1]); ts.Read(t1, t2); var count = (ts.MaxDateTime - ts.MinDateTime).TotalMinutes; for (int t = 0; t <= count / 15; t++) { pc = cbtt[i].ToUpper() + " " + t1.AddMinutes(t * 15).ToString("yyMMMdd"); for (int j = 0; j < ID.Length; j++) { var c = ID[j].Split(' ')[0]; var p = ID[j].Split(' ')[1]; HydrometInstantSeries.KeepFlaggedData = true; ts = new HydrometInstantSeries(c, p); ts.Read(t1, t2); pc = pc + " " + p.ToUpper(); if (j == 0) { value = " " + ts.MinDateTime.AddMinutes(t * 15).TimeOfDay + " " + ts[ts.MinDateTime.AddMinutes(t * 15)].Value; } else { value = value + " " + ts[ts.MinDateTime.AddMinutes(t * 15)].Value; } } if (ts.MinDateTime.AddMinutes(t * 15).TimeOfDay.TotalHours == 0 || ts.MinDateTime.AddMinutes(t * 15).TimeOfDay.TotalHours == 12) { WriteLines(pc); } WriteLines(value); } } if (cfg.IsGet || (cfg.IsGetAll == false && cfg.IsGetPcode)) { if (cfg.IsGetAll == false && cfg.IsGetPcode) { pcode = cfg.pcode; Id = ""; for (int j = 0; j < pcode.Length; j++) { Id = Id + cbtt[i] + " " + pcode[j] + ","; } ID = Id.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); } var count = (t2 - t1).TotalDays; for (int t = 0; t <= count; t++) { pc = cbtt[i].ToUpper() + " " + t1.AddDays(t).ToString("yyMMMdd"); for (int j = 0; j < ID.Length; j++) { var c = ID[j].Split(' ')[0]; var p = ID[j].Split(' ')[1]; HydrometInstantSeries.KeepFlaggedData = true; HydrometInstantSeries ts = new HydrometInstantSeries(c, p); ts.Read(t1, t2); pc = pc + " " + p.ToUpper(); if (j == 0) { value = " " + ts.MaxDateTime.AddDays(-count + t).TimeOfDay + " " + ts[ts.MaxDateTime.AddDays(-count + t)].Value; } else { value = value + " " + ts[ts.MaxDateTime.AddDays(-count + t)].Value; } } WriteLines(pc); WriteLines(value); } } } } } return(s); }