public void Add(string[] cbttPcodeList, DateTime t1, DateTime t2, HydrometHost svr = HydrometHost.PNLinux, TimeInterval interval = TimeInterval.Monthly, int back = 0) { // make cbttPcodeList unique. List <string> lst = new List <string>(cbttPcodeList); cbttPcodeList = lst.Distinct().ToArray(); //minT = t1; //maxT = t2; m_interval = interval; string query = String.Join(",", cbttPcodeList); if (query.Length > 0) { DataTable m_table = new DataTable(); if (interval == TimeInterval.Monthly && svr != HydrometHost.GreatPlains) { m_table = HydrometDataUtility.MPollTable(svr, query, t1, t2); } else if (interval == TimeInterval.Daily) { m_table = HydrometDataUtility.ArchiveTable(svr, query, t1, t2, back); } else if (interval == TimeInterval.Irregular) { m_table = HydrometDataUtility.DayFilesTable(svr, query, t1, t2, back); } m_table.ExtendedProperties.Add("interval", interval.ToString()); s_counter++; m_table.TableName = svr.ToString() + "_" + interval.ToString() + s_counter; m_dataSet.Tables.Add(m_table); } }
public static HydrometDataCache Cache; // in-memory cache used for forecasting // public bool FromCache = false; private void ReadMpollFromHydromet(DateTime t1, DateTime t2) { string key = m_cbtt + " " + m_pcode; int tableIndex = -1; if (Cache != null && (tableIndex = Cache.TableIndex(key, TimeSeries.TimeInterval.Monthly, t1, t2)) >= 0) { int idx = Cache.DataSet.Tables[tableIndex].Columns.IndexOf(key); if (idx < 0) { throw new Exception("oops"); } //Console.WriteLine("Cache hit for: " + key); ReadFromTable(Cache.DataSet.Tables[tableIndex], idx, idx + 1, t1, t2); if (ConvertToAcreFeet) { ConvertFromThousandAcreFeetToAcreFeet(this); } // FromCache = true; } else { var tbl = HydrometDataUtility.MPollTable(this.server, key, t1, t2); ReadFromTable(tbl, 1, 2, t1, t2); if (ConvertToAcreFeet) { ConvertFromThousandAcreFeetToAcreFeet(this); } } }
/// <summary> /// Inserts a constant value many times into dayfiles /// </summary> /// <param name="user"></param> /// <param name="password"></param> /// <param name="t1">starting date/time</param> /// <param name="t2">ending date/time</param> /// <param name="value">value to insert</param> /// <param name="increment">minutes between values</param> /// <returns></returns> public static string InsertDayFileValue(string user, string password, DateTime t1, DateTime t2, string cbtt, string pcode, double value, int increment) { DateTime t = t1; if (t2 < t1) { return("Error dates out of order"); } TimeSpan ts = new TimeSpan(t2.Ticks - t1.Ticks); if (ts.Days > 365) { if (System.Windows.Forms.MessageBox.Show("Warning. A large amount of data will be inserted. Is this OK?", "Continue?", System.Windows.Forms.MessageBoxButtons.OKCancel) != System.Windows.Forms.DialogResult.OK) { return("inserting data was canceled"); } } string fn = FileUtility.GetTempFileName(".txt"); StreamWriter output = new StreamWriter(fn); output.WriteLine("yyyyMMMdd hhmm cbtt PC NewValue OldValue Flag User:"******"-03";// manually entered data double missing = 998877.0; string str = t.ToString("yyyyMMMdd HHmm").ToUpper() + " " + cbtt.ToUpper().PadRight(8) + " " + pcode.ToUpper().Trim().PadRight(9) + " " + value.ToString("F2").PadRight(10) + " " + missing.ToString("F2").PadRight(10) + " " + flagCode.ToString().PadRight(3); output.WriteLine(str); t = t.AddMinutes(increment); } while (t <= t2); output.Close(); string remoteFilename = HydrometDataUtility.CreateRemoteFileName(user, TimeInterval.Irregular); return(SaveInstantData(user, password, fn, remoteFilename)); }
// Dayfile update file public static int WriteDayfileUpdateFile(DataTable tblNew, DataTable tblOld, string outputFilename, out string[] arcCommandList, out string[] modifiedParameters, out string[] modifiedCbtt, out DateRange range) { range = new DateRange(); DateTime t1 = DateTime.MaxValue; DateTime t2 = DateTime.MinValue; var arcCommands = new List <string>(); var modParameterList = new List <string>(); var modcbtt = new List <string>(); arcCommandList = arcCommands.ToArray(); modifiedCbtt = modcbtt.ToArray(); modifiedParameters = modParameterList.ToArray(); if (tblNew.Rows.Count != tblOld.Rows.Count) { Logger.WriteLine("Error: the number of rows in the data has changed. no update file will be written"); return(0); } if (tblNew.Columns.Count != tblOld.Columns.Count) { Logger.WriteLine("Error: the number of columns in the data has changed. no update file will be written"); return(0); } StreamWriter output = new StreamWriter(outputFilename); int modifiedCounter = 0; // first column is date, other columns are values output.WriteLine("yyyyMMMdd hhmm cbtt PC NewValue OldValue Flag user:"******"-00"; for (int r = 0; r < tblOld.Rows.Count; r++) { double valNew = HydrometDataUtility.ReadDouble(tblNew.Rows[r][c]); double valOld = HydrometDataUtility.ReadDouble(tblOld.Rows[r][c]); string newFlag = HydrometDataUtility.ReadFlag(tblNew.Rows[r][c + 1]); string oldFlag = HydrometDataUtility.ReadFlag(tblOld.Rows[r][c + 1]); if (valNew != valOld || newFlag != oldFlag) { // something changed. write to script. DateTime date = (DateTime)tblNew.Rows[r][0]; UpdateDateRange(ref t1, ref t2, modifiedCounter, date); UpdateDayfileDependencies(modcbtt, arcCommands, modParameterList, stationName, pcode, date); flagCode = FlagCode(newFlag); System.Globalization.NumberFormatInfo nf = new System.Globalization.NumberFormatInfo(); nf.NumberDecimalDigits = 2; string str = date.ToString("yyyyMMMdd HHmm").ToUpper() + " " + stationName.Trim().PadRight(8) + " " + pcode.Trim().PadRight(9) + " " + FortranFormat(valNew) + " " + FortranFormat(valOld) + " " + flagCode.ToString().PadRight(3); output.WriteLine(str); modifiedCounter++; } } } output.Close(); range = new DateRange(t1, t2); arcCommandList = arcCommands.ToArray(); modifiedParameters = modParameterList.ToArray(); modifiedCbtt = modcbtt.ToArray(); return(modifiedCounter); }