Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
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);
        }