Ejemplo n.º 1
0
        public void CalculateScore(ReportStudent student)
        {
            ItemWeightCollection subjectWeight = new ItemWeightCollection();

            foreach (string each in Subjects)
            {
                if (student.Scores[SubjectToken].Contains(each))
                {
                    subjectWeight.Add(each, student.Scores[SubjectToken].Weights[each]);
                }
            }

            ItemWeightCollection domainWeight = new ItemWeightCollection();

            foreach (string each in Domains)
            {
                if (student.Scores[DomainToken].Contains(each))
                {
                    domainWeight.Add(each, student.Scores[DomainToken].Weights[each]);
                }
            }

            if (subjectWeight.Count <= 0 && domainWeight.Count <= 0)
            {
                return;
            }

            student.Scores[TargetToken].Clear();
            student.Scores[TargetToken].Add("加權平均", 加權平均(student, subjectWeight, domainWeight), 0);
            student.Scores[TargetToken].Add("加權總分", 加權總分(student, subjectWeight, domainWeight), 0);
            student.Scores[TargetToken].Add("合計總分", 合計總分(student, subjectWeight, domainWeight), 0);
            student.Scores[TargetToken].Add("算術平均", 算術平均(student, subjectWeight, domainWeight), 0);
        }
Ejemplo n.º 2
0
        private decimal 加權平均(ReportStudent student, ItemWeightCollection subjectWeight, ItemWeightCollection domainWeight)
        {
            // 如果學生有成績計算規則使用學生,沒有使用預設2位。
            if (student.StudScoreCalculator == null)
            {
                decimal sum = 0, weight = subjectWeight.GetWeightSum() + domainWeight.GetWeightSum();

                foreach (string scoreItem in subjectWeight.Keys)
                {
                    sum += (student.Scores[SubjectToken][scoreItem] * subjectWeight[scoreItem]);
                }

                foreach (string scoreItem in domainWeight.Keys)
                {
                    sum += (student.Scores[DomainToken][scoreItem] * domainWeight[scoreItem]);
                }

                return(Round(sum / weight));
            }
            else
            {
                decimal sumS = 0, sumD = 0, avgS = 0, avgD = 0, wS = subjectWeight.GetWeightSum(), wD = domainWeight.GetWeightSum();
                decimal sumAll = 0, avgAll = 0;
                foreach (string scoreItem in subjectWeight.Keys)
                {
                    sumS   += (student.Scores[SubjectToken][scoreItem] * subjectWeight[scoreItem]);
                    sumAll += (student.Scores[SubjectToken][scoreItem] * subjectWeight[scoreItem]);
                }


                foreach (string scoreItem in domainWeight.Keys)
                {
                    sumD   += (student.Scores[DomainToken][scoreItem] * domainWeight[scoreItem]);
                    sumAll += (student.Scores[DomainToken][scoreItem] * domainWeight[scoreItem]);
                }

                // 當科目與領域混用,進位方式使用領域。
                if (wS > 0 && wD > 0)
                {
                    avgAll = student.StudScoreCalculator.ParseDomainScore(sumAll / (wS + wD));
                    return(avgAll);
                }
                else
                {
                    if (wS > 0)
                    {
                        avgS = student.StudScoreCalculator.ParseSubjectScore(sumS / wS);
                    }

                    if (wD > 0)
                    {
                        avgD = student.StudScoreCalculator.ParseDomainScore(sumD / wD);
                    }

                    return(avgS + avgD);
                }
            }
        }
Ejemplo n.º 3
0
        private decimal 算術平均(ReportStudent student, ItemWeightCollection subjectWeight, ItemWeightCollection domainWeight)
        {
            // 如果學生有成績計算規則使用學生,沒有使用預設2位。
            if (student.StudScoreCalculator == null)
            {
                decimal sum = 0, weight = subjectWeight.Count + domainWeight.Count;

                foreach (string scoreItem in subjectWeight.Keys)
                {
                    sum += student.Scores[SubjectToken][scoreItem];
                }

                foreach (string scoreItem in domainWeight.Keys)
                {
                    sum += student.Scores[DomainToken][scoreItem];
                }

                return(Round(sum / weight));
            }
            else
            {
                decimal sumS = 0, sumD = 0, avgS = 0, avgD = 0, sumAll = 0, avgAll = 0;
                foreach (string scoreItem in subjectWeight.Keys)
                {
                    sumS   += student.Scores[SubjectToken][scoreItem];
                    sumAll += student.Scores[SubjectToken][scoreItem];
                }
                foreach (string scoreItem in domainWeight.Keys)
                {
                    sumD   += student.Scores[DomainToken][scoreItem];
                    sumAll += student.Scores[DomainToken][scoreItem];
                }


                // 當科目與領域混用,進位方式使用領域
                if (subjectWeight.Count > 0 && domainWeight.Count > 0)
                {
                    avgAll = student.StudScoreCalculator.ParseDomainScore(sumAll / (subjectWeight.Count + domainWeight.Count));
                    return(avgAll);
                }
                else
                {
                    if (subjectWeight.Count > 0)
                    {
                        avgS = student.StudScoreCalculator.ParseSubjectScore(sumS / subjectWeight.Count);
                    }

                    if (domainWeight.Count > 0)
                    {
                        avgD = student.StudScoreCalculator.ParseDomainScore(sumD / domainWeight.Count);
                    }

                    return(avgS + avgD);
                }
            }
        }
Ejemplo n.º 4
0
        private decimal 加權總分(ReportStudent student, ItemWeightCollection subjectWeight, ItemWeightCollection domainWeight)
        {
            decimal sum = 0;

            foreach (string scoreItem in subjectWeight.Keys)
            {
                sum += (student.Scores[SubjectToken][scoreItem] * subjectWeight[scoreItem]);
            }

            foreach (string scoreItem in domainWeight.Keys)
            {
                sum += (student.Scores[DomainToken][scoreItem] * domainWeight[scoreItem]);
            }

            return(sum);
        }
Ejemplo n.º 5
0
        private decimal 算術平均(ReportStudent student, ItemWeightCollection subjectWeight, ItemWeightCollection domainWeight)
        {
            decimal sum = 0, weight = subjectWeight.Count + domainWeight.Count;

            foreach (string scoreItem in subjectWeight.Keys)
            {
                sum += student.Scores[SubjectToken][scoreItem];
            }

            foreach (string scoreItem in domainWeight.Keys)
            {
                sum += student.Scores[DomainToken][scoreItem];
            }

            return(Round(sum / weight));
        }
Ejemplo n.º 6
0
        private decimal 加權平均(ReportStudent student, ItemWeightCollection subjectWeight, ItemWeightCollection domainWeight)
        {
            decimal sum = 0, weight = subjectWeight.GetWeightSum() + domainWeight.GetWeightSum();

            foreach (string scoreItem in subjectWeight.Keys)
            {
                sum += (student.Scores[SubjectToken][scoreItem] * subjectWeight[scoreItem]);
            }

            foreach (string scoreItem in domainWeight.Keys)
            {
                sum += (student.Scores[DomainToken][scoreItem] * domainWeight[scoreItem]);
            }

            return(Round(sum / weight));
        }