Exemplo n.º 1
0
        private void PlotCurrentData(FcPlotUI ui, string inflowCode, string outflowCode)
        {
            // Process current inflow curve
            var      sInflow = new Reclamation.TimeSeries.Hydromet.HydrometDailySeries(inflowCode.Split(' ')[0], inflowCode.Split(' ')[1]);
            DateTime t1      = DateTime.Now;
            DateTime t2      = DateTime.Now;
            int      yr      = Convert.ToInt32(ui.textBoxWaterYear.Text);

            ui.SetupDates(yr, ref t1, ref t2, false);
            sInflow.Read(t1, t2);
            var sInflowShifted = Reclamation.TimeSeries.Math.ShiftToYear(sInflow, Convert.ToInt16(ui.textBoxWaterYear.Text) - 1);

            CreateSeries(System.Drawing.Color.ForestGreen, ui.textBoxWaterYear.Text + "-Inflow", sInflowShifted, "right");

            // Process current outflow curve
            var sOutflow = new Reclamation.TimeSeries.Hydromet.HydrometDailySeries(outflowCode.Split(' ')[0], outflowCode.Split(' ')[1]);

            t1 = DateTime.Now;
            t2 = DateTime.Now;
            yr = Convert.ToInt32(ui.textBoxWaterYear.Text);
            ui.SetupDates(yr, ref t1, ref t2, false);
            sOutflow.Read(t1, t2);
            var sOutflowShifted = Reclamation.TimeSeries.Math.ShiftToYear(sOutflow, Convert.ToInt16(ui.textBoxWaterYear.Text) - 1);

            CreateSeries(System.Drawing.Color.DarkViolet, ui.textBoxWaterYear.Text + "-Outflow", sOutflowShifted, "right");
        }
Exemplo n.º 2
0
        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();
        }
Exemplo n.º 3
0
        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");
        }
Exemplo n.º 4
0
        /// <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)";
        }
Exemplo n.º 5
0
        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");
        }