public SeriesList ToSeries() { seriesDict.Clear(); for (int i = 0; i < tf.Length; i++) { var msg = GoesMessageDataSet.ParseMessage(tf[i]); if (msg != null) { var cbttList = SiteLookupMultiple("NESSID", msg.nessid, "SITE"); if (cbttList.Length == 0) { Logger.WriteLine("Warning: no cbtt found for " + msg.nessid + " skipping this messages"); continue; } for (int c = 0; c < cbttList.Length; c++) { string cbtt = cbttList[c]; int expectedLength = Convert.ToInt32(SiteLookup("NESSID", msg.nessid, "SMSGLEN")); int lenerr = msg.length - expectedLength; var reptime = Convert.ToInt32(SiteLookup("NESSID", msg.nessid, "REPTIM")); var primaryChannel = SiteLookup("NESSID", msg.nessid, "PCHAN"); var expectedSeconds = msg.MST.Hour * 3600 + reptime; //DateTime midnight = new DateTime(msg.MST.Year,msg.MST.Month,msg.MST.Day,0,0,0); TimeSpan ts = new TimeSpan(msg.MST.Hour, msg.MST.Minute, msg.MST.Second); var timeerr = ts.TotalSeconds - expectedSeconds; int parity = 0; if (msg.failure == "?") { parity = 1; } Add(cbtt, "PARITY", msg.MST, parity); Add(cbtt, "POWER", msg.MST, Convert.ToDouble(msg.power)); Add(cbtt, "MSGLEN", msg.MST, msg.length); if (msg.channel != primaryChannel) { continue; } Add(cbtt, "LENERR", msg.MST, lenerr); Add(cbtt, "TIMEERR", msg.MST, timeerr); } } } SeriesList rval = new SeriesList(); rval.AddRange(seriesDict.Values); return(rval); }
public SeriesList ToSeries(string[] valid_pcodes) { foreach (var pcode in dataHeader) { int idx = Array.IndexOf(dataHeader, pcode); if (idx >= 0 && Array.IndexOf(valid_pcodes, pcode) >= 0) { string key = "instant_" + SiteName.ToLower() + "_" + pcode.ToLower(); Series s = new Series(); if (dict.ContainsKey(key)) { s = dict[key]; } else { s.Name = key; s.Parameter = pcode; s.Table.TableName = key; s.SiteID = SiteName; dict.Add(key, s); } for (int i = 2; i < tf.Length; i++) { var tokens = tf[i].Replace("\"", "").Split(','); double d = 0; DateTime t; if (DateTime.TryParse(tokens[0], out t) && double.TryParse(tokens[idx], out d)) { if (s.IndexOf(t) >= 0) { Logger.WriteLine("LoggerNetFile: skipping duplicate point "); } else { s.Add(t, d); } } else { Logger.WriteLine("LoggerNetFile: Skipping line " + tf[i]); } } Logger.WriteLine("LoggerNetFile.ToSeries(): " + key + " has " + s.Count + " items"); } } SeriesList sl = new SeriesList(); sl.AddRange(dict.Values.ToArray()); return(sl); // Logger.WriteLine("Found " + rval.Count + " parameters in " + tf.FileName); }
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 static Series SumSetMissingToZero(Series[] items) { var rval = new Series(); if (items.Length > 0) rval = items[0].Copy(); SeriesList list = new SeriesList(); list.AddRange(items); rval = Math.FillMissingWithZero(rval, list.MinDateTime, list.MaxDateTime); for (int i = 1; i < items.Length; i++) { rval = rval + Math.FillMissingWithZero(items[i], list.MinDateTime, list.MaxDateTime); } return rval; }
public SeriesList ToSeries() { // match gate or level status// matches gv1, gv2,... lv1, lv2,... Regex reColumns = new Regex("^(g|l)v[1-6]{1}$", RegexOptions.Compiled); // match valid site names (site01,site02, ) Regex reSites = new Regex("^(site)[0-9]{1,3}$"); for (int i = 0; i < csv.Rows.Count; i++) { var row = csv.Rows[i]; //sitename,tmstp,gv1,gs1,gv2,gs2,gv3,gs3,gv4,gs4,gv5,gs5,gv6,gs6,lv1,ls1,lv2,ls2,lv3,ls3,lv4,ls4,lv5,ls5,lv6,ls6,sv,ss string siteid = row["sitename"].ToString().ToLower().Replace("'", ""); string timestamp = row["tmstp"].ToString().Replace("'", ""); if (!reSites.IsMatch(siteid)) { continue; } DateTime t; if (!DateTime.TryParse(timestamp, out t)) { continue; } for (int j = 2; j < csv.Columns.Count; j++) { string pcode = csv.Columns[j].ToString().ToLower(); if (!reColumns.IsMatch(pcode)) { continue; } string val = row[j].ToString(); double dval; if (!double.TryParse(val, out dval)) { continue; } var key = "instant_" + siteid + "_" + pcode.ToLower(); Series s = new Series(); if (dict.ContainsKey(key)) { s = dict[key]; } else { s.Name = siteid + "_" + pcode; s.Parameter = pcode; s.Table.TableName = key; s.SiteID = siteid; dict.Add(key, s); } if (s.IndexOf(t) >= 0) { Logger.WriteLine("skipping duplicate point " + s.Name + " " + timestamp + " " + val); } else { s.Add(t, dval); } } } SeriesList sl = new SeriesList(); sl.AddRange(dict.Values.ToArray()); return(sl); }