Пример #1
0
        void FetchNewForecasts(Station station, ForecastDataSource source, bool force = false)
        {
            if (!(force || source.IsNewDataReady(station)))
            {
                return;
            }

            Weather weather = null;

            try
            {
                weather = source.GetWeatherForecasts(station);
                OnFetchingSucceeded(station, source, weather.FetchedTime);
            }
            catch (ResponseParsingException e)
            {
                Trace.TraceError(String.Format("Response parsing error when fetching {0} forecast from {1}: {2}", station, source.Id, e.Message));
                OnFetchingFailed(station, source, "ответ сервера не разобран");
                failedCases.Add(new Tuple <ForecastDataSource, Station>(source, station));
            }
            catch (StationQueryNotFoundException e)
            {
                Trace.TraceError(String.Format("Station query not found for {0} in station {1}. {2}", source.Id, station, e.Message));
                OnFetchingFailed(station, source, "требуется строка запроса станции");
            }
            catch (NoLatLongException e)
            {
                Trace.TraceError(String.Format("Coordinates of {0} needed for {1}. {2}", station, source.Id, e.Message));
                OnFetchingFailed(station, source, "требуются координаты станции");
            }
            catch (NoStationOffsetException e)
            {
                Trace.TraceError(String.Format("UTC offset of {0} needed for {1}. {2}", station, source.Id, e.Message));
                OnFetchingFailed(station, source, "требуется часовой пояс станции");
            }

            if (weather != null)
            {
                ForecastsDatabase.Save(weather);
            }
            return;
        }
Пример #2
0
        public static Dictionary <string, PlotData> GetGroupedByParameterForecastPlots(ForecastViewerRequest request)
        {
            var result          = new Dictionary <string, PlotData>();
            var loadedForecasts = new Dictionary <IAbstractDataSource, IEnumerable <Forecast> >();

            foreach (var source in request.Sources)
            {
                loadedForecasts.Add(
                    source, ForecastsDatabase.Load(
                        request.Station,
                        source,
                        GetValidTimeDates(request.DateTime, request.GivenTime, source)));
            }

            int plotsKey = GeneratePlotGroupKey();

            foreach (var parameterType in request.ParameterTypes)
            {
                var sourceSeriesDict = GetSeriesBySourceDictionary(request, loadedForecasts, parameterType);
                result.Add(parameterType, new PlotData(plotsKey, parameterType, sourceSeriesDict));
            }

            return(result);
        }
Пример #3
0
        void FetchRealData(Station station, RealDataSource source, bool force = false)
        {
            if (!(force || !source.IsNewDataReady(station)))
            {
                return;
            }

            Weather weather = null;

            try
            {
                weather = source.GetWeatherReal(station);
                OnFetchingSucceeded(station, source, weather.FetchedTime);
            }
            catch (ResponseParsingException e)
            {
                Trace.TraceError(String.Format("Response parsing error when fetching {0} forecast from {1}: {2}", station, source.Id, e.Message));
                OnFetchingFailed(station, source, "ответ сервера не разобран");
            }
            catch (NoLatLongException e)
            {
                Trace.TraceError(String.Format("Coordinates of {0} needed for {1}. {2}", station, source.Id, e.Message));
                OnFetchingFailed(station, source, "требуются координаты станции");
            }
            catch (NoStationOffsetException e)
            {
                Trace.TraceError(String.Format("UTC offset of {0} needed for {1}. {2}", station, source.Id, e.Message));
                OnFetchingFailed(station, source, "требуется часовой пояс станции");
            }

            if (weather != null)
            {
                ForecastsDatabase.Save(weather);
            }
            return;
        }
Пример #4
0
        public static Dictionary <string, PlotData> GetGroupedByParameterAccuracyPlots(AccuracyRequest request)
        {
            var result          = new Dictionary <string, PlotData>();
            var loadedForecasts = new Dictionary <IAbstractDataSource, IEnumerable <Forecast> >();

            foreach (var source in request.Sources)
            {
                loadedForecasts.Add(
                    source, ForecastsDatabase.Load(
                        request.Station,
                        source,
                        GetValidTimeDates(request.Date, GivenForecastTimeKind.Valid, source)));
            }

            int plotsKey = GeneratePlotGroupKey();

            int      hours = request.AccuracyComparison == AccuracyComparison.HalfDay ? 12 : 24;
            DateTime date  = request.Date;

            var realSources = request.Sources.Where(s => s is RealDataSource).Cast <RealDataSource>();

            if (realSources.Count() == 0)
            {
                realSources = SourcesDirector.Instance.RealDataSources;
            }
            if (realSources.Count() == 0)
            {
                OnSelectingFailed("Не выбран источник реальных данных.");
                return(result);
            }
            RealDataSource realSource = realSources.First();

            try
            {
                foreach (var parameterType in request.ParameterTypes)
                {
                    var dict = (from source in request.Sources
                                where source is ForecastDataSource
                                where source.Parameters.Contains(parameterType)
                                let allSeries = from f in FilterForecastsForSingleDate(loadedForecasts[source], TimeSpan.FromHours(hours), date)
                                                select GetSeries(f.ToIEnumerable(), GivenForecastTimeKind.Created, parameterType, f.CreationTime)
                                                where allSeries.Count() > 0
                                                select new
                    {
                        Key = source,
                        Value = allSeries.MergeSeries()
                    }).ToDictionary(item => item.Key, item => item.Value);

                    var real = from f in loadedForecasts[realSource]
                               group f by GetForecastGroupingTime(f, GivenForecastTimeKind.Valid) into fByValidTime
                                   where IsSuitableDateTime(fByValidTime.Key, date, RequestTimeDeterminateness.AllDay)
                               select GetSeries(fByValidTime.ToList(), GivenForecastTimeKind.Created, parameterType, fByValidTime.Key);

                    dict.Add(realSource, real.MergeSeries());
                    result.Add(parameterType, new PlotData(plotsKey, parameterType, dict));
                }
            }
            catch (Exception e)
            {
                OnSelectingFailed(e.Message);
            }

            return(result);
        }