Exemplo n.º 1
0
        public static StudentTotals CalculateStudentTotals(List<Student> sortedStudentList)
        {
            // Calculate totals

            var totals = new StudentTotals
            {
                MissingBaseline = (sortedStudentList.Where(student => student.MissingBaselineCount > 0)
                    .Select(student => student.MissingBaselineCount))
                    .Count(),

                CaringAdultsmin = (sortedStudentList.Select(student => student.Intvns.CareMin))
                    .Sum(),

                ServiceMins = (sortedStudentList.Select(student => student.Intvns.ServMin))
                    .Sum(),

                SupportMins = (sortedStudentList.Select(student => student.Intvns.HighQualTotalMin))
                    .Sum(),

                InSchoolSupportMins = (sortedStudentList.Select(student => student.Intvns.HighQualInSchoolMin))
                    .Sum(),

                OutSchoolSupportMins = (sortedStudentList.Select(student => student.Intvns.HighQualOutOfSchoolMin))
                    .Sum(),

                InterventionMins = (sortedStudentList.Select(student => student.Intvns.DuplicatedTotalMins))
                    .Sum(),

                ReportDays = (sortedStudentList.Select(student => student.Ytd.InstructDays))
                    .Sum(),

                ImproveOverall = sortedStudentList.Count(student => student.Improvement.Any)
            };

            return totals;
        }
        // Assign data to total boxes 
        private void SetDataTotalBoxes(StudentTotals studentTotals)
        {

            var inSchoolBoxString = $"{studentTotals.InSchoolSupportMins} {MinsTag}";
            var outSchoolBoxString = $"{studentTotals.OutSchoolSupportMins} {MinsTag}";
            var careBoxString = $"{studentTotals.CaringAdultsmin} {MinsTag}";
            var serveBoxString = $"{studentTotals.ServiceMins} {MinsTag}";

            SetInlineExpression.SetFormattedText(inSchoolBox, inSchoolBoxString);
            SetInlineExpression.SetFormattedText(outSchoolBox, outSchoolBoxString);
            SetInlineExpression.SetFormattedText(careBox, careBoxString);
            SetInlineExpression.SetFormattedText(serveBox, serveBoxString);

            inSchoolPctBox.Text = 
                $"{TotalsCalc.IsNumberFilter(studentTotals.InSchoolSupportMins / (studentTotals.InSchoolSupportMins + studentTotals.OutSchoolSupportMins)):P0}";
            outSchoolPctBox.Text = 
                $"{TotalsCalc.IsNumberFilter(studentTotals.OutSchoolSupportMins / (studentTotals.InSchoolSupportMins + studentTotals.OutSchoolSupportMins)):P0}";

            // Calculate and display the percentage of students who need each of the intervention types. 

            double studentCount = _filteredStudentList.Count();

            IntNeededBoxAttend.Text =
                $"{TotalsCalc.IsNumberFilter(_filteredStudentList.Count(student => student.Intvns.Needed.Attend == "No") / studentCount):P0}";

            IntNeededBoxBehav.Text =
                $"{TotalsCalc.IsNumberFilter(_filteredStudentList.Count(student => student.Intvns.Needed.Behav == "Yes") / studentCount):P0}";

            IntNeededBoxAcad.Text =
                $"{TotalsCalc.IsNumberFilter(_filteredStudentList.Count(student => student.Intvns.Needed.AcadMath == "Yes" || student.Intvns.Needed.AcadReading == "Yes" || student.Intvns.Needed.AcadOther == "Yes") / studentCount):P0}";

            // Calculate and display the percentage of students in each grade. 

            DisplayGradePercentages(studentCount, Grade6Box, "6th");
            DisplayGradePercentages(studentCount, Grade7Box, "7th");
            DisplayGradePercentages(studentCount, Grade8Box, "8th");
            DisplayGradePercentages(studentCount, Grade9Box, "9th");
            DisplayGradePercentages(studentCount, Grade10Box, "10th");
           
            // Setting general information boxes

            string missingBaselineBoxString =
                $"<Span Foreground='{(studentTotals.MissingBaseline == 0 ? "Black" : "Red")}'>{studentTotals.MissingBaseline}</Span>";

            SetInlineExpression.SetFormattedText(missingBaselineBox, missingBaselineBoxString);

            improvedBox.Text = studentTotals.ImproveOverall.ToString();
            avgDaysReportedBox.Text = $"{TotalsCalc.IsNumberFilter(Math.Round(studentTotals.ReportDays / studentCount, 1))}";
            
        }
        // Master workflow: this loads xml file and displays data in datagrids and text fields 
        public async Task LoadData(bool loadStudentList = true, bool setFilterBoxes = true)
        {
            // load studentList unless otherwise specified
            if (loadStudentList)
            {           
                StudentList.Clear();

                ProgressBarStudentList.IsIndeterminate = true;
                StudentList = await StudentListGenerator.CreateStudentListAsync(FilePath);
                ProgressBarStudentList.IsIndeterminate = false;
            }

            // Clear combobox and insert all student names in list, which can be selected to produce individual student data reports
            _studentNameList = StudentList.Select(student => student.Profile.Name).Distinct().ToList();
            ComboBoxControls.SetComboBox(studentBox, _studentNameList, false);

            // Set filter comboboxes (site, fellow, and grade), unless otherwise specified,
            // and return dictionary associating fellows with their sites
            if (setFilterBoxes)
            {
                _fellowSiteDict = await ComboBoxControls.SetFilterBoxes(StudentList, siteBox, fellowBox, gradeBox);
            }

            // filters student list according to settings and comboboxe selections
            _filteredStudentList = ListFilters.SetStudentListFilters(siteBox, fellowBox, gradeBox);
            
            // Set student list to datagrid(s)
            SetDatagrids();

            // calculate student totals to add to total boxes
            _studentTotals = await TotalsCalc.CalculateStudentTotalsAsync(_filteredStudentList);

            // Set text boxes presenting totals for student data 
            SetDataTotalBoxes(_studentTotals);

        }