private static Series CalculateTarget(FloodControlPoint pt, double percent, int waterYear, Point start, HydrometRuleCurve m_ruleCurve, Series avg30yrQU, DateTime t2, double forecastValue) { //double runoffSum = 0; string flag = ""; Series s = new Series(); Series residual = new Series(); DateTime t = start.DateTime; while (t <= t2) { int idx = avg30yrQU.IndexOf(t); var sum = SumResidual(avg30yrQU, t, t2) * percent; residual.Add(t, sum); t = t.AddDays(1); } for (int i = 0; i < residual.Count(); i++) { // lookup space requirement in reservoir rule curve DateTime avg = residual[i].DateTime; DateTime dt = new DateTime(waterYear, residual[i].DateTime.Month, residual[i].DateTime.Day); double val = -m_ruleCurve.LookupRequiredSpace(avg, residual[i].Value, out flag) * pt.PercentSpace / 100 + pt.TotalUpstreamActiveSpace; if (val >= pt.TotalUpstreamActiveSpace) { val = pt.TotalUpstreamActiveSpace; } s.Add(dt, val); } return(s); }
internal void PlotEsps(FcPlotUI ui, FloodControlPoint pt, FcOpsMenu opsUI) { opsUI.toolStripStatusLabel1.Text = "Plotting Esps..."; // Get required variables from the available resources string inflowYear = opsUI.numericUpDownInflowYear.Value.ToString(); var sItem = opsUI.comboBoxEspTraces.SelectedItem; var selIndex = opsUI.yearList.IndexOf(sItem.ToString()); var s = opsUI.espList[selIndex - 1]; inflowYear = (sItem.ToString()); int yr = Convert.ToInt32(ui.textBoxWaterYear.Text); DateTime t1 = new DateTime(), t2 = new DateTime(); ui.SetupDates(yr, ref t1, ref t2, false); t2 = ui.GetWyEnd(t2); var sInflow = new Reclamation.TimeSeries.Hydromet.HydrometDailySeries("", ""); var sInflowShifted = new Series(); sInflow.Table = s.Table; sInflowShifted = Reclamation.TimeSeries.Math.ShiftToYear(sInflow, Convert.ToInt16(ui.textBoxWaterYear.Text) - 1); sInflowShifted = sInflowShifted.Subset(t1, t2); CreateSeries(espColors[espColorCounter], inflowYear + "-ESP Inflow", sInflowShifted, "right", true); espColorCounter++; if (espColorCounter >= espColors.Count) { espColorCounter = 0; } SetupTChartTools(); }
/// <summary> /// ComputeTargets method uses the a Rule curve, forecast, and historical average /// to project flood target levels through the forecast period. /// computes a target Seriesuses the current forecast and forecast volume period /// </summary> /// <param name="pt"></param> /// <param name="waterYear"></param> /// <param name="start"></param> /// <param name="optionalPercents"></param> /// <returns></returns> public static SeriesList ComputeTargets(FloodControlPoint pt, int waterYear, Point start, int[] optionalPercents, bool dashed, bool forecastOverride, string forecastValIn) { string cbtt = pt.StationFC; SeriesList rval = new SeriesList(); Series forecast = new Series(); int forecastMonth = 0; double forecastValue = 0; if (forecastOverride) { forecastMonth = DateTime.Now.Month;// System.Math.Min(1, DateTime.Now.Month); forecastValue = Convert.ToDouble(forecastValIn); } else { //calculate forecast of most recent month forecast = GetLatestForecast(cbtt, waterYear); forecastMonth = MonthOfLastForecast(forecast); //if no forecast cannot compute target if (forecastMonth == 0) { return(rval); } //value of forecast to use for percent of average forecastValue = forecast[forecastMonth - 1].Value; } // average runoff month - end(typically July) volume if (cbtt.ToLower() == "hgh") { var avg30yrQU = Get30YearAverageSeries(pt.DailyStationQU, "qu", 5); // sum volume for the forecast period (may,sep) var t = new DateTime(start.DateTime.Year, 5, 1); var t2 = new DateTime(start.DateTime.Year, 9, 30); double historicalAverageResidual = SumResidual(avg30yrQU, t, t2); double percent = forecastValue / historicalAverageResidual; var x = HGHTarget(pt, forecastValue, start.DateTime, t); x.Name = "Forecast " + (100 * percent).ToString("F0") + "% " + (forecastValue / 1000.0).ToString("F0");; rval.Add(x); for (int i = 0; i < optionalPercents.Length; i++) { var fc = historicalAverageResidual * optionalPercents[i] / 100.0; x = HGHTarget(pt, fc, start.DateTime, t); x.Name = "Target (" + optionalPercents[i].ToString("F0") + "%) " + (fc / 1000.0).ToString("F0"); rval.Add(x); } } else { rval.Add(GetTargets(pt, waterYear, start, optionalPercents, forecastMonth, forecastValue, dashed)); } return(rval); }
private static Series HGHTarget(FloodControlPoint pt, double forecastValue, DateTime t1, DateTime t2) { HydrometRuleCurve m_ruleCurve = RuleCurveFactory.Create(pt, 7100); Series target = new Series("Target"); string flag = ""; DateTime t = t1; while (t < t2.AddDays(-1)) { t = t.AddDays(1).Date; double val = -m_ruleCurve.LookupRequiredSpace(t, forecastValue, out flag) * pt.PercentSpace / 100 + pt.TotalUpstreamActiveSpace; target.Add(t, val); } return(target); }
/// <summary> /// Create a list of targts /// </summary> /// <param name="pt"></param> /// <param name="waterYear"></param> /// <param name="start"></param> /// <param name="optionalPercents"></param> /// <param name="m_ruleCurve"></param> /// <param name="t2"></param> /// <param name="forecastMonth"></param> /// <param name="forecastValue"></param> /// <returns></returns> private static SeriesList GetTargets(FloodControlPoint pt, int waterYear, Point start, int[] optionalPercents, int forecastMonth, double forecastValue, bool dashed) { SeriesList rval = new SeriesList(); HydrometRuleCurve m_ruleCurve = RuleCurveFactory.Create(pt, 7100, dashed); var t1 = new DateTime(waterYear, pt.ForecastMonthStart, 1); var t2 = new DateTime(waterYear, pt.ForecastMonthEnd, 1).EndOfMonth(); var avg30yrQU = Get30YearAverageSeries(pt.DailyStationQU, "qu", forecastMonth); // sum volume for the forecast period var t = new DateTime(start.DateTime.Year, start.DateTime.Month, 1); double historicalAverageResidual = SumResidual(avg30yrQU, t, t2); // capture if running the process before forecast season starts (before Jan) if (DateTime.Now.Month > 9) { historicalAverageResidual = SumResidual(avg30yrQU, t.AddYears(1), t2.AddYears(1)); } double percent = forecastValue / historicalAverageResidual; //get thirty year average QU from daily //avg30yrQU = Get30YearAverageSeries(pt.DailyStationQU, "qu", forecastMonth); Series targetx = CalculateTarget(pt, percent, waterYear, start, m_ruleCurve, avg30yrQU, t2, forecastValue); targetx.Name = "Forecast (" + (100 * percent).ToString("F0") + "%)" + (forecastValue / 1000.0).ToString("F0"); //targetx.Add(start); rval.Add(targetx); for (int i = 0; i < optionalPercents.Length; i++) { var fc = historicalAverageResidual * optionalPercents[i] / 100.0; targetx = CalculateTarget(pt, optionalPercents[i] / 100.0, waterYear, start, m_ruleCurve, avg30yrQU , t2, fc); targetx.Name = "Target (" + optionalPercents[i].ToString("F0") + "%) "; //targetx.Add(start); rval.Add(targetx); } return(rval); }
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; }
public FcOpsMenu(FcPlotUI ui) { InitializeComponent(); this.ui = ui; pt = new FloodControlPoint(ui.comboBoxSite.Text.ToString()); double maxSpace = pt.TotalUpstreamActiveSpace; this.textBoxSpace.Text = maxSpace.ToString("F0"); string dams = string.Join(", ", pt.UpstreamReservoirs); this.textBoxDams.Text = dams; string inflowCode = pt.ResOpsInflow; this.textBoxInflowCode.Text = inflowCode; int maxYear = DateTime.Now.Year - 1; if (DateTime.Now.Month > 9) { maxYear = DateTime.Now.Year; } this.numericUpDownInflowYear.Maximum = maxYear; this.numericUpDownInflowYear.Value = maxYear; string outflowCode = pt.ResOpsOutflow; this.textBoxOutflowCode.Text = outflowCode; this.numericUpDownOutflowYear.Maximum = maxYear; this.numericUpDownOutflowYear.Value = maxYear; this.dateTimePickerSimStart.MaxDate = DateTime.Now.Date; this.comboBoxEspDay.SelectedItem = this.comboBoxEspDay.Items[1]; this.comboBoxEspTraces.SelectedItem = this.comboBoxEspTraces.Items[0]; this.toolStripStatusLabel1.Text = ""; this.textBoxRfcNode.Text = pt.EspNode; if (ui.HydrometServer != Reclamation.TimeSeries.Hydromet.HydrometHost.PNLinux) { this.checkBoxUseCustomInflow.Checked = false; this.checkBoxUseCustomInflow.Enabled = false; } // Fill outflow datagrid var qOutTable = new System.Data.DataTable(); qOutTable.Columns.Add("Outflow", typeof(Int64)); qOutTable.Columns.Add("StartDate", typeof(DateTime)); qOutTable.Columns.Add("EndDate", typeof(DateTime)); var qOutRow = qOutTable.NewRow(); qOutRow["StartDate"] = DateTime.Now.Date; qOutRow["EndDate"] = DateTime.Now.AddDays(10).Date; var s = new Reclamation.TimeSeries.Hydromet.HydrometDailySeries(outflowCode.Split(' ')[0], outflowCode.Split(' ')[1]); s.Read(DateTime.Now.AddDays(-1).Date, DateTime.Now.Date); try { qOutRow["Outflow"] = s[0].Value; } catch { qOutRow["Outflow"] = -99; } qOutTable.Rows.Add(qOutRow); this.dataGridView1.DataSource = qOutTable; this.dataGridView1.Columns[1].ReadOnly = true; this.dataGridView1.Columns[1].DefaultCellStyle.ForeColor = System.Drawing.Color.Gray; this.dataGridView1.RowsAdded += new System.Windows.Forms.DataGridViewRowsAddedEventHandler(this.dataGridView1_RowsAdded); // Handle ENTER key press this.KeyPress += new System.Windows.Forms.KeyPressEventHandler(CheckEnterKeyPress); this.numericUpDownInflowYear.KeyPress += new System.Windows.Forms.KeyPressEventHandler(CheckEnterKeyPress); this.numericUpDownOutflowYear.KeyPress += new System.Windows.Forms.KeyPressEventHandler(CheckEnterKeyPress); this.numericUpDownInflowShift.KeyPress += new System.Windows.Forms.KeyPressEventHandler(CheckEnterKeyPress); this.numericUpDownOutflowShift.KeyPress += new System.Windows.Forms.KeyPressEventHandler(CheckEnterKeyPress); this.textBoxInflowScale.KeyPress += new System.Windows.Forms.KeyPressEventHandler(CheckEnterKeyPress); this.textBoxOutflowScale.KeyPress += new System.Windows.Forms.KeyPressEventHandler(CheckEnterKeyPress); this.comboBoxEspTraces.KeyPress += new System.Windows.Forms.KeyPressEventHandler(CheckEnterKeyPress); // Add tooltips // Create the ToolTip and associate with the Form container. ToolTip toolTip1 = new ToolTip(); // Set up the delays for the ToolTip. toolTip1.AutoPopDelay = 5000; toolTip1.InitialDelay = 200; toolTip1.ReshowDelay = 200; // Force the ToolTip text to be displayed whether or not the form is active. toolTip1.ShowAlways = true; // Set up the ToolTip text for the Button and Checkbox. toolTip1.SetToolTip(this.checkBoxRedrawGraph, "Unchecking this will allow you to graph multiple scenario curves on the chart"); toolTip1.SetToolTip(this.checkBoxUseCustomInflow, "Checking this will allow you to download and use RFC ESP inflows"); toolTip1.SetToolTip(this.checkBoxUseCustomOutflow, "Checking this will allow you to use your own outflow schedule"); }
/// <summary> /// Method to perform operations given an inflow and an outflow /// [JR] Need to refactor this code! Maybe make a new class like FloodOperation? something like SimulationOperation? /// </summary> /// <param name="ui"></param> internal void FcOps(FcPlotUI ui, FloodControlPoint pt, FcOpsMenu opsUI) { opsUI.toolStripStatusLabel1.Text = "Performing operations simulation..."; // Get required variables from the available resources string inflowCode = opsUI.textBoxInflowCode.Text; string outflowCode = opsUI.textBoxOutflowCode.Text; string inflowYear = opsUI.numericUpDownInflowYear.Value.ToString(); string outflowYear = opsUI.numericUpDownOutflowYear.Value.ToString(); string[] resCodes = pt.UpstreamReservoirs; double maxSpace = pt.TotalUpstreamActiveSpace; decimal inflowShift = opsUI.numericUpDownInflowShift.Value; decimal outflowShift = opsUI.numericUpDownOutflowShift.Value; string inflowScale = opsUI.textBoxInflowScale.Text; string outflowScale = opsUI.textBoxOutflowScale.Text; // redraw the main graph if (opsUI.checkBoxRedrawGraph.Checked) { ui.GraphData(); } PlotCurrentData(ui, inflowCode, outflowCode); var sOutflow = new Reclamation.TimeSeries.Hydromet.HydrometDailySeries("", ""); var sOutflowShifted = new Series(); var sInflow = new Reclamation.TimeSeries.Hydromet.HydrometDailySeries("", ""); var sInflowShifted = new Series(); DateTime t1, t2; int yr; // Get observed storage contents // [JR] we only need the last value so we can streamline this code... // or keep it as is and allow the user to start the simulation from a past date... var ithStorage = new Reclamation.TimeSeries.Hydromet.HydrometDailySeries(resCodes[0], "AF"); t1 = DateTime.Now; t2 = DateTime.Now; yr = Convert.ToInt32(ui.textBoxWaterYear.Text); ui.SetupDates(yr, ref t1, ref t2, false); ithStorage.Read(t1, t2); Series sStorage = new Series(ithStorage.Table, "content", TimeInterval.Daily); for (int i = 1; i < resCodes.Count(); i++) { ithStorage = new Reclamation.TimeSeries.Hydromet.HydrometDailySeries(resCodes[i], "AF"); t1 = DateTime.Now; t2 = DateTime.Now; yr = Convert.ToInt32(ui.textBoxWaterYear.Text); ui.SetupDates(yr, ref t1, ref t2, false); ithStorage.Read(t1, t2); Series sStorageTemp = new Series(ithStorage.Table, "content", TimeInterval.Daily); sStorage = sStorage + sStorageTemp; } //Reclamation.TimeSeries.Point lastPt = sStorage[sStorage.Count() - 1]; // could potentially start simulation from any past date... Reclamation.TimeSeries.Point lastPt = sStorage[opsUI.dateTimePickerSimStart.Value.AddDays(-1)]; // Process simulation outflow curve double outflowScaleValue; try { outflowScaleValue = Convert.ToDouble(outflowScale); } catch { outflowScaleValue = 1.0; } sOutflow = new Reclamation.TimeSeries.Hydromet.HydrometDailySeries(outflowCode.Split(' ')[0], outflowCode.Split(' ')[1]); t1 = DateTime.Now; t2 = DateTime.Now; yr = Convert.ToInt32(outflowYear); ui.SetupDates(yr, ref t1, ref t2, false); sOutflow.Read(t1, t2); sOutflowShifted = Reclamation.TimeSeries.Math.ShiftToYear(sOutflow, Convert.ToInt16(ui.textBoxWaterYear.Text) - 1); t1 = sOutflowShifted.MinDateTime; t2 = sOutflowShifted.MaxDateTime; sOutflowShifted = Reclamation.TimeSeries.Math.Shift(sOutflowShifted, Convert.ToInt32(outflowShift)); sOutflowShifted = sOutflowShifted.Subset(t1, t2); sOutflowShifted = sOutflowShifted * outflowScaleValue; if (opsUI.checkBoxUseCustomOutflow.Checked) //apply custom outflow { DateTime customT1 = opsUI.dateTimePickerCustomOutflow1.Value; DateTime customT2 = opsUI.dateTimePickerCustomOutflow2.Value; DateTime customT3 = opsUI.dateTimePickerCustomOutflow3.Value; var customV1 = Convert.ToInt32(opsUI.textBoxCustomOutflow1.Text); var customV2 = Convert.ToInt32(opsUI.textBoxCustomOutflow2.Text); Series rval = sOutflowShifted.Clone(); foreach (var item in sOutflowShifted) { DateTime sDate1 = new DateTime(customT1.Year, customT1.Month, customT1.Day); DateTime sDate2 = new DateTime(customT2.Year, customT2.Month, customT2.Day); DateTime sDate3 = new DateTime(customT3.Year, customT3.Month, customT3.Day); var ithDate = item.DateTime; if (ithDate >= sDate1 && ithDate < sDate2 && customV1 >= 0) { rval.Add(ithDate, customV1); } else if (ithDate >= sDate2 && ithDate < sDate3 && customV2 >= 0) { rval.Add(ithDate, customV2); } else { rval.Add(item); } } sOutflowShifted = rval; } CreateSeries(System.Drawing.Color.Plum, outflowYear + "-Outflow", sOutflowShifted, "right", true); // Process simulation inflow curve double inflowScaleValue; try { inflowScaleValue = Convert.ToDouble(inflowScale); } catch { inflowScaleValue = 1.0; } if (opsUI.checkBoxUseCustomInflow.Checked && opsUI.yearList.Count() > 0) { var sItem = opsUI.comboBoxEspTraces.SelectedItem; var selIndex = opsUI.yearList.IndexOf(sItem.ToString()); var s = opsUI.espList[selIndex - 1]; inflowYear = (sItem.ToString()); sInflow.Table = s.Table; sInflowShifted = Reclamation.TimeSeries.Math.Shift(sInflow, Convert.ToInt32(inflowShift)); sInflowShifted = sInflowShifted.Subset(sOutflowShifted.MinDateTime, sOutflowShifted.MaxDateTime); sInflowShifted = sInflowShifted * inflowScaleValue; CreateSeries(System.Drawing.Color.LawnGreen, inflowYear + "-ESP Inflow", sInflowShifted, "right", true); } else { sInflow = new Reclamation.TimeSeries.Hydromet.HydrometDailySeries(inflowCode.Split(' ')[0], inflowCode.Split(' ')[1]); t1 = DateTime.Now; t2 = DateTime.Now; yr = Convert.ToInt32(inflowYear); ui.SetupDates(yr, ref t1, ref t2, false); sInflow.Read(t1, t2); sInflowShifted = Reclamation.TimeSeries.Math.ShiftToYear(sInflow, Convert.ToInt16(ui.textBoxWaterYear.Text) - 1); t1 = sInflowShifted.MinDateTime; t2 = sInflowShifted.MaxDateTime; sInflowShifted = Reclamation.TimeSeries.Math.Shift(sInflowShifted, Convert.ToInt32(inflowShift)); sInflowShifted = sInflowShifted.Subset(t1, t2); sInflowShifted = sInflowShifted * inflowScaleValue; CreateSeries(System.Drawing.Color.LawnGreen, inflowYear + "-Inflow", sInflowShifted, "right", true); } // Process simulated storage curve and run storage simulation forward DateTime minDate = new DateTime(System.Math.Min(sOutflowShifted.MaxDateTime.Ticks, sInflowShifted.MaxDateTime.Ticks)); //day-shifting misaligns the max-dates of each series if (lastPt.DateTime < minDate) { var t = lastPt.DateTime; var stor = lastPt.Value; var simStorage = new Series(); var simSpill = new Series(); var simShort = new Series(); simStorage.Add(lastPt); while (t < minDate) { t = t.AddDays(1); var volIn = (sInflowShifted[t].Value * 86400.0 / 43560.0); var volOut = (sOutflowShifted[t].Value * 86400.0 / 43560.0); var tempStor = stor + volIn - volOut; if (tempStor >= maxSpace) { var spill = (tempStor - maxSpace) * 43560.0 / 86400.0; simSpill.Add(t, spill); stor = maxSpace; } else if (tempStor <= 0) { var shrt = (0 - tempStor) * 43560.0 / 86400.0; simShort.Add(t, shrt); stor = 0; } else { stor = tempStor; } simStorage.Add(t, stor); } // Add series items to chart CreateSeries(System.Drawing.Color.DodgerBlue, "Simulated Storage (" + inflowYear + "-Qin | " + outflowYear + "-Qout)", simStorage, "left", true); if (simSpill.Count() > 0) { CreateSeries(System.Drawing.Color.OrangeRed, "Simulated Spill (" + inflowYear + "-Qin | " + outflowYear + "-Qout)", simSpill, "right", true); } if (simShort.Count() > 0) { CreateSeries(System.Drawing.Color.Cyan, "Simulated Shortage (" + inflowYear + "-Qin | " + outflowYear + "-Qout)", simShort, "right", true); } } tChart1.Axes.Right.Grid.Visible = false; tChart1.Axes.Right.Title.Caption = "Flow (cfs)"; tChart1.Axes.Right.FixedLabelSize = false; SetupTChartTools(); opsUI.toolStripStatusLabel1.Text = "Showing results for (" + inflowYear + "-Qin | " + outflowYear + "-Qout)"; }
public FcOpsMenu(FcPlotUI ui) { InitializeComponent(); this.ui = ui; pt = new FloodControlPoint(ui.comboBoxSite.Text.ToString()); double maxSpace = pt.TotalUpstreamActiveSpace; this.textBoxSpace.Text = maxSpace.ToString("F0"); string dams = string.Join(", ", pt.UpstreamReservoirs); this.textBoxDams.Text = dams; string inflowCode = pt.ResOpsInflow; this.textBoxInflowCode.Text = inflowCode; int maxYear = DateTime.Now.Year - 1; if (DateTime.Now.Month > 9) { maxYear = DateTime.Now.Year; } this.numericUpDownInflowYear.Maximum = maxYear; this.numericUpDownInflowYear.Value = maxYear; string outflowCode = pt.ResOpsOutflow; this.textBoxOutflowCode.Text = outflowCode; this.numericUpDownOutflowYear.Maximum = maxYear; this.numericUpDownOutflowYear.Value = maxYear; this.dateTimePickerCustomOutflow1.Value = DateTime.Now.Date; this.dateTimePickerCustomOutflow2.Value = DateTime.Now.Date.AddDays(5); this.dateTimePickerCustomOutflow3.Value = DateTime.Now.Date.AddDays(10); this.dateTimePickerSimStart.MaxDate = DateTime.Now.Date; this.comboBoxEspDay.SelectedItem = this.comboBoxEspDay.Items[1]; this.comboBoxEspTraces.SelectedItem = this.comboBoxEspTraces.Items[0]; this.toolStripStatusLabel1.Text = ""; this.textBoxRfcNode.Text = pt.EspNode; // Handle ENTER key press this.KeyPress += new System.Windows.Forms.KeyPressEventHandler(CheckEnterKeyPress); this.numericUpDownInflowYear.KeyPress += new System.Windows.Forms.KeyPressEventHandler(CheckEnterKeyPress); this.numericUpDownOutflowYear.KeyPress += new System.Windows.Forms.KeyPressEventHandler(CheckEnterKeyPress); this.numericUpDownInflowShift.KeyPress += new System.Windows.Forms.KeyPressEventHandler(CheckEnterKeyPress); this.numericUpDownOutflowShift.KeyPress += new System.Windows.Forms.KeyPressEventHandler(CheckEnterKeyPress); this.textBoxInflowScale.KeyPress += new System.Windows.Forms.KeyPressEventHandler(CheckEnterKeyPress); this.textBoxOutflowScale.KeyPress += new System.Windows.Forms.KeyPressEventHandler(CheckEnterKeyPress); this.comboBoxEspTraces.KeyPress += new System.Windows.Forms.KeyPressEventHandler(CheckEnterKeyPress); // Add tooltips // Create the ToolTip and associate with the Form container. ToolTip toolTip1 = new ToolTip(); // Set up the delays for the ToolTip. toolTip1.AutoPopDelay = 5000; toolTip1.InitialDelay = 200; toolTip1.ReshowDelay = 200; // Force the ToolTip text to be displayed whether or not the form is active. toolTip1.ShowAlways = true; // Set up the ToolTip text for the Button and Checkbox. toolTip1.SetToolTip(this.checkBoxRedrawGraph, "Unchecking this will allow you to graph multiple scenario curves on the chart"); toolTip1.SetToolTip(this.checkBoxUseCustomInflow, "Checking this will allow you to download and use RFC ESP inflows"); toolTip1.SetToolTip(this.checkBoxUseCustomOutflow, "Checking this will allow you to use your own outflow schedule"); }