Exemplo n.º 1
0
        private SubjectMetaViewModel GetSubjectMetaViewModelFromQuery(SubjectMetaQueryContext query)
        {
            var observations = _observationService.FindObservations(query).AsQueryable();
            var locations    = new Dictionary <string, ObservationalUnitsMetaViewModel>();
            var timePeriods  = new TimePeriodsMetaViewModel();
            var filters      = new Dictionary <string, FilterMetaViewModel>();
            var indicators   = new Dictionary <string, IndicatorsMetaViewModel>();

            var stopwatch = Stopwatch.StartNew();

            stopwatch.Start();

            if (query.Locations == null)
            {
                locations = GetObservationalUnits(observations);

                _logger.LogTrace("Got Observational Units in {Time} ms", stopwatch.Elapsed.TotalMilliseconds);
                stopwatch.Restart();
            }

            if (query.TimePeriod == null && query.Locations != null)
            {
                timePeriods = GetTimePeriods(observations);

                _logger.LogTrace("Got Time Periods in {Time} ms", stopwatch.Elapsed.TotalMilliseconds);
                stopwatch.Restart();
            }

            if (query.TimePeriod != null)
            {
                filters = GetFilters(query.SubjectId, observations, false);

                _logger.LogTrace("Got Filters in {Time} ms", stopwatch.Elapsed.TotalMilliseconds);
                stopwatch.Restart();

                indicators = GetIndicators(query.SubjectId);

                _logger.LogTrace("Got Indicators in {Time} ms", stopwatch.Elapsed.TotalMilliseconds);
            }

            stopwatch.Stop();

            // Only data relevant to the step being executed in the table tool needs to be returned hence the
            // null checks above so only the minimum requisite DB calls for the task are performed.
            return(new SubjectMetaViewModel
            {
                Filters = filters,
                Indicators = indicators,
                Locations = locations,
                TimePeriod = timePeriods
            });
        }
 private IEnumerable <Observation> GetObservations(ObservationQueryContext queryContext)
 {
     return(_observationService.FindObservations(queryContext));
 }