public async Task <IEnumerable <Document> > GetSchoolDataDocumentAsync(string urn, string term, SchoolFinancialType schoolFinancialType, CentralFinancingType cFinance)
        {
            var dataGroup = schoolFinancialType.ToString();

            if (schoolFinancialType == SchoolFinancialType.Academies)
            {
                dataGroup = (cFinance == CentralFinancingType.Include) ? DataGroups.MATDistributed : DataGroups.Academies;
            }

            var collectionName = _dataCollectionManager.GetCollectionIdByTermByDataGroup(term, dataGroup);

            try
            {
                var query =
                    _client.CreateDocumentQuery <Document>(
                        UriFactory.CreateDocumentCollectionUri(DatabaseId, collectionName),
                        $"SELECT * FROM c WHERE c.URN={urn}");

                return(await query.QueryAsync());
            }
            catch (Exception)
            {
                return(null);
            }
        }
        public Document GetSchoolDataDocument(string urn, string term, SchoolFinancialType schoolFinancialType, CentralFinancingType cFinance)
        {
            var dataGroup = schoolFinancialType.ToString();

            if (schoolFinancialType == SchoolFinancialType.Academies)
            {
                dataGroup = (cFinance == CentralFinancingType.Include) ? DataGroups.MATDistributed : DataGroups.Academies;
            }

            var collectionName = _dataCollectionManager.GetCollectionIdByTermByDataGroup(term, dataGroup);

            if (collectionName == null)
            {
                return(null);
            }

            try
            {
                var query =
                    _client.CreateDocumentQuery <Document>(
                        UriFactory.CreateDocumentCollectionUri(DatabaseId, collectionName),
                        $"SELECT * FROM c WHERE c.URN={urn}");

                var result = query.ToList().FirstOrDefault();

                if (dataGroup == DataGroups.MATDistributed && result == null)//if nothing found in -Distributed collection try to source it from Academies data
                {
                    return(GetSchoolDataDocument(urn, term, schoolFinancialType, CentralFinancingType.Exclude));
                }

                if (result != null && result.GetPropertyValue <bool>("DNS"))//School did not submit finance, return & display none in the charts
                {
                    return(null);
                }

                return(result);
            }
            catch (Exception)
            {
                return(null);
            }
        }
        private async Task <List <SchoolFinancialDataModel> > GetFinancialDataHistoricallyAsync(string urn, SchoolFinancialType schoolFinancialType, CentralFinancingType cFinance)
        {
            var models     = new List <SchoolFinancialDataModel>();
            var latestYear = _financialDataService.GetLatestDataYearPerSchoolType(schoolFinancialType);

            var taskList = new List <Task <IEnumerable <Document> > >();

            for (int i = ChartHistory.YEARS_OF_HISTORY - 1; i >= 0; i--)
            {
                var term = FormatHelpers.FinancialTermFormatAcademies(latestYear - i);
                var task = _financialDataService.GetSchoolDataDocumentAsync(urn, term, schoolFinancialType, cFinance);
                taskList.Add(task);
            }

            for (int i = ChartHistory.YEARS_OF_HISTORY - 1; i >= 0; i--)
            {
                var term           = FormatHelpers.FinancialTermFormatAcademies(latestYear - i);
                var taskResult     = await taskList[ChartHistory.YEARS_OF_HISTORY - 1 - i];
                var resultDocument = taskResult?.FirstOrDefault();
                var dataGroup      = schoolFinancialType.ToString();

                if (schoolFinancialType == SchoolFinancialType.Academies)
                {
                    dataGroup = (cFinance == CentralFinancingType.Include) ? DataGroups.MATDistributed : DataGroups.Academies;
                }

                if (dataGroup == DataGroups.MATDistributed && resultDocument == null)//if nothing found in -Distributed collection try to source it from (non-distributed) Academies data
                {
                    resultDocument = (await _financialDataService.GetSchoolDataDocumentAsync(urn, term, schoolFinancialType, CentralFinancingType.Exclude))
                                     ?.FirstOrDefault();
                }

                if (resultDocument != null && resultDocument.GetPropertyValue <bool>("DNS"))//School did not submit finance, return & display "no data" in the charts
                {
                    resultDocument = null;
                }

                models.Add(new SchoolFinancialDataModel(urn, term, resultDocument, schoolFinancialType));
            }

            return(models);
        }
Beispiel #4
0
        public int GetLatestFinancialDataYearPerSchoolType(SchoolFinancialType type)
        {
            var latestCollectionId = GetLatestActiveTermByDataGroup(type.ToString());

            return(int.Parse(latestCollectionId.Split('-').Last()));
        }