Beispiel #1
0
        /// <summary>
        /// prints csv table in this format.
        /// DateTime,current year, previous, average
        /// 10/1/2017, 123.34,   69.0,   77.7
        /// 10/2/2017, 120.0,   67.0,   77.3
        /// </summary>
        private void PrintAnalysis(TimeRange r, string siteID, string parameter)
        {
            Console.Write("Content-type: text/csv\n\n");
            var years   = new List <int>();
            var current = DateTime.Now.Date.WaterYear();
            var prev    = current - 1;

            years.Add(current);
            years.Add(prev);
            DateTime startOf30YearAvearge = HydrometDataUtility.T1Thirty;

            var x = new SeriesList();

            Series s = new HydrometDailySeries(siteID, parameter, HydrometHost.PNLinux);

            x.Add(s);
            var result = PiscesAnalysis.WaterYears(x, years.ToArray(), true, 10, true, startOf30YearAvearge);
            var tbl    = result.ToDataTable(true);

            // Console.WriteLine("<pre/>");
            Console.WriteLine("DateTime,Current Year,Previous Year,Average");
            for (int i = 0; i < tbl.Rows.Count; i++)
            {
                var o   = tbl.Rows[i];
                var str = ((DateTime)o[0]).ToString("yyyy/MM/dd");
                Console.WriteLine(str + "," + o[1].ToString() + "," + o[2].ToString() + "," + o[3].ToString());
            }
        }
Beispiel #2
0
        /// <summary>
        /// prints csv table in this format.
        /// DateTime,current year, previous, average
        /// 10/1/2017, 123.34,   69.0,   77.7
        /// 10/2/2017, 120.0,   67.0,   77.3
        /// </summary>
        private string PrintAnalysis(string siteID, string parameter)
        {
            var years   = new List <int>();
            var current = DateTime.Now.Date.WaterYear();
            var prev    = current - 1;

            years.Add(current);
            years.Add(prev);
            DateTime startOf30YearAvearge = HydrometDataUtility.T1Thirty;

            var x = new SeriesList();

            var s = db.GetSeriesFromTableName("daily_" + siteID + "_" + parameter);

            if (s == null)
            {
                return("Error:  no data found: " + siteID + "/" + parameter);
            }
            x.Add(s);
            var result = PiscesAnalysis.WaterYears(x, years.ToArray(), true, 10, true, startOf30YearAvearge);
            var tbl    = result.ToDataTable(true);
            // Console.WriteLine("<pre/>");
            StringBuilder sb = new StringBuilder();

            sb.Append("DateTime,Current Year,Previous Year,Average");

            for (int i = 0; i < tbl.Rows.Count; i++)
            {
                var o   = tbl.Rows[i];
                var str = ((DateTime)o[0]).ToString("yyyy/MM/dd");
                sb.AppendLine();
                sb.Append(str + "," + o[1].ToString() + "," + o[2].ToString() + "," + o[3].ToString());
            }
            return(sb.ToString());
        }
Beispiel #3
0
        private static void GPAverage(string cbtt, HydrometHost server, MonthDayRange range, SeriesList wyList)
        {
            var se_avg = new HydrometDailySeries(cbtt, "se_avg", server);
            var sl2    = new SeriesList();

            sl2.Add(se_avg);
            var list1 = PiscesAnalysis.WaterYears(sl2, new int[] { 2002 }, false, range.Month1, true);

            if (list1.Count == 1)
            {
                var se = list1[0];
                se.Appearance.LegendText = "SE_AVG";
                wyList.Add(se);
            }
        }
Beispiel #4
0
        private void buttonRefresh_Click(object sender, EventArgs e)
        {
            try
            {
                timeSeriesGraph1.AnnotationOnMouseMove = checkBoxAnnotate.Checked;
                Cursor = Cursors.WaitCursor;
                Application.DoEvents();
                string pcodeOrig = DeterminePcode();

                timeSeriesGraph1.Clear();

                string cbttOrig = comboBoxCbtt.Text.Trim();
                string cbtt = cbttOrig, pcode = pcodeOrig;

                var seriesList = new List <string>();
                if ((cbttOrig.Trim() == "" || pcodeOrig.Trim() == "") && textBoxMultiple.Text == "")
                {
                    return;
                }
                else
                {
                    if (!checkBoxUseList.Checked)
                    {
                        UserPreference.Save("Snowgg->cbtt", cbttOrig);
                        UserPreference.Save("Snowgg->pcode", comboBoxPcode.Text.Trim());
                        seriesList.Add(cbttOrig + "_" + pcodeOrig);
                    }
                    else
                    {
                        var seriesItems = textBoxMultiple.Text.Split(',');
                        foreach (string item in seriesItems)
                        {
                            if (item.Trim().Split(' ').Length == 2)
                            {
                                seriesList.Add(item.Trim().Split(' ')[0] + "_" + item.Trim().Split(' ')[1]);
                            }
                        }
                    }
                }

                int[]      waterYears            = this.yearSelector1.SelectedYears;
                SeriesList finalSeriesCollection = new SeriesList();
                foreach (string series in seriesList)
                {
                    cbtt = series.Split('_')[0];
                    comboBoxCbtt.Text  = cbtt;
                    pcode              = series.Split('_')[1];
                    comboBoxPcode.Text = pcode;
                    var server = HydrometInfoUtility.HydrometServerFromPreferences();
                    var range  = monthRangePicker1.MonthDayRange;

                    Series s  = new HydrometDailySeries(cbtt, pcode, server);
                    var    sl = new SeriesList();
                    sl.Add(s);

                    var wyList = PiscesAnalysis.WaterYears(sl, waterYears, false, 10, true);

                    foreach (var item in wyList)
                    {
                        item.Name = cbtt + " " + pcode;
                    }


                    wyList = ApplyDeltas(wyList, waterYears);
                    AddStatistics(wyList);

                    if (checkBoxGP.Checked)
                    {
                        GPAverage(cbtt, server, range, wyList);
                    }

                    var mp = ReadMpollData(pcode, cbtt);
                    mp.RemoveMissing();
                    if (mp.Count > 0)
                    {
                        wyList.Add(mp);
                    }

                    // remove months outside selected range
                    var list = FilterBySelectedRange(range, wyList);
                    finalSeriesCollection.Add(list);
                }

                // Set series line colors
                var uniqueSeriesNames  = new List <string>();
                var uniqueSeriesColors = new List <string>();
                int colorCounter       = 0;
                foreach (var item in finalSeriesCollection)
                {
                    // set line color by year which is identified in the legendtext field
                    if (!uniqueSeriesNames.Contains(item.Appearance.LegendText) && !item.Appearance.LegendText.Contains("%") &&
                        !item.Appearance.LegendText.Contains("avg") && !item.Appearance.LegendText.Contains("max") && !item.Appearance.LegendText.Contains("min"))
                    {
                        uniqueSeriesNames.Add(item.Appearance.LegendText);//.Name);
                        uniqueSeriesColors.Add(snowGgColors[colorCounter]);
                        colorCounter = (colorCounter + 1) % snowGgColors.Count;
                    }
                }
                foreach (var item in finalSeriesCollection)
                {
                    try
                    {
                        int colIdx = uniqueSeriesNames.IndexOf(item.Appearance.LegendText);//.Name);
                        item.Appearance.Color = uniqueSeriesColors[colIdx];
                    }
                    catch
                    {
                        item.Appearance.Color = "Black";
                    }
                }

                this.timeSeriesGraph1.AnalysisType = AnalysisType.WaterYears;
                this.timeSeriesGraph1.Series       = finalSeriesCollection;
                if (seriesList.Count == 1)
                {
                    this.timeSeriesGraph1.Title = HydrometInfoUtility.LookupSiteDescription(cbtt) + "  Elevation:" + HydrometInfoUtility.LookupElevation(pcode);
                }
                //timeSeriesGraph1.GraphSettings = GetGraphSettings();

                this.timeSeriesGraph1.Draw(true);

                comboBoxCbtt.Text  = cbttOrig;
                comboBoxPcode.Text = pcodeOrig;

                timeSeriesGraph1.GraphSettings = GetGraphSettings();
            }
            finally
            {
                Cursor = Cursors.Default;
            }
        }
Beispiel #5
0
        private DataTable GetTimeSeries()
        {
            HydrometHost svr = HydrometInfoUtility.HydrometServerFromPreferences();

            string query = comboBoxInputs.Text.Trim();

            if (m_db == TimeInterval.Daily)
            {
                if (CbttOnly(query))
                {
                    string[] pcodes = HydrometInfoUtility.ArchiveParameters(query);
                    if (pcodes.Length > 0)
                    {
                        query = query + " " + String.Join(",", pcodes);
                    }
                }
                string[] tokens = query.Split(' ');
                if (tokens.Length != 2)
                {
                    return(new DataTable());
                }

                string cbtt  = tokens[0];
                string pcode = tokens[1];
                Series s     = new HydrometDailySeries(cbtt, pcode, HydrometInfoUtility.HydrometServerFromPreferences());
                var    sl    = new SeriesList();
                sl.Add(s);

                int beginningMonth = 1;
                if (checkBoxWaterYear.Checked)
                {
                    beginningMonth = 10;
                }

                var wyList = PiscesAnalysis.WaterYears(sl, this.yearSelector1.SelectedYears, false, beginningMonth, true);

                if (checkBoxCelsius.Checked)
                {
                    for (int i = 0; i < wyList.Count; i++)
                    {
                        s = wyList[i];
                        if (s.Units.ToLower() == "degrees f")
                        {
                            Reclamation.TimeSeries.Math.ConvertUnits(s, "degrees C");
                        }
                    }
                }

                // remove months outside selected range
                var list = FilterBySelectedRange(this.monthRangePicker1.MonthDayRange, wyList);


                return(list.ToDataTable(true));
                // return HydrometUtility.ArchiveTable(svr,query, T1, T2);
            }
            //else
            //    if (m_db == HydrometDataBase.Dayfiles)
            //    {

            //        if (CbttOnly(query))
            //        {
            //            string[] pcodes = Hydromet.DayfileParameters(query);
            //            if (pcodes.Length > 0)
            //            {
            //                query = query + " " + String.Join(",", pcodes);
            //            }
            //        }
            //        return HydrometUtility.DayFilesTable(svr,query, T1, T2);
            //    }
            //    else
            //        if (m_db == HydrometDataBase.MPoll)
            //        {

            //            return HydrometUtility.MPollTable(svr,query, T1, T2);
            //        }

            return(new DataTable());
        }
Beispiel #6
0
        private void buttonRefresh_Click(object sender, EventArgs e)
        {
            try
            {
                timeSeriesGraph1.AnnotationOnMouseMove = checkBoxAnnotate.Checked;
                Cursor = Cursors.WaitCursor;
                Application.DoEvents();
                string pcode = DeterminePcode();

                timeSeriesGraph1.Clear();

                string cbtt = comboBoxCbtt.Text.Trim();

                if (cbtt.Trim() == "" || pcode.Trim() == "")
                {
                    return;
                }

                UserPreference.Save("Snowgg->cbtt", cbtt);
                UserPreference.Save("Snowgg->pcode", comboBoxPcode.Text.Trim());

                int[] waterYears = this.yearSelector1.SelectedYears;
                var   server     = HydrometInfoUtility.HydrometServerFromPreferences();
                var   range      = monthRangePicker1.MonthDayRange;

                Series s  = new HydrometDailySeries(cbtt, pcode, server);
                var    sl = new SeriesList();
                sl.Add(s);

                var wyList = PiscesAnalysis.WaterYears(sl, waterYears, false, 10, true);

                AddStatistics(wyList);

                if (checkBoxGP.Checked)
                {
                    GPAverage(cbtt, server, range, wyList);
                }

                var mp = ReadMpollData(pcode, cbtt);
                mp.RemoveMissing();
                if (mp.Count > 0)
                {
                    wyList.Add(mp);
                }

                // remove months outside selected range
                var list = FilterBySelectedRange(range, wyList);

                this.timeSeriesGraph1.AnalysisType = AnalysisType.WaterYears;
                this.timeSeriesGraph1.Series       = list;
                this.timeSeriesGraph1.Title        = HydrometInfoUtility.LookupSiteDescription(cbtt) + "  Elevation:" + HydrometInfoUtility.LookupElevation(cbtt);
                this.timeSeriesGraph1.Draw(true);


                timeSeriesGraph1.GraphSettings = GetGraphSettings();
            }
            finally
            {
                Cursor = Cursors.Default;
            }
        }
Beispiel #7
0
        private void buttonRefresh_Click(object sender, EventArgs e)
        {
            try
            {
                timeSeriesGraph1.AnnotationOnMouseMove = checkBoxAnnotate.Checked;
                timeSeriesGraph1.AnnotationDateShift   = !cySelected;
                Cursor = Cursors.WaitCursor;
                Application.DoEvents();
                string pcodeOrig = DeterminePcode();

                timeSeriesGraph1.Clear();

                string cbttOrig = comboBoxCbtt.Text.Trim();
                string cbtt = cbttOrig, pcode = pcodeOrig;

                var seriesList = new List <string>();
                if ((cbttOrig.Trim() == "" || pcodeOrig.Trim() == "") && textBoxMultiple.Text == "")
                {
                    return;
                }
                else
                {
                    if (!checkBoxUseList.Checked)
                    {
                        UserPreference.Save("Snowgg->cbtt", cbttOrig);
                        UserPreference.Save("Snowgg->pcode", comboBoxPcode.Text.Trim());
                        seriesList.Add(cbttOrig + "_" + pcodeOrig);
                    }
                    else
                    {
                        var seriesItems = textBoxMultiple.Text.Split(',');
                        foreach (string item in seriesItems)
                        {
                            if (item.Trim().Split(' ').Length == 2)
                            {
                                seriesList.Add(item.Trim().Split(' ')[0] + "_" + item.Trim().Split(' ')[1]);
                            }
                        }
                    }
                }

                int[]      waterYears            = this.yearSelector1.SelectedYears;
                SeriesList finalSeriesCollection = new SeriesList();
                foreach (string series in seriesList)
                {
                    cbtt = series.Split('_')[0];
                    comboBoxCbtt.Text  = cbtt;
                    pcode              = series.Split('_')[1];
                    comboBoxPcode.Text = pcode;
                    var server = HydrometInfoUtility.HydrometServerFromPreferences();
                    var range  = monthRangePicker1.MonthDayRange;

                    Series s;
                    if (this.checkBoxUseInstant.Checked)
                    {
                        s = new HydrometInstantSeries(cbtt, pcode, server);
                    }
                    else
                    {
                        s = new HydrometDailySeries(cbtt, pcode, server);
                    }
                    var sl = new SeriesList();
                    sl.Add(s);

                    // get wy data
                    var wyList = new SeriesList();
                    if (cySelected)
                    {
                        wyList = PiscesAnalysis.WaterYears(sl, waterYears, false, 1, true);
                    }
                    else
                    {
                        wyList = PiscesAnalysis.WaterYears(sl, waterYears, false, 10, true);
                    }

                    foreach (Series item in wyList)
                    {
                        item.Name = cbtt + " " + pcode;
                        // remove missing data points
                        var missingItems = item.Table.Select("value = 998877");
                        foreach (var row in missingItems)
                        {
                            item.RemoveAt(item.IndexOf(Convert.ToDateTime(row.ItemArray[0])));
                        }
                    }

                    // apply deltas and add stats if toggled
                    wyList = ApplyDeltas(wyList, waterYears);
                    AddStatistics(wyList);

                    if (checkBoxGP.Checked)
                    {
                        GPAverage(cbtt, server, range, wyList);
                    }

                    // remove months outside selected range
                    var list = FilterBySelectedRange(range, wyList);
                    finalSeriesCollection.Add(list);
                }

                // Set series line colors
                var uniqueSeriesNames  = new List <string>();
                var uniqueSeriesColors = new List <string>();
                int colorCounter       = 0;
                foreach (var item in finalSeriesCollection)
                {
                    // set line color by year which is identified in the legendtext field
                    if (!uniqueSeriesNames.Contains(item.Appearance.LegendText) && !item.Appearance.LegendText.Contains("%") &&
                        !item.Appearance.LegendText.Contains("avg") && !item.Appearance.LegendText.Contains("max") && !item.Appearance.LegendText.Contains("min"))
                    {
                        uniqueSeriesNames.Add(item.Appearance.LegendText);//.Name);
                        uniqueSeriesColors.Add(snowGgColors[colorCounter]);
                        colorCounter = (colorCounter + 1) % snowGgColors.Count;
                    }
                }
                foreach (var item in finalSeriesCollection)
                {
                    try
                    {
                        int colIdx = uniqueSeriesNames.IndexOf(item.Appearance.LegendText);//.Name);
                        item.Appearance.Color = uniqueSeriesColors[colIdx];
                    }
                    catch
                    {
                        item.Appearance.Color = "SlateGray"; //System.Drawing.KnownColor.SlateGray
                    }
                }

                this.timeSeriesGraph1.AnalysisType = AnalysisType.WaterYears;
                this.timeSeriesGraph1.Series       = finalSeriesCollection;
                if (seriesList.Count == 1)
                {
                    this.timeSeriesGraph1.Title = HydrometInfoUtility.LookupSiteDescription(cbtt) + "  Elevation:" + HydrometInfoUtility.LookupElevation(cbtt);
                }
                //timeSeriesGraph1.GraphSettings = GetGraphSettings();

                this.timeSeriesGraph1.Draw(true);

                comboBoxCbtt.Text  = cbttOrig;
                comboBoxPcode.Text = pcodeOrig;

                timeSeriesGraph1.GraphSettings = GetGraphSettings();
                this.dataGridView1.DataSource  = this.timeSeriesGraph1.Series.ToDataTable(true);
                this.dataGridView1.Columns[0].DefaultCellStyle.Format = "MMM-d";
                this.linkLabelReport.Visible = true;
            }
            finally
            {
                Cursor      = Cursors.Default;
                dataQueried = true;
            }
        }