コード例 #1
0
        private void ChangePart(object sender, EventArgs e)
        {
            GenericPicker <SectionPart> picker = (GenericPicker <SectionPart>)sender;

            if (picker.SelectedIndex >= picker.Items.Count || picker.SelectedIndex < 0)
            {
                //this is a fix for a bug where the event listener is still listening even though it's been unassigned.
                return;
            }
            SectionPart part      = picker.SelectedItem;
            double      partScore = ScoringHelper.ScorePart(part, inspection).Item3;

            partScoreLabel.Text = "Part score: " + (partScore * 100).ToString("0.00") + "%";
            setScoresColor(partScore, partScoreLabel);
        }
コード例 #2
0
        private static List <ReportSection> PrepareInspectionForScoring(Inspection inspection)
        {
            List <ReportSection> reportSections = new List <ReportSection>();
            double sumTotalAvailablePoints      = 0;
            double sumTotalEarnedPoints         = 0;
            bool   anyUnacceptables             = false;

            foreach (SectionModel section in inspection.Checklist.Sections)
            {
                //We can have a commendable section even with unacceptable parts.
                //bool anyUnacceptableParts = false;
                if (section.SectionParts.Any())
                {
                    double sumSectionAvailablePoints = 0;
                    double sumSectionEarnedPoints    = 0;
                    foreach (SectionPart part in section.SectionParts)
                    {
                        Tuple <double, double, double> partScores = ScoringHelper.ScorePart(part, inspection);
                        part.availablePoints = partScores.Item1;
                        part.earnedPoints    = partScores.Item2;
                        part.percentage      = partScores.Item3;
                        if (part.availablePoints > 0)
                        {
                            double percentScore = part.percentage * 100;
                            if (percentScore < inspection.Checklist.ScoreThresholdSatisfactory)
                            {
                                part.rating = Rating.Unacceptable;
                                //anyUnacceptableParts = true;
                            }
                            else if (percentScore < inspection.Checklist.ScoreThresholdCommendable)
                            {
                                part.rating = Rating.Satisfactory;
                            }
                            else
                            {
                                part.rating = Rating.Commendable;
                            }
                        }
                        sumSectionAvailablePoints += partScores.Item1;
                        sumSectionEarnedPoints    += partScores.Item2;
                    }
                    section.availablePoints = sumSectionAvailablePoints;
                    section.earnedPoints    = sumSectionEarnedPoints;
                    if (sumSectionAvailablePoints > 0)
                    {
                        section.percentage = sumSectionEarnedPoints / sumSectionAvailablePoints;
                    }
                    else
                    {
                        section.percentage = 0;
                    }
                }
                else
                {
                    Tuple <double, double, double> sectionScores = ScoringHelper.ScoreSection(section, inspection);
                    section.availablePoints = sectionScores.Item1;
                    section.earnedPoints    = sectionScores.Item2;
                    section.percentage      = sectionScores.Item3;
                }

                if (section.availablePoints > 0)
                {
                    double percentScore = section.percentage * 100;
                    if (percentScore < inspection.Checklist.ScoreThresholdSatisfactory)
                    {
                        anyUnacceptables = true;
                        section.rating   = Rating.Unacceptable;
                    }
                    else if (percentScore < inspection.Checklist.ScoreThresholdCommendable /*|| anyUnacceptableParts*/)
                    {
                        section.rating = Rating.Satisfactory;
                    }
                    else
                    {
                        section.rating = Rating.Commendable;
                    }
                }
                else
                {
                    section.rating = Rating.None;
                }

                sumTotalAvailablePoints += section.availablePoints;
                sumTotalEarnedPoints    += section.earnedPoints;
                if (true)                       //if we're supposed to render this section
                {
                    ReportSection reportSection = new ReportSection(section);
                    reportSection.PartsToRender = section.SectionParts;
                    reportSections.Add(reportSection);
                }
            }
            inspection.availablePoints = sumTotalAvailablePoints;
            inspection.earnedPoints    = sumTotalEarnedPoints;
            if (sumTotalAvailablePoints > 0)
            {
                inspection.percentage = sumTotalEarnedPoints / sumTotalAvailablePoints;
                double percentScore = inspection.percentage * 100;
                if (percentScore < inspection.Checklist.ScoreThresholdSatisfactory)
                {
                    inspection.rating = Rating.Unacceptable;
                }
                else if (percentScore < inspection.Checklist.ScoreThresholdCommendable || anyUnacceptables)
                {
                    inspection.rating = Rating.Satisfactory;
                }
                else
                {
                    inspection.rating = Rating.Commendable;
                }
            }
            else
            {
                inspection.percentage = 0;
                inspection.rating     = Rating.None;
            }
            return(reportSections);
        }