public AllDistrictComparisonsDto CreateResponseObject()
        {
            var response = new AllDistrictComparisonsDto
            {
                DistrictFiscalYearMetrics = new List <DistrictComparisonDto>()
            };

            //get fiscal years
            var fiscalYears = FiscalYearsService.GetSupportedYears();

            response.FiscalYears = fiscalYears.ToDictionary(x => x.FiscalYearId, x => x.Name);

            //create comparison record for every district
            var districts = DistrictsService.GetAll();

            foreach (var district in districts)
            {
                var districtData = new DistrictComparisonDto
                {
                    District            = district,
                    MetricsByFiscalYear = fiscalYears.ToDictionary(x => x.FiscalYearId, x => new DistrictFiscalYearMetrics
                    {
                        Metrics = new Dictionary <ComparisonType, object>()
                    })
                };
                response.DistrictFiscalYearMetrics.Add(districtData);
            }

            return(response);
        }
        public void LoadComparisonData(AllDistrictComparisonsDto response)
        {
            BudgetsService.Prime();

            foreach (var districtContainer in response.DistrictFiscalYearMetrics)
            {
                //for each fiscal year
                foreach (var fyMetric in districtContainer.MetricsByFiscalYear)
                {
                    var budget         = BudgetsService.Find(districtContainer.District.DistrictId, fyMetric.Key);
                    var previousBudget = BudgetsService.FindPreviousYear(budget);

                    //we need current and previous to calculate any increases...
                    if (budget == null || previousBudget == null)
                    {
                        Logger.LogDebug($"Skipping for district {districtContainer.District.Name}. Budget Null?:{budget == null}. Previous Budget Null?:({previousBudget == null}");
                        continue;
                    }

                    var fyEnrollment = EnrollmentService.Find(districtContainer.District.DistrictId, budget.FiscalYearId);


                    //add the metric
                    fyMetric.Value.Metrics.Add(ComparisonType.Enrollment, fyEnrollment.Enrollment);
                }
            }
        }
        public void LoadComparisonData(AllDistrictComparisonsDto response)
        {
            BudgetsService.Prime();

            foreach (var districtContainer in response.DistrictFiscalYearMetrics)
            {
                //for each fiscal year
                foreach (var fyMetric in districtContainer.MetricsByFiscalYear)
                {
                    var budget         = BudgetsService.Find(districtContainer.District.DistrictId, fyMetric.Key);
                    var previousBudget = BudgetsService.FindPreviousYear(budget);

                    //we need current and previous to calculate any increases...
                    if (budget == null || previousBudget == null)
                    {
                        continue;
                    }

                    if (!budget.Millage.HasValue || !previousBudget.Millage.HasValue)
                    {
                        continue;
                    }

                    var millageChange   = budget.Millage - previousBudget.Millage;
                    var taxRateIncrease = millageChange / previousBudget.Millage;


                    //add the metric
                    fyMetric.Value.Metrics.Add(ComparisonType.TaxRateIncrease, taxRateIncrease);
                }
            }
        }
Ejemplo n.º 4
0
        public void LoadComparisonData(AllDistrictComparisonsDto response)
        {
            BudgetsService.Prime();

            var enrollments = EnrollmentsService.GetAll().ToDictionary(x => x.DistrictId);

            foreach (var districtContainer in response.DistrictFiscalYearMetrics)
            {
                //for each fiscal year
                foreach (var fyMetric in districtContainer.MetricsByFiscalYear)
                {
                    //only proceed if we have a budget
                    var budget = BudgetsService.Find(districtContainer.District.DistrictId, fyMetric.Key);
                    if (budget == null || budget.Assessed.HasValue == false)
                    {
                        continue;
                    }

                    //add assessment
                    fyMetric.Value.Metrics.Add(ComparisonType.Assessed, budget.Assessed);

                    //if we have enrollment, calculate assessment per student
                    if (enrollments.TryGetValue(districtContainer.District.DistrictId, out var enrollment))
                    {
                        var assessedPerStudent = budget.Assessed.Value / enrollment.Enrollment;
                        fyMetric.Value.Metrics.Add(ComparisonType.AssessedPerStudent, assessedPerStudent);
                    }

                    //we can't do comparisons to previous w/out a previous budget
                    var previousBudget = BudgetsService.FindPreviousYear(budget);
                    if (previousBudget == null || previousBudget.Assessed.HasValue == false)
                    {
                        continue;
                    }

                    var assessedChanged    = budget.Assessed - previousBudget.Assessed;
                    var assessedNewRevenue = (assessedChanged * budget.Millage) / 1000;

                    //add the metric
                    fyMetric.Value.Metrics.Add(ComparisonType.AssessedIncrease, assessedChanged);
                    fyMetric.Value.Metrics.Add(ComparisonType.AssessedNewRevenue, assessedNewRevenue);

                    if (enrollment == null)
                    {
                        continue;
                    }

                    var assessedNewRevenuePerStudent = assessedNewRevenue / enrollment.Enrollment;
                    fyMetric.Value.Metrics.Add(ComparisonType.AssessedNewRevenuePerStudent, assessedNewRevenuePerStudent);
                }
            }
        }
        public void LoadComparisonData(AllDistrictComparisonsDto response)
        {
            var expendituresByDistrict = BudgetExpendituresService.GetAll().ToDictionary(x => x.DistrictId);

            foreach (var districtContainer in response.DistrictFiscalYearMetrics)
            {
                //if we don't have expenditures for this district... pass
                if (!expendituresByDistrict.ContainsKey(districtContainer.District.DistrictId))
                {
                    continue;
                }

                //get expenditures for this district
                var districtExpenditures = expendituresByDistrict[districtContainer.District.DistrictId];
                var topLevel             = districtExpenditures.TopLevelExpenditures.FirstOrDefault(x => x.TopLevelId == 1000);
                var midLevel             = topLevel?.MidLevelExpenditures.FirstOrDefault(x => x.MidLevelId == 1200);
                if (midLevel == null)
                {
                    continue;
                }


                var fiscalYearExpenditures = midLevel.FiscalYearAmounts.ToDictionary(x => x.FiscalYearId);

                //for each fiscal year
                foreach (var fyMetric in districtContainer.MetricsByFiscalYear)
                {
                    //if we don't have expenditures for this year... pass
                    if (!fiscalYearExpenditures.ContainsKey(fyMetric.Key))
                    {
                        continue;
                    }

                    //calculate the expenditure per student based on average enrollment...
                    var amount1200 = (decimal)fiscalYearExpenditures[fyMetric.Key].Total;
                    var total      = (decimal)districtExpenditures.FiscalYearAmounts.FirstOrDefault(x => x.FiscalYearId == fyMetric.Key).Total;
                    var percent    = amount1200 / total;

                    //add the metric
                    fyMetric.Value.Metrics.Add(ComparisonType.SpecialEducation1200PercentageCost, percent);
                }
            }
        }
Ejemplo n.º 6
0
        public void LoadComparisonData(AllDistrictComparisonsDto response)
        {
            var expendituresByDistrict = BudgetExpendituresService.GetAll().ToDictionary(x => x.DistrictId);
            var enrollmentsByDistrict  = EnrollmentsService.GetAll().ToDictionary(x => x.DistrictId);

            BudgetsService.Prime();

            foreach (var districtContainer in response.DistrictFiscalYearMetrics)
            {
                //if we don't have expenditures for this district... pass
                if (!expendituresByDistrict.ContainsKey(districtContainer.District.DistrictId))
                {
                    continue;
                }

                //if we don't have enrollment data for this district... pass
                if (!enrollmentsByDistrict.ContainsKey(districtContainer.District.DistrictId))
                {
                    continue;
                }

                //get expenditures for this district
                var districtExpenditures   = expendituresByDistrict[districtContainer.District.DistrictId];
                var fiscalYearExpenditures = districtExpenditures.FiscalYearAmounts.ToDictionary(x => x.FiscalYearId);

                //for each fiscal year
                foreach (var fyMetric in districtContainer.MetricsByFiscalYear)
                {
                    //if we don't have expenditures for this year... pass
                    if (!fiscalYearExpenditures.ContainsKey(fyMetric.Key))
                    {
                        continue;
                    }

                    //calculate the expenditure per student based on average enrollment...
                    var fyExpenditures = (decimal)fiscalYearExpenditures[fyMetric.Key].Total;
                    var enrollment     = (decimal)enrollmentsByDistrict[districtContainer.District.DistrictId].Enrollment;
                    var costPerStudent = fyExpenditures / enrollment;

                    //add the metric
                    fyMetric.Value.Metrics.Add(ComparisonType.TotalCost, fyExpenditures);
                    fyMetric.Value.Metrics.Add(ComparisonType.TotalCostPerStudent, costPerStudent);

                    //now make comparisons to previous year
                    var budget         = BudgetsService.Find(districtContainer.District.DistrictId, fyMetric.Key);
                    var previousBudget = BudgetsService.FindPreviousYear(budget);

                    //only make comparison if we have data
                    if (previousBudget == null)
                    {
                        continue;
                    }

                    if (!fiscalYearExpenditures.ContainsKey(previousBudget.FiscalYearId))
                    {
                        continue;
                    }

                    var previousYearExpenditures = (decimal)fiscalYearExpenditures[previousBudget.FiscalYearId].Total;

                    var costIncrease           = fyExpenditures - previousYearExpenditures;
                    var costPerStudentIncrease = costIncrease / enrollment;


                    fyMetric.Value.Metrics.Add(ComparisonType.TotalCostIncrease, costIncrease);
                    fyMetric.Value.Metrics.Add(ComparisonType.TotalCostIncreasePerStudent, costPerStudentIncrease);
                }
            }
        }
Ejemplo n.º 7
0
        public void LoadComparisonData(AllDistrictComparisonsDto response)
        {
            BudgetsService.Prime();

            var enrollmentByDistrict = EnrollmentsService.GetAll().ToDictionary(x => x.DistrictId);
            var chichesterEnrollment = enrollmentByDistrict[ChichesterDistrictId]?.Enrollment;
            var chichesterContainer  = response.DistrictFiscalYearMetrics.FirstOrDefault(x => x.District.DistrictId == ChichesterDistrictId);

            if (chichesterEnrollment == null || chichesterContainer == null)
            {
                return;
            }

            foreach (var districtContainer in response.DistrictFiscalYearMetrics)
            {
                //for each fiscal year
                foreach (var fyMetric in districtContainer.MetricsByFiscalYear)
                {
                    var budget = BudgetsService.Find(districtContainer.District.DistrictId, fyMetric.Key);
                    if (budget == null)
                    {
                        continue;
                    }

                    var costPerStudent = (decimal?)fyMetric.Value.Metrics[ComparisonType.TotalCostPerStudent];
                    if (!costPerStudent.HasValue)
                    {
                        return;
                    }

                    var chichesterMetrics        = chichesterContainer.MetricsByFiscalYear[fyMetric.Key];
                    var chichesterCostPerStudent = (decimal?)chichesterMetrics.Metrics[ComparisonType.TotalCostPerStudent];

                    Logger.LogDebug($"Chichester {ComparisonType.TotalCostPerStudent}:{chichesterCostPerStudent}, {ComparisonType.Enrollment}:{chichesterEnrollment}");


                    //what is the difference in this districts cost-per-student than chichester?
                    var difference = Math.Abs(costPerStudent.Value - chichesterCostPerStudent.Value);


                    //if chichester costs-per-student were the same as this district, how much would we save?
                    var chichesterExcessSpending = difference * chichesterEnrollment;

                    fyMetric.Value.Metrics.Add(ComparisonType.CostPerStudentComparedToChichester, difference);


                    var data = new
                    {
                        Value = chichesterExcessSpending,

                        //include all the intermediary values for proof
                        calculationValues = new {
                            ChichesterCostPerStudent = chichesterCostPerStudent,
                            DistrictCostPerStudent   = costPerStudent.Value,
                            DifferenceCostPerStudent = difference,
                            ChichesterEnrollment     = chichesterEnrollment,
                        }
                    };

                    fyMetric.Value.Metrics.Add(ComparisonType.ExcessChichesterSpending, data);
                }
            }
        }
Ejemplo n.º 8
0
        public void LoadComparisonData(AllDistrictComparisonsDto response)
        {
            var expendituresByDistrict = BudgetExpendituresService.GetAll().ToDictionary(x => x.DistrictId);
            var revenuesByDistrict     = BudgetRevenuesService.GetAll().ToDictionary(x => x.DistrictId);
            var enrollmentsByDistrict  = EnrollmentsService.GetAll().ToDictionary(x => x.DistrictId);

            foreach (var districtContainer in response.DistrictFiscalYearMetrics)
            {
                //if we don't have expenditures for this district... pass
                if (!expendituresByDistrict.ContainsKey(districtContainer.District.DistrictId))
                {
                    continue;
                }

                //if we don't have enrollment data for this district... pass
                if (!revenuesByDistrict.ContainsKey(districtContainer.District.DistrictId))
                {
                    continue;
                }

                //get expenditures for this district
                var districtExpenditures   = expendituresByDistrict[districtContainer.District.DistrictId];
                var fiscalYearExpenditures = districtExpenditures.FiscalYearAmounts.ToDictionary(x => x.FiscalYearId);

                var districtRevenues   = revenuesByDistrict[districtContainer.District.DistrictId];
                var fiscalYearRevenues = districtRevenues.FiscalYearAmounts.ToDictionary(x => x.FiscalYearId);

                //for each fiscal year
                foreach (var fyMetric in districtContainer.MetricsByFiscalYear)
                {
                    //if we don't have expenditures for this year... pass
                    if (!fiscalYearExpenditures.ContainsKey(fyMetric.Key))
                    {
                        continue;
                    }

                    //calculate the expenditure per student based on average enrollment...
                    var     fyExpenditures = fiscalYearExpenditures[fyMetric.Key];
                    var     fyRevenues     = fiscalYearRevenues[fyMetric.Key];
                    decimal deficit        = (fyRevenues.Total - fyExpenditures.Total);

                    //positive values are just confusing. normalize to zero.
                    if (deficit > 0)
                    {
                        deficit = 0;
                    }

                    //deficit should be positive value
                    deficit = Math.Abs(deficit);

                    var enrollment = (decimal)enrollmentsByDistrict[districtContainer.District.DistrictId].Enrollment;

                    //calculate deficit per student
                    var deficitPerStudent = deficit / enrollment;


                    //add the metric
                    fyMetric.Value.Metrics.Add(ComparisonType.Deficit, deficit);
                    fyMetric.Value.Metrics.Add(ComparisonType.DeficitPerStudent, deficitPerStudent);
                }
            }
        }
        public void LoadComparisonData(AllDistrictComparisonsDto response)
        {
            var revenueByDistrict     = BudgetRevenuesService.GetAll().ToDictionary(x => x.DistrictId);
            var enrollmentsByDistrict = EnrollmentsService.GetAll().ToDictionary(x => x.DistrictId);

            BudgetsService.Prime();

            foreach (var districtContainer in response.DistrictFiscalYearMetrics)
            {
                //if we don't have revenues for this district... pass
                if (!revenueByDistrict.ContainsKey(districtContainer.District.DistrictId))
                {
                    continue;
                }

                //if we don't have enrollment data for this district... pass
                if (!enrollmentsByDistrict.ContainsKey(districtContainer.District.DistrictId))
                {
                    continue;
                }

                //get revenues for this district
                var districtRevenues   = revenueByDistrict[districtContainer.District.DistrictId];
                var fiscalYearRevenues = districtRevenues.FiscalYearAmounts.ToDictionary(x => x.FiscalYearId);
                var levelAmounts       = districtRevenues.Sources.ToDictionary(x => x.LevelId);

                //for each fiscal year
                foreach (var fyMetric in districtContainer.MetricsByFiscalYear)
                {
                    //if we don't have revenue for this year... pass
                    if (!fiscalYearRevenues.ContainsKey(fyMetric.Key))
                    {
                        continue;
                    }

                    //calculate the revenue per student based on average enrollment...
                    var fyRevenue         = (decimal)fiscalYearRevenues[fyMetric.Key].Total;
                    var enrollment        = enrollmentsByDistrict[districtContainer.District.DistrictId];
                    var revenuePerStudent = fyRevenue / enrollment.Enrollment;

                    //add the metric
                    fyMetric.Value.Metrics.Add(ComparisonType.TotalRevenue, fyRevenue);
                    fyMetric.Value.Metrics.Add(ComparisonType.TotalRevenuePerStudent, revenuePerStudent);

                    //try to get state revenues
                    if (levelAmounts.TryGetValue("S", out var stateRevenues))
                    {
                        var currentYearStateRevenue = stateRevenues.FiscalYearAmounts.FirstOrDefault(x => x.FiscalYearId == fyMetric.Key);
                        if (currentYearStateRevenue != null)
                        {
                            var fyStateRevenue = currentYearStateRevenue.Total;
                            fyMetric.Value.Metrics.Add(ComparisonType.StateRevenue, fyStateRevenue);

                            var stateRevenuePerStudent = currentYearStateRevenue.Total / enrollment.Enrollment;
                            fyMetric.Value.Metrics.Add(ComparisonType.StateRevenuePerStudent, stateRevenuePerStudent);

                            fyMetric.Value.Metrics.Add(ComparisonType.StateRevenuePercent, fyStateRevenue / fyRevenue);
                        }
                    }



                    //now make comparisons to previous year
                    var budget         = BudgetsService.Find(districtContainer.District.DistrictId, fyMetric.Key);
                    var previousBudget = BudgetsService.FindPreviousYear(budget);

                    //only make comparison if we have data
                    if (previousBudget == null)
                    {
                        continue;
                    }

                    if (!fiscalYearRevenues.ContainsKey(previousBudget.FiscalYearId))
                    {
                        continue;
                    }

                    var previousYearsRevenue = (decimal)fiscalYearRevenues[previousBudget.FiscalYearId].Total;

                    var revenueIncrease           = fyRevenue - previousYearsRevenue;
                    var revenuePerStudentIncrease = revenueIncrease / enrollment.Enrollment;


                    fyMetric.Value.Metrics.Add(ComparisonType.RevenueIncrease, revenueIncrease);
                    fyMetric.Value.Metrics.Add(ComparisonType.RevenueIncreasePerStudent, revenuePerStudentIncrease);
                }
            }
        }