/// <summary>
        /// If Decodes software is installed locally
        /// DECODE raw data for a single parameter
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void AdvancedRawData_Click(object sender, EventArgs e)
        {
            // determine siteid (cbtt) and pcode

            SpreadsheetRange r = new SpreadsheetRange(wbView.RangeSelection);
            var col            = r.SelectedRangeColumnNames[0];

            var tokens = col.Trim().Split(' ');

            if (tokens.Length != 2)
            {
                return;
            }

            var cbtt  = tokens[0].ToLower();
            var pcode = tokens[1].ToLower();

            // find date range that is selected.
            var t = r.SelectedDateRange;
            // account for timezone offset and transmission time delay
            // summer UTC-6h
            // winter UTC-7h

            var t1 = t.DateTime1.AddHours(-24);
            var t2 = t.DateTime2.AddHours(+24);

            var svr = Database.GetServer("hydromet_opendcs");

            if (svr == null)
            {
                MessageBox.Show("Error connecting to the database.  Please check your password");
                return;
            }

            var fn  = FileUtility.GetSimpleTempFileName(".txt");
            var log = FileUtility.GetSimpleTempFileName(".txt");

            // run DECODES to create output file
            DecodesUtility.RunDecodesRoutingSpec(svr, "hydromet-tools", t1, t2, cbtt, fn, log);
            //Don't Go Karl!
            foreach (var item in File.ReadAllLines(log))
            {
                Logger.WriteLine(item);
            }

            foreach (var item in File.ReadAllLines(fn))
            {
                Logger.WriteLine(item);
            }



            TextFile tf = new TextFile(fn);

            if (!HydrometInstantSeries.IsValidDMS3(tf))
            {
                MessageBox.Show("Error reading Decodes output");
                return;
            }
            // Read Decodes output
            var sl = HydrometInstantSeries.HydrometDMS3DataToSeriesList(tf);
            // filter by cbtt and pcode
            var s = sl.Find(x => x.Table.TableName == "instant_" + cbtt + "_" + pcode);

            if (s == null)
            {
                Logger.WriteLine("Error: could not find decoded data for " + cbtt + "/" + pcode);
                return;
            }
            // use dataview for sorted data
            // filter by date range
            Series decoded = s.Clone();

            for (int i = 0; i < s.Count; i++)
            {
                var pt = s[i];
                if (pt.DateTime >= t.DateTime1 && pt.DateTime <= t.DateTime2)
                {
                    decoded.Add(pt);
                }
            }

            // put values into hydromet tools
            r.InsertSeriesValues(decoded);
        }
示例#2
0
        private void ProcessFile(RouteOptions routing, string fileName)
        {
            string importTag = "import"; // used to make friendly export filename

            try
            {
                TextFile   tf = new TextFile(fileName);
                SeriesList sl = new SeriesList();

                if (HydrometInstantSeries.IsValidDMS3(tf))
                {
                    importTag = "decodes";
                    sl        = HydrometInstantSeries.HydrometDMS3DataToSeriesList(tf);
                }
                else if (HydrometDailySeries.IsValidArchiveFile(tf))
                {
                    importTag = "htools";
                    sl        = HydrometDailySeries.HydrometDailyDataToSeriesList(tf);
                }
                else if (LoggerNetFile.IsValidFile(tf))
                {
                    LoggerNetFile lf = new LoggerNetFile(tf);

                    if (lf.IsValid && Array.IndexOf(validSites, lf.SiteName) >= 0)
                    {
                        importTag = lf.SiteName;
                        sl        = lf.ToSeries(validPcodes);
                    }
                }
                //else if (DecodesRawFile.IsValidFile(tf))
                //{
                //    DecodesRawFile df = new DecodesRawFile(tf);
                //    importTag = "raw";
                //    sl = df.ToSeries();
                //}
                else
                {
                    Logger.WriteLine("skipped Unknown File Format: " + fileName);
                    return;
                }

                m_importer = new TimeSeriesImporter(m_db, routing, m_saveOption);
                Console.WriteLine("Found " + sl.Count + " series in " + fileName);
                foreach (var item in sl)
                {
                    Logger.WriteLine(item.Table.TableName);
                }

                if (sl.Count > 0)
                {
                    m_importer.Import(sl, m_computeDependencies, m_computeDailyDependencies, importTag);
                    FileUtility.MoveToSubDirectory(Path.GetDirectoryName(fileName), "attic", fileName);
                }
            }
            catch (Exception ex)
            {
                Logger.WriteLine("Error:" + ex.Message);
                Console.WriteLine("Error:  skipping file, will move to error subdirectory " + fileName);
                FileUtility.MoveToSubDirectory(Path.GetDirectoryName(fileName), "error", fileName);
            }
        }
示例#3
0
        private void ProcessFile(string fileName)
        {
            Logger.WriteLine("ProcessFile('" + fileName + "')");
            string importTag = "import"; // used to make friendly export filename

            try
            {
                TextFile   tf = new TextFile(fileName);
                SeriesList sl = new SeriesList();

                if (HydrometInstantSeries.IsValidDMS3(tf))
                {
                    importTag = "decodes";
                    sl        = HydrometInstantSeries.HydrometDMS3DataToSeriesList(tf);
                }
                else if (HydrometDailySeries.IsValidArchiveFile(tf))
                {
                    importTag = "htools";
                    sl        = HydrometDailySeries.HydrometDailyDataToSeriesList(tf);
                }
                else if (LoggerNetFile.IsValidFile(tf))
                {
                    LoggerNetFile lf = new LoggerNetFile(tf);

                    if (lf.IsValid && Array.IndexOf(validSites, lf.SiteName) >= 0)
                    {
                        importTag = lf.SiteName;
                        sl        = lf.ToSeries(validPcodes);
                    }
                }
                else if (CsvScadaFile.IsValidFile(tf))
                {
                    importTag = "scada";
                    m_db.GetSiteCatalog();
                    var scada = new CsvScadaFile(fileName);
                    sl = scada.ToSeries();
                }
                else if (XConnectTextFile.IsValidFile(tf))
                {
                    importTag = "xc";
                    var xc = new XConnectTextFile(tf);
                    sl = xc.ToSeries();
                }
                else if (HydrometMonthlySeries.IsValidFile(tf))
                {
                    sl = HydrometMonthlySeries.FileToSeriesList(tf);
                }
                else
                {
                    Logger.WriteLine("skipped Unknown File Format: " + fileName);
                    return;
                }

                if (m_importer == null)
                {
                    m_importer = new TimeSeriesImporter(m_db, m_saveOption);
                }
                Console.WriteLine("Found " + sl.Count + " series in " + fileName);
                foreach (var item in sl)
                {
                    Logger.WriteLine(item.Table.TableName);
                }

                if (sl.Count > 0)
                {
                    m_importer.Import(sl, m_computeDependencies, m_computeDailyDependencies, importTag);
                    FileUtility.MoveToSubDirectory(Path.GetDirectoryName(fileName), "attic", fileName);
                }
            }
            catch (Exception ex)
            {
                Logger.WriteLine("Error:" + ex.Message);
                Console.WriteLine("Error:  skipping file, will move to error subdirectory " + fileName);
                FileUtility.MoveToSubDirectory(Path.GetDirectoryName(fileName), "error", fileName);
            }
        }