public TestDeleteDatabaseProperties() { string path; if (LinuxUtility.IsLinux()) { path = "/tmp"; } else { path = "C:\\Temp\\"; } string fn = Path.Combine(path, "factory.pdb"); FileUtility.GetTempFileNameInDirectory(path, ".pdb"); SQLiteServer.CreateNewDatabase(fn); SQLiteServer svr = new SQLiteServer(fn); db = new TimeSeriesDatabase(svr, false); string dataPath = TestData.DataPath; Series s = new Series("Glomma River"); db.AddSeries(s); s = db.GetSeriesFromName("Glomma River"); s.TimeSeriesDatabase = db; s.Properties.Set("elevation", " 690 m"); s.Properties.Save(); }
public void ExportDatabase() { string path; if (LinuxUtility.IsLinux()) { path = "/tmp"; } else { path = "C:\\Temp\\"; } db.Export(Path.Combine(path, "export1")); }
//todo run command line function private static string[] RunExecutable(string exe, string args) { if (LinuxUtility.IsLinux()) { return(RunLocal(exe, args)); } else {// run remote var tokens = File.ReadAllLines(@"c:\utils\linux\dectalk.txt"); SshClient ssh = new SshClient("dectalk", tokens[0], tokens[1]); ssh.Connect(); var cmd = ssh.RunCommand(exe + " " + args); Console.WriteLine(cmd.Result); return(cmd.Result.Split('\n')); } }
public TimeSeriesDatabaseTest() { string path; if (LinuxUtility.IsLinux()) { path = "/tmp"; } else { path = "C:\\Temp\\"; } tmpDir = Path.Combine(path, "db_test"); if (!Directory.Exists(tmpDir)) { Directory.CreateDirectory(tmpDir); } string fn = Path.Combine(path, "factory.pdb"); FileUtility.GetTempFileNameInDirectory(path, ".pdb"); SQLiteServer.CreateNewDatabase(fn); SQLiteServer svr = new SQLiteServer(fn); db = new TimeSeriesDatabase(svr, false); //string dataPath = ReclamationTesting.Properties.Settings.Default.DataPath; string dataPath = TestData.DataPath; File.Copy(Path.Combine(dataPath, textFileName), Path.Combine(tmpDir, textFileName), true); textFileName = Path.Combine(tmpDir, textFileName); // Add some data for export test Series s; int c; int sdi; AddTextSeries(out s, out c, out sdi); }
internal static DateTime ConvertToMountainTime(DateTime utc) { DateTime mountain; if (LinuxUtility.IsLinux()) { TimeZoneInfo tzi = TimeZoneInfo.FindSystemTimeZoneById("US/Mountain"); Console.WriteLine("try ConvertTimeFromUtc"); mountain = TimeZoneInfo.ConvertTimeFromUtc(utc, tzi); //Console.WriteLine("try other way.."); //mountain = TimeZoneInfo.ConvertTimeBySystemTimeZoneId // (utc, "US/Mountain"); } else { mountain = TimeZoneInfo.ConvertTimeBySystemTimeZoneId (utc, "Mountain Standard Time"); } //Console.WriteLine("{0} (UTC) = {1} Mountain time", utc, mountain); return(mountain); }
public void AddBug() { string path; if (LinuxUtility.IsLinux()) { path = "/tmp"; } else { path = "C:\\Temp\\"; } DateTime t1 = new DateTime(2013, 1, 1); var t2 = t1.AddDays(365); var fn = FileUtility.GetTempFileNameInDirectory(path, ".pdb"); SQLiteServer svr = new SQLiteServer(fn); TimeSeriesDatabase db = new Reclamation.TimeSeries.TimeSeriesDatabase(svr, false); var s = new HydrometDailySeries("pal", "af"); s.Name = "pal_af"; s.Read(t1, t2); db.AddSeries(s); var cs = new CalculationSeries("add_test"); cs.Expression = "pal_af + pal_af"; db.AddSeries(cs); cs = db.GetSeriesFromName("add_test") as CalculationSeries; cs.Calculate(t1, t2); cs = db.GetSeriesFromName("add_test") as CalculationSeries; cs.Read(); Assert.IsTrue(cs.Count > 0); }
public static string GetOutgoingFileName(string prefix, string cbtt, string pcode, string route = "") { string outgoing = ConfigurationManager.AppSettings["outgoing"]; if (outgoing == "" || outgoing == null) { Console.WriteLine("Error: 'outgoing' directory not defined in config file"); Logger.WriteLine("Error: 'outgoing' directory not defined in config file"); // hack hack hack if (LinuxUtility.IsLinux()) { outgoing = "/tmp"; } else { outgoing = "C:\\Temp\\"; } } if (!Directory.Exists(outgoing) || outgoing == null) { Console.WriteLine("Error: path does not exist: '" + outgoing + "'"); } // route is subdirectory i.e. /home/hydromet/outgoing/route if (route != "") { outgoing = Path.Combine(outgoing, route); } if (!Directory.Exists(outgoing)) { Console.WriteLine("Error: Directoy does not exist " + outgoing); } return(Path.Combine(outgoing, GetUniqueFileName(outgoing, prefix, cbtt, pcode))); }
/// <summary> /// Path for incoming data files /// </summary> /// <returns></returns> static string GetIncommingFileName(string prefix, string cbtt, string pcode, string fileExtension) { string incoming = ConfigurationManager.AppSettings["incoming"]; if (incoming == "" || incoming == null) { Console.WriteLine("Error: 'incoming' directory not defined in config file"); Logger.WriteLine("Error: 'incoming' directory not defined in config file"); // hack hack hack // hack hack hack if (LinuxUtility.IsLinux()) { incoming = "/tmp"; } else { incoming = "C:\\Temp\\"; } } return(Path.Combine(incoming, TimeSeriesTransfer.GetUniqueFileName(incoming, prefix, cbtt, pcode, fileExtension))); }
static Series ParseXmlData(XPathDocument doc, string siteID, string inel_element, DateTime t) { Series s = new Series(); var nav = doc.CreateNavigator(); DateTime inlTime = t.Date; // used to increment each 5 minutes TimeZoneInfo mst; TimeZoneInfo mdt; if (LinuxUtility.IsLinux()) { //var c = TimeZoneInfo.GetSystemTimeZones(); //foreach (var item in c) //{ // Console.WriteLine(item); //} mst = TimeZoneInfo.FindSystemTimeZoneById("US/Arizona"); // no daylight shift mdt = TimeZoneInfo.FindSystemTimeZoneById("US/Mountain"); // with daylight shifting } else { mst = TimeZoneInfo.FindSystemTimeZoneById("US Mountain Standard Time"); // no daylight shift mdt = TimeZoneInfo.FindSystemTimeZoneById("Mountain Standard Time"); // with daylight shifting } string ts = ""; do { ts = inlTime.ToString("HH:mm"); var query = "mesonet/Time[@time=\"" + ts + "\"]/tower[@id=\"" + siteID + "\"]"; // /spd"; var nodeName = inel_element; var tag = ""; int idx = inel_element.IndexOf("."); if (idx > 0) { tag = inel_element.Substring(0, idx); query += "/" + tag; nodeName = inel_element.Substring(idx + 1); } var nodes = nav.Select(query); while (nodes.MoveNext()) { //Console.WriteLine(ts+ "id=" + nodes.Current.GetAttribute("id", "")); if (nodes.Current.HasChildren) { var children = nodes.Current.SelectChildren(XPathNodeType.All); while (children.MoveNext()) { var n = children.Current; if (n.LocalName == nodeName) { // Console.WriteLine(n.LocalName + " = " + n.Value); double val = 0; if (double.TryParse(n.Value, out val)) { //s.Add(t.Date.AddHours(time.Hour).AddMinutes(time.Minute), val, "inl"); DateTimeWithZone td = new DateTimeWithZone(inlTime, mst); DateTime hydrometDateTime; if (td.TryConvertToTimeZone(mdt, out hydrometDateTime)) { if (s.IndexOf(hydrometDateTime) < 0) {// in November time change, we have duplicate dates.. s.Add(hydrometDateTime, val, "inl"); } else { Console.WriteLine("skipping dateTime " + hydrometDateTime.ToString()); } } } } else if (n.LocalName == inel_element) { } } } } inlTime = inlTime.AddMinutes(5); } while (ts != "23:55"); Console.WriteLine("Read " + s.Count + " data points "); return(s); }