public SchoolFinancialDataModel(string id, string term, Document financialDataDocumentModel, SchoolFinancialType financialType) { Id = id; Term = term; FinancialDataDocumentModel = financialDataDocumentModel; FinancialType = financialType; }
private List <string> BuildTermsList(SchoolFinancialType type) { var years = new List <string>(); var latestYear = _financialDataService.GetLatestDataYearPerSchoolType(type); for (int i = 0; i < ChartHistory.YEARS_OF_HISTORY; i++) { years.Add(FormatHelpers.FinancialTermFormatAcademies(latestYear - i)); } return(years); }
public void PopulateHistoricalChartsWithSchoolData(List <ChartViewModel> historicalCharts, List <SchoolFinancialDataModel> SchoolFinancialDataModels, string term, RevenueGroupType revgroup, UnitType unit, SchoolFinancialType schoolFinancialType) { foreach (var chart in historicalCharts) { BuildChart(SchoolFinancialDataModels, term, revgroup, unit, schoolFinancialType, chart); if (chart.SubCharts != null) { foreach (var subChart in chart.SubCharts) { BuildChart(SchoolFinancialDataModels, term, revgroup, unit, schoolFinancialType, subChart); } } } }
private string GenerateJson(List <HistoricalChartData> historicalChartData, SchoolFinancialType schoolFinancialType) { var clonedHistoricalChartDataList = new List <HistoricalChartData>(); foreach (var chartData in historicalChartData) { var clonedChartData = (HistoricalChartData)chartData.Clone(); clonedChartData.Year = (schoolFinancialType == SchoolFinancialType.Academies) ? clonedChartData.Year.Replace(" / ", "/") : clonedChartData.Year.Replace(" / ", "-"); clonedChartData.Year = clonedChartData.Year.Remove(5, 2); clonedHistoricalChartDataList.Add(clonedChartData); } return(JsonConvert.SerializeObject(clonedHistoricalChartDataList)); }
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 void BuildChart(List <SchoolFinancialDataModel> SchoolFinancialDataModels, string term, RevenueGroupType revgroup, UnitType unit, SchoolFinancialType schoolFinancialType, ChartViewModel chart) { var historicalChartData = new List <HistoricalChartData>(); foreach (var schoolData in SchoolFinancialDataModels) { decimal?amount = null; decimal?rawAmount = null; switch (unit) { case UnitType.AbsoluteMoney: case UnitType.AbsoluteCount: amount = schoolData.GetDecimal(chart.FieldName); break; case UnitType.PerTeacher: rawAmount = schoolData.GetDecimal(chart.FieldName); if (rawAmount == null) { break; } amount = (schoolData.TeacherCount == 0) ? null : (rawAmount / (decimal)schoolData.TeacherCount); if (amount.HasValue) { amount = decimal.Round(amount.GetValueOrDefault(), 2, MidpointRounding.AwayFromZero); } break; case UnitType.PerPupil: rawAmount = schoolData.GetDecimal(chart.FieldName); if (rawAmount == null) { break; } amount = (schoolData.PupilCount == 0) ? null : (rawAmount / (decimal)schoolData.PupilCount); if (amount.HasValue) { amount = decimal.Round(amount.GetValueOrDefault(), 2, MidpointRounding.AwayFromZero); } break; case UnitType.PercentageOfTotal: decimal total = 0; rawAmount = schoolData.GetDecimal(chart.FieldName); if (rawAmount == null) { break; } switch (revgroup) { case RevenueGroupType.Expenditure: total = schoolData.TotalExpenditure; break; case RevenueGroupType.Income: total = schoolData.TotalIncome; break; case RevenueGroupType.Balance: total = schoolData.InYearBalance; break; } if (total == 0) { amount = 0; } else { amount = (total == 0) ? 0 : (rawAmount / total) * 100; amount = decimal.Round(amount.GetValueOrDefault(), 2, MidpointRounding.AwayFromZero); } break; case UnitType.NoOfPupilsPerMeasure: rawAmount = schoolData.GetDecimal(chart.FieldName); if (rawAmount == null || rawAmount == 0) { break; } amount = (schoolData.PupilCount == 0) ? null : ((decimal)schoolData.PupilCount / rawAmount); amount = decimal.Round(amount.GetValueOrDefault(), 2, MidpointRounding.AwayFromZero); break; case UnitType.HeadcountPerFTE: string fieldNameBase = chart.FieldName.Contains("FullTimeEquivalent") ? chart.FieldName.Substring(0, chart.FieldName.Length - 18) : chart.FieldName.Substring(0, chart.FieldName.Length - 9); total = schoolData.GetDecimal(fieldNameBase + "Headcount").GetValueOrDefault(); rawAmount = schoolData.GetDecimal(fieldNameBase + "FullTimeEquivalent"); if (rawAmount == null) { break; } if (total == 0) { amount = 0; } else { amount = (total == 0) ? 0 : (total / rawAmount); amount = decimal.Round(amount.GetValueOrDefault(), 2, MidpointRounding.AwayFromZero); } break; case UnitType.FTERatioToTotalFTE: total = schoolData.GetDecimal("TotalSchoolWorkforceFullTimeEquivalent").GetValueOrDefault(); rawAmount = schoolData.GetDecimal(chart.FieldName); if (rawAmount == null) { break; } if (total == 0) { amount = 0; } else { amount = (total == 0) ? 0 : (rawAmount / total) * 100; amount = decimal.Round(amount.GetValueOrDefault(), 2, MidpointRounding.AwayFromZero); } break; } historicalChartData.Add(new HistoricalChartData() { Year = schoolData.Term, Amount = amount, TeacherCount = schoolData.TeacherCount, PupilCount = schoolData.PupilCount, Unit = unit.ToString() }); } chart.HistoricalData = historicalChartData; chart.DataJson = GenerateJson(historicalChartData, schoolFinancialType); chart.LastYear = term; chart.LastYearBalance = historicalChartData.Find(d => d.Year == term).Amount; chart.ShowValue = unit; }
public int GetLatestFinancialDataYearPerSchoolType(SchoolFinancialType type) { var latestCollectionId = GetLatestActiveTermByDataGroup(type.ToString()); return(int.Parse(latestCollectionId.Split('-').Last())); }
private string FormatTerm(string term, SchoolFinancialType financialType) { return(financialType == SchoolFinancialType.Academies ? term : term.Replace('/', '-')); }
public int GetLatestDataYearPerSchoolType(SchoolFinancialType type) { return(_dataCollectionManager.GetLatestFinancialDataYearPerSchoolType(type)); }
public Document GetSchoolDataDocument(string urn, string term, SchoolFinancialType schoolFinancialType, CentralFinancingType cFinance) { return(_financialDataRepository.GetSchoolDataDocument(urn, term, schoolFinancialType, cFinance)); }
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 <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); } }
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); }