示例#1
0
        /// <summary>
        /// Loads the observations from the Text File
        /// </summary>
        /// <param name="stationId"></param>
        /// <param name="ch"></param>
        /// <param name="start"></param>
        /// <param name="end"></param>
        /// <param name="observations"></param>
        /// <returns></returns>
        public int LoadObservationsFromFile(int stationId, Channel ch, DateTime start, DateTime end,
            IObservationList observations)
        {
            int channelId = ch.ChId;

            observations.Clear();

            List<Channel> oneChannel = new List<Channel> { ch };

            ChmiFile dta = new ChmiFile(stationId , oneChannel, LocalDataDir);
            List<Observation> rawData = dta.Read();

            foreach (Observation obs in rawData)
            {
                if (obs.Time >= start && obs.Time <= end)
                {
                    observations.AddObservation(obs.Time, obs.Value);
                }
            }

            return 0;
        }
示例#2
0
        public void ImportAll()
        {
            //check stationXmlFile
            StationXmlFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "stanice.xml");
            logFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "log.txt");
            LocalDataDir = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "data");
            if (!Directory.Exists(LocalDataDir))
                Directory.CreateDirectory(LocalDataDir);

            if (!File.Exists(StationXmlFile))
            {
                Logger.WriteMessage(logFile, "Couldn't find file " + StationXmlFile);
                return;
            }

            SetGraphDirFromXmlFile();

            StringBuilder log = new StringBuilder();
            DateTime start = DateTime.Now;
            log.AppendLine(start.ToString() + @" Start import data from Fiedler..\n");
            try
            {
                Downloader d = new Downloader(LocalDataDir, DownloadInterval);
                //int numStations = 0;
                int numStations = d.DownloadAll(StationXmlFile, log, "CHMI_1");
                //also for testing: download the DTA files
                d.DownloadAll(StationXmlFile, log, "DTA");
                log.AppendLine("Files downloaded: " + numStations);
                DataManager m = DataManager.Create(ConnectionString);
                m.CheckAllStations(StationXmlFile);
                m.CheckAllChannels(StationXmlFile);
                List<Station> stations = Station.ReadListOfStations(StationXmlFile);
                List<Channel> channels = Channel.ReadFromXml(StationXmlFile);
                List<Channel> stChannels;
                List<Observation> observations;
                ChmiFile dta;
                int added = 0;
                foreach (Station st in stations)
                {
                    stChannels = Channel.FindByStation(channels, st.Id);
                    dta = new ChmiFile(st.Id, channels, LocalDataDir);
                    observations = dta.Read();
                    added += m.AddObservations(observations, stChannels, log);
                }
                log.AppendLine("observations added: " + added + "Time taken: " +
                    ((TimeSpan)(DateTime.Now.Subtract(start))).TotalSeconds + @" s.");
            }
            catch (Exception ex)
            {
                log.AppendLine("UNKNOWN ERROR at " + ex.Source);
                log.AppendLine(ex.Message);
            }
            finally
            {
                Logger logger = new Logger(logFile);
                logger.WriteMessage(log.ToString());
            }
        }