示例#1
0
        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;
        }
示例#2
0
        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;
        }