예제 #1
0
        public static IEnumerable <Forecast> Load(Station station, IAbstractDataSource source, IEnumerable <DateTime> validTimeDates)
        {
            IEnumerable <Forecast> result = new List <Forecast>();

            if (IsSourceDatabaseExists(source, station))
            {
                List <string> patterns = validTimeDates.Select(dt => GetChunkStartMarker(dt)).ToList();

                MemoryStream ms   = null;
                string       path = GetSourceFilename(source, station);
                try
                {
                    ActualizeCache(path);
                    ms = new MemoryStream(cache[path]);
                    using (var sr = new StreamReader(ms))
                    {
                        result = (ReadAllChunksOfPatterns(sr, patterns));
                    }
                }
                catch (Exception e)
                {
                    Trace.TraceError("Loading forecast {0}: {1}", path, e.Message);
                    OnLoadingFailed(station, source, validTimeDates, e.Message);
                }
                finally
                {
                    if (ms != null)
                    {
                        ms.Dispose();
                    }
                }
            }

            return(result);
        }
예제 #2
0
 public LoadingFailedEventArgs(Station station, IAbstractDataSource source, IEnumerable <DateTime> dates, string message)
 {
     this.station = station;
     this.source  = source;
     this.message = message;
     this.dates   = dates;
 }
예제 #3
0
파일: Weather.cs 프로젝트: sm-g/weatherlog
 public Weather(Station station, IAbstractDataSource source, IEnumerable <Forecast> forecasts)
 {
     Station     = station;
     Source      = source;
     Forecasts   = forecasts;
     FetchedTime = DateTime.Now;
 }
예제 #4
0
파일: Colors.cs 프로젝트: sm-g/weatherlog
        public static OxyColor OxyColor(this IAbstractDataSource source)
        {
            OxyColor res;

            if (colorsBySource.TryGetValue(source.Id, out res))
            {
                return(res);
            }
            return(OxyPlot.OxyColor.FromRgb(1, 1, 1));
        }
예제 #5
0
파일: Fetcher.cs 프로젝트: sm-g/weatherlog
        private void OnFetchingSucceeded(Station station, IAbstractDataSource source, DateTime fetchedTime)
        {
            EventHandler <FetchingSucceededEventArgs> handler = this.FetchingSucceeded;

            if (handler != null)
            {
                handler(this, new FetchingSucceededEventArgs(station, source, fetchedTime));
            }
            Interlocked.Increment(ref fetchingsSucceed);
        }
예제 #6
0
파일: Fetcher.cs 프로젝트: sm-g/weatherlog
        private void OnFetchingFailed(Station station, IAbstractDataSource source, string message)
        {
            EventHandler <FetchingFailedEventArgs> handler = this.FetchingFailed;

            if (handler != null)
            {
                handler(this, new FetchingFailedEventArgs(station, source, message));
            }
            Interlocked.Increment(ref fetchingsFailed);
        }
예제 #7
0
        public DateTime GetStationLastFetchTime(IAbstractDataSource source, Station station)
        {
            Dictionary <string, DateTime> sourceTimes;

            if (!_lastFetchTimes.TryGetValue(station.Id, out sourceTimes))
            {
                sourceTimes = SourcesDatabase.LoadLastFetchTimes(station);
                if (sourceTimes.Count == 0)
                {
                    return(DateTime.MinValue);
                }
                else
                {
                    _lastFetchTimes[station.Id] = sourceTimes;
                }
            }
            return(sourceTimes[source.Id]);
        }
예제 #8
0
        private void AddDataSeries(ParameterTimeSeries data, IAbstractDataSource source, OxyColor color)
        {
            string timeRelation = GetRelationPreposition(data.GroupingTimeKind, true);
            var    lineSerie    = new LineSeries
            {
                StrokeThickness             = 2,
                Color                       = color,
                MarkerType                  = MarkerType.Circle,
                MarkerSize                  = 4,
                MarkerFill                  = color,
                CanTrackerInterpolatePoints = false,
                TrackerFormatString         = source.Name + "\r\n{0}\r\n{1} {2:" + targetDateTimeFormat + "}\r\n{3}: {4} " + ParametersFactory.GetUnit(data.Type),
                Title                       = string.Format("{0} {1} {2:" + (source is ForecastDataSource ? groupingDateTimeFormat : groupingDateFormat) + "}", data.Length, timeRelation, data.GroupingTime),
                Smooth                      = false,
            };

            for (int i = 0; i < data.Length; i++)
            {
                lineSerie.Points.Add(new DataPoint(DateTimeAxis.ToDouble(data.TargetTimes[i]), data.RealValues[i]));
            }
            PlotModel.Series.Add(lineSerie);
        }
예제 #9
0
 private static void OnLoadingFailed(Station station, IAbstractDataSource source, IEnumerable <DateTime> dates, string message)
 {
     LoadingFailed(null, new LoadingFailedEventArgs(station, source, dates, message));
 }
예제 #10
0
 private static void OnSavingFailed(Station station, IAbstractDataSource source, string message)
 {
     SavingFailed(null, new SavingFailedEventArgs(station, source, message));
 }
예제 #11
0
 private static string GetSourceFilename(IAbstractDataSource source, Station station)
 {
     return(StationsDatabase.GetStationDir(station) + source.Id + filesExtension);
 }
예제 #12
0
 private static bool IsSourceDatabaseExists(IAbstractDataSource source, Station station)
 {
     return(new FileInfo(GetSourceFilename(source, station)).Exists);
 }
예제 #13
0
 public SavingFailedEventArgs(Station station, IAbstractDataSource source, string message)
 {
     this.station = station;
     this.source  = source;
     this.message = message;
 }
 public LastFetchTimeChangedEventArgs(IAbstractDataSource source, Station station)
 {
     this.station = station;
     this.source  = source;
 }
예제 #15
0
 public FetchingSucceededEventArgs(Station station, IAbstractDataSource source, DateTime time)
 {
     this.station = station;
     this.source  = source;
     this.time    = time;
 }
예제 #16
0
        private static DateTime[] GetValidTimeDates(DateTime date, GivenForecastTimeKind mode, IAbstractDataSource source)
        {
            DateTime[] validTimeDates = null;

            if (mode == GivenForecastTimeKind.Valid || source is RealDataSource)
            {
                validTimeDates = new DateTime[1] {
                    date
                };
            }
            else if (mode == GivenForecastTimeKind.Created)
            {
                int daysForward = (int)Math.Ceiling(((ForecastDataSource)source).PredictionDepth.TotalDays);
                validTimeDates = new DateTime[daysForward];
                for (int i = 0; i < daysForward; i++)
                {
                    validTimeDates[i] = date.AddDays(i);
                }
            }
            else
            {
                throw new ArgumentOutOfRangeException("mode", "Unknown kind of given forecast time.");
            }

            return(validTimeDates);
        }