Ejemplo n.º 1
0
        public async Task <ActionResult> Index(
            string urn,
            SimpleCriteria simpleCriteria,
            BenchmarkCriteria benchmarkCriteria,
            int basketSize = ComparisonListLimit.DEFAULT,
            SchoolFinancialDataModel benchmarkSchoolData = null,
            EstablishmentType searchedEstabType          = EstablishmentType.All,
            ComparisonType comparisonType = ComparisonType.Manual,
            ComparisonArea areaType       = ComparisonArea.All,
            string laCode                  = null,
            RevenueGroupType tab           = RevenueGroupType.Expenditure,
            CentralFinancingType financing = CentralFinancingType.Include)
        {
            ChartGroupType chartGroup;

            switch (tab)
            {
            case RevenueGroupType.Expenditure:
                chartGroup = ChartGroupType.TotalExpenditure;
                break;

            case RevenueGroupType.Income:
                chartGroup = ChartGroupType.TotalIncome;
                break;

            case RevenueGroupType.Balance:
                chartGroup = ChartGroupType.InYearBalance;
                break;

            case RevenueGroupType.Workforce:
                chartGroup = ChartGroupType.Workforce;
                break;

            default:
                chartGroup = ChartGroupType.All;
                break;
            }

            var defaultUnitType = tab == RevenueGroupType.Workforce ? UnitType.AbsoluteCount : UnitType.AbsoluteMoney;
            var benchmarkCharts = await BuildSchoolBenchmarkChartsAsync(tab, chartGroup, defaultUnitType, financing);

            var establishmentType = DetectEstablishmentType(base.ExtractSchoolComparisonListFromCookie());

            var chartGroups = _benchmarkChartBuilder.Build(tab, establishmentType).DistinctBy(c => c.ChartGroup).ToList();

            string selectedArea = "";

            switch (areaType)
            {
            case ComparisonArea.All:
                selectedArea = "All England";
                break;

            case ComparisonArea.LaCode:
            case ComparisonArea.LaName:
                selectedArea = _laService.GetLaName(laCode);
                break;
            }

            string schoolArea = "";

            if (benchmarkSchoolData != null)
            {
                schoolArea = _laService.GetLaName(benchmarkSchoolData.LaNumber.ToString());
            }

            var academiesTerm  = FormatHelpers.FinancialTermFormatAcademies(_financialDataService.GetLatestDataYearPerSchoolType(SchoolFinancialType.Academies));
            var maintainedTerm = FormatHelpers.FinancialTermFormatMaintained(_financialDataService.GetLatestDataYearPerSchoolType(SchoolFinancialType.Maintained));

            var vm = new BenchmarkChartListViewModel(benchmarkCharts, base.ExtractSchoolComparisonListFromCookie(), chartGroups, comparisonType, benchmarkCriteria, simpleCriteria, benchmarkSchoolData, establishmentType, searchedEstabType, schoolArea, selectedArea, academiesTerm, maintainedTerm, areaType, laCode, urn, basketSize);

            ViewBag.Tab               = tab;
            ViewBag.ChartGroup        = chartGroup;
            ViewBag.UnitType          = defaultUnitType;
            ViewBag.HomeSchoolId      = vm.SchoolComparisonList.HomeSchoolUrn;
            ViewBag.EstablishmentType = vm.EstablishmentType;
            ViewBag.Financing         = financing;
            ViewBag.ChartFormat       = ChartFormat.Charts;

            return(View("Index", vm));
        }
 public async Task AddHistoricalChartsAsync(TabType tabType, ChartGroupType chartGroup, CentralFinancingType cFinance, UnitType unitType)
 {
     SchoolVM.HistoricalCharts.AddRange(_historicalChartBuilder.Build(tabType, chartGroup, SchoolVM.EstablishmentType, unitType));
     SchoolVM.HistoricalFinancialDataModels.AddRange(await this.GetFinancialDataHistoricallyAsync(SchoolVM.Id, SchoolVM.EstablishmentType, SchoolVM.Tab == TabType.Workforce ? CentralFinancingType.Exclude : cFinance));
     _fcService.PopulateHistoricalChartsWithFinancialData(SchoolVM.HistoricalCharts, SchoolVM.HistoricalFinancialDataModels, SchoolVM.LatestTerm, tabType, unitType, SchoolVM.EstablishmentType);
 }
        private async Task <List <FinancialDataModel> > GetFinancialDataHistoricallyAsync(long urn, EstablishmentType estabType, CentralFinancingType cFinance)
        {
            var models     = new List <FinancialDataModel>();
            var latestYear = await _financialDataService.GetLatestDataYearPerEstabTypeAsync(estabType);

            var taskList = new List <Task <SchoolTrustFinancialDataObject> >();

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

            for (int i = ChartHistory.YEARS_OF_HISTORY - 1; i >= 0; i--)
            {
                var term             = SchoolFormatHelpers.FinancialTermFormatAcademies(latestYear - i);
                var resultDataObject = await taskList[ChartHistory.YEARS_OF_HISTORY - 1 - i];

                if (estabType == EstablishmentType.Academies && cFinance == CentralFinancingType.Include && resultDataObject == null)//if nothing found in MAT-Allocs collection try to source it from (non-allocated) Academies data
                {
                    resultDataObject = (await _financialDataService.GetSchoolFinancialDataObjectAsync(urn, term, estabType, CentralFinancingType.Exclude));
                }

                if (resultDataObject != null && resultDataObject.DidNotSubmit)//School did not submit finance, return & display "no data" in the charts
                {
                    resultDataObject = null;
                }

                models.Add(new FinancialDataModel(urn.ToString(), term, resultDataObject, estabType));
            }

            return(models);
        }
Ejemplo n.º 4
0
 public Document GetSchoolDataDocument(string urn, string term, SchoolFinancialType schoolFinancialType, CentralFinancingType cFinance)
 {
     return(_financialDataRepository.GetSchoolDataDocument(urn, term, schoolFinancialType, cFinance));
 }
        private async Task <FinancialDataModel> GetLatestFinancialDataAsync(long urn, EstablishmentType estabType, CentralFinancingType cFinance)
        {
            var latestYear = await _financialDataService.GetLatestDataYearPerEstabTypeAsync(estabType);

            var term             = SchoolFormatHelpers.FinancialTermFormatAcademies(latestYear);
            var resultDataObject = await _financialDataService.GetSchoolFinancialDataObjectAsync(urn, term, estabType, cFinance);

            if (estabType == EstablishmentType.Academies && cFinance == CentralFinancingType.Include && resultDataObject == null)//if nothing found in MAT-Allocs collection try to source it from (non-allocated) Academies data
            {
                resultDataObject = (await _financialDataService.GetSchoolFinancialDataObjectAsync(urn, term, estabType, CentralFinancingType.Exclude));
            }

            if (resultDataObject != null && resultDataObject.DidNotSubmit)//School did not submit finance, return & display "no data" in the charts
            {
                resultDataObject = null;
            }

            return(new FinancialDataModel(urn.ToString(), term, resultDataObject, estabType));
        }
        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);
            }
        }
Ejemplo n.º 7
0
 public async Task <IEnumerable <Document> > GetSchoolDataDocumentAsync(string urn, string term, SchoolFinancialType schoolFinancialType, CentralFinancingType cFinance)
 {
     return(await _financialDataRepository.GetSchoolDataDocumentAsync(urn, term, schoolFinancialType, cFinance));
 }
        public async Task <ActionResult> Detail(int urn, UnitType unit = UnitType.AbsoluteMoney, CentralFinancingType financing = CentralFinancingType.Include, RevenueGroupType tab = RevenueGroupType.Expenditure, ChartFormat format = ChartFormat.Charts)
        {
            ChartGroupType chartGroup;

            switch (tab)
            {
            case RevenueGroupType.Expenditure:
                chartGroup = ChartGroupType.TotalExpenditure;
                break;

            case RevenueGroupType.Income:
                chartGroup = ChartGroupType.TotalIncome;
                break;

            case RevenueGroupType.Balance:
                chartGroup = ChartGroupType.InYearBalance;
                break;

            case RevenueGroupType.Workforce:
                chartGroup = ChartGroupType.Workforce;
                break;

            default:
                chartGroup = ChartGroupType.All;
                break;
            }

            var schoolDetailsFromEdubase = _contextDataService.GetSchoolByUrn(urn.ToString());

            if (schoolDetailsFromEdubase == null)
            {
                return(View("EmptyResult", new SchoolSearchViewModel(base.ExtractSchoolComparisonListFromCookie(), SearchTypes.SEARCH_BY_NAME_ID)));
            }

            SchoolViewModel schoolVM = await BuildSchoolVMAsync(tab, chartGroup, financing, schoolDetailsFromEdubase);

            UnitType unitType;

            switch (tab)
            {
            case RevenueGroupType.Workforce:
                unitType = UnitType.AbsoluteCount;
                break;

            case RevenueGroupType.Balance:
                unitType = unit == UnitType.AbsoluteMoney || unit == UnitType.PerPupil || unit == UnitType.PerTeacher ? unit : UnitType.AbsoluteMoney;
                break;

            default:
                unitType = unit;
                break;
            }

            _fcService.PopulateHistoricalChartsWithSchoolData(schoolVM.HistoricalCharts, schoolVM.HistoricalSchoolFinancialDataModels, (BuildTermsList(schoolVM.FinancialType)).First(), tab, unitType, schoolVM.FinancialType);

            ViewBag.Tab         = tab;
            ViewBag.ChartGroup  = chartGroup;
            ViewBag.UnitType    = unitType;
            ViewBag.Financing   = financing;
            ViewBag.ChartFormat = format;

            return(View("Detail", schoolVM));
        }
        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);
        }
        private async Task <SchoolViewModel> BuildSchoolVMAsync(RevenueGroupType revenueGroup, ChartGroupType chartGroup, CentralFinancingType cFinance, dynamic schoolDetailsData, UnitType unit = UnitType.AbsoluteCount)
        {
            var schoolVM = new SchoolViewModel(schoolDetailsData, base.ExtractSchoolComparisonListFromCookie());

            schoolVM.HistoricalCharts = _historicalChartBuilder.Build(revenueGroup, chartGroup, schoolVM.FinancialType, unit);
            schoolVM.ChartGroups      = _historicalChartBuilder.Build(revenueGroup, schoolVM.FinancialType).DistinctBy(c => c.ChartGroup).ToList();
            schoolVM.Terms            = BuildTermsList(schoolVM.FinancialType);
            schoolVM.Tab = revenueGroup;

            schoolVM.HistoricalSchoolFinancialDataModels = await this.GetFinancialDataHistoricallyAsync(schoolVM.Id, schoolVM.FinancialType, cFinance);

            schoolVM.TotalRevenueIncome      = schoolVM.HistoricalSchoolFinancialDataModels.Last().TotalIncome;
            schoolVM.TotalRevenueExpenditure = schoolVM.HistoricalSchoolFinancialDataModels.Last().TotalExpenditure;
            schoolVM.InYearBalance           = schoolVM.HistoricalSchoolFinancialDataModels.Last().InYearBalance;

            return(schoolVM);
        }
        public async Task <PartialViewResult> GetCharts(int urn, string term, RevenueGroupType revGroup, ChartGroupType chartGroup, UnitType unit, CentralFinancingType financing = CentralFinancingType.Include, ChartFormat format = ChartFormat.Charts)
        {
            financing = revGroup == RevenueGroupType.Workforce ? CentralFinancingType.Exclude : financing;

            var schoolDetailsFromEdubase = _contextDataService.GetSchoolByUrn(urn.ToString());

            SchoolViewModel schoolVM = await BuildSchoolVMAsync(revGroup, chartGroup, financing, schoolDetailsFromEdubase, unit);

            _fcService.PopulateHistoricalChartsWithSchoolData(schoolVM.HistoricalCharts, schoolVM.HistoricalSchoolFinancialDataModels, term, revGroup, unit, schoolVM.FinancialType);

            ViewBag.ChartFormat = format;

            return(PartialView("Partials/Chart", schoolVM));
        }
        public async Task <SchoolTrustFinancialDataObject> GetSchoolFinanceDataObjectAsync(long urn, string term, EstablishmentType estabType, CentralFinancingType cFinance)
        {
            var dataGroup = estabType.ToDataGroup(cFinance);

            string collectionName = await _dataCollectionManager.GetCollectionIdByTermByDataGroupAsync(term, dataGroup);

            var container = _client.GetContainer(_databaseId, collectionName);

            var queryString     = $"SELECT * FROM c WHERE c.{SchoolTrustFinanceDataFieldNames.URN}=@URN";
            var queryDefinition = new QueryDefinition(queryString)
                                  .WithParameter($"@URN", urn);

            try
            {
                var feedIterator = container.GetItemQueryIterator <SchoolTrustFinancialDataObject>(queryDefinition, null);
                return((await feedIterator.ReadNextAsync()).FirstOrDefault());
            }
            catch (Exception ex)
            {
                if (term.Contains(_dataCollectionManager.GetLatestFinancialDataYearPerEstabTypeAsync(estabType).ToString()))
                {
                    var errorMessage = $"{collectionName} could not be loaded! : {ex.Message} : {queryDefinition.QueryText}";
                    base.LogException(ex, errorMessage);
                }
                return(null);
            }
        }
        public async Task <SchoolTrustFinancialDataObject> GetSchoolFinancialDataObjectAsync(long urn, string term, EstablishmentType estabType, CentralFinancingType cFinance)
        {
            var dataGroup = estabType.ToDataGroup(cFinance);

            var collectionName = await _dataCollectionManager.GetCollectionIdByTermByDataGroupAsync(term, dataGroup);

            var container = _client.GetContainer(_databaseId, collectionName);

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

            var queryString = $"SELECT * FROM c WHERE c.{SchoolTrustFinanceDataFieldNames.URN}=@URN";

            var queryDefinition = new QueryDefinition(queryString)
                                  .WithParameter($"@URN", urn);

            try
            {
                var feedIterator = container.GetItemQueryIterator <SchoolTrustFinancialDataObject>(queryDefinition, null);
                var result       = (await feedIterator.ReadNextAsync()).FirstOrDefault();

                if (dataGroup == DataGroups.MATAllocs && result == null)//if nothing found in MAT-Allocs collection try to source it from Academies data
                {
                    return(await GetSchoolFinancialDataObjectAsync(urn, term, estabType, CentralFinancingType.Exclude));
                }

                if (result != null && result.DidNotSubmit)//School did not submit finance, return & display none in the charts
                {
                    return(null);
                }

                return(result);
            }
            catch (Exception ex)
            {
                if (term.Contains(_dataCollectionManager.GetLatestFinancialDataYearPerEstabTypeAsync(estabType).ToString()))
                {
                    var errorMessage = $"{collectionName} could not be loaded! : {ex.Message} : {queryDefinition.QueryText}";
                    base.LogException(ex, errorMessage);
                }
                return(null);
            }
        }