Exemplo n.º 1
0
 public Task <Either <ActionResult, SubjectMetaViewModel> > GetSubjectMetaRestricted(
     SubjectMetaQueryContext query)
 {
     return(_persistenceHelper.CheckEntityExists <Subject>(query.SubjectId)
            .OnSuccess(CheckCanViewSubjectData)
            .OnSuccess(subject => GetSubjectMetaViewModelFromQuery(query)));
 }
        private async Task <Either <ActionResult, TableBuilderResultViewModel> > Query(
            Release release,
            ObservationQueryContext queryContext)
        {
            return(await _statisticsPersistenceHelper.CheckEntityExists <Subject>(queryContext.SubjectId)
                   .OnSuccessDo(CheckCanViewSubjectData)
                   .OnSuccess(async() =>
            {
                var observations = GetObservations(queryContext).AsQueryable();

                if (!observations.Any())
                {
                    return new TableBuilderResultViewModel();
                }

                return await _resultSubjectMetaService
                .GetSubjectMeta(release.Id, SubjectMetaQueryContext.FromObservationQueryContext(queryContext), observations)
                .OnSuccess(subjectMetaViewModel =>
                {
                    return new TableBuilderResultViewModel
                    {
                        SubjectMeta = subjectMetaViewModel,
                        Results = observations.Select(observation =>
                                                      _resultBuilder.BuildResult(observation, queryContext.Indicators))
                    };
                });
            }));
        }
 private IEnumerable <FootnoteViewModel> GetFilteredFootnotes(Guid releaseId, IQueryable <Observation> observations,
                                                              SubjectMetaQueryContext queryContext)
 {
     return(_footnoteRepository.GetFilteredFootnotes(releaseId, queryContext.SubjectId, observations, queryContext.Indicators)
            .Select(footnote => new FootnoteViewModel
     {
         Id = footnote.Id,
         Label = footnote.Content
     }));
 }
Exemplo n.º 4
0
 public IEnumerable <Observation> FindObservations(SubjectMetaQueryContext query)
 {
     return(DbSet()
            .AsNoTracking()
            .Include(observation => observation.FilterItems)
            .ThenInclude(filterItem => filterItem.FilterItem)
            .ThenInclude(filterItem => filterItem.FilterGroup)
            .ThenInclude(filterGroup => filterGroup.Filter)
            .Where(ObservationPredicateBuilder.Build(query)));
 }
Exemplo n.º 5
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
            });
        }
        public Task <Either <ActionResult, ResultSubjectMetaViewModel> > GetSubjectMeta(Guid releaseId,
                                                                                        SubjectMetaQueryContext query, IQueryable <Observation> observations)
        {
            return(_persistenceHelper.CheckEntityExists <Subject>(query.SubjectId)
                   .OnSuccess(CheckCanViewSubjectData)
                   .OnSuccess(async subject =>
            {
                var stopwatch = Stopwatch.StartNew();
                stopwatch.Start();

                var observationalUnits = _locationService.GetObservationalUnits(observations);
                _logger.LogTrace("Got Observational Units in {Time} ms", stopwatch.Elapsed.TotalMilliseconds);
                stopwatch.Restart();

                var filters = GetFilters(query.SubjectId, observations, true);
                _logger.LogTrace("Got Filters in {Time} ms", stopwatch.Elapsed.TotalMilliseconds);
                stopwatch.Restart();

                var footnotes = GetFilteredFootnotes(releaseId, observations, query);
                _logger.LogTrace("Got Footnotes in {Time} ms", stopwatch.Elapsed.TotalMilliseconds);
                stopwatch.Restart();

                var geoJsonAvailable = HasBoundaryLevelDataForAnyObservationalUnits(observationalUnits);
                _logger.LogTrace("Got GeoJsonAvailable in {Time} ms", stopwatch.Elapsed.TotalMilliseconds);
                stopwatch.Restart();

                var boundaryLevels = GetBoundaryLevelOptions(query.BoundaryLevel, observationalUnits.Keys);

                var indicators = GetIndicators(query);
                _logger.LogTrace("Got Indicators in {Time} ms", stopwatch.Elapsed.TotalMilliseconds);
                stopwatch.Restart();

                var locations = GetGeoJsonObservationalUnits(observationalUnits, query.IncludeGeoJson ?? false,
                                                             query.BoundaryLevel);
                _logger.LogTrace("Got Observational Units in {Time} ms", stopwatch.Elapsed.TotalMilliseconds);
                stopwatch.Restart();

                var timePeriodRange = GetTimePeriodRange(observations);
                _logger.LogTrace("Got Time Periods in {Time} ms", stopwatch.Elapsed.TotalMilliseconds);
                stopwatch.Stop();

                var publication = await _subjectService.GetPublicationForSubject(subject.Id);

                return new ResultSubjectMetaViewModel
                {
                    Filters = filters,
                    Footnotes = footnotes,
                    GeoJsonAvailable = geoJsonAvailable,
                    Indicators = indicators,
                    Locations = locations,
                    BoundaryLevels = boundaryLevels,
                    PublicationName = publication.Title,
                    SubjectName = subject.Name,
                    TimePeriodRange = timePeriodRange
                };
            }));
        }
        private IEnumerable <IndicatorMetaViewModel> GetIndicators(SubjectMetaQueryContext query)
        {
            var indicators = _indicatorService.GetIndicators(query.SubjectId, query.Indicators);

            return(BuildIndicatorViewModels(indicators));
        }
 public Task <ActionResult <SubjectMetaViewModel> > GetSubjectMetaAsync(
     [FromBody] SubjectMetaQueryContext query)
 {
     return(_subjectMetaService.GetSubjectMeta(query).HandleFailuresOrOk());
 }