aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEugeniy Mikhailov <evgmik@gmail.com>2013-12-08 18:34:56 -0500
committerEugeniy Mikhailov <evgmik@gmail.com>2013-12-08 18:34:56 -0500
commit6a2d55ceb7bdc1df307aaaca6acfb8f9216cc1cd (patch)
tree38ea28162043097b254424217ef5eaa9e76e4394
parentb0654412ce518cb8a22ace232f4734da49047bb6 (diff)
downloadGradeBook-6a2d55ceb7bdc1df307aaaca6acfb8f9216cc1cd.tar.gz
GradeBook-6a2d55ceb7bdc1df307aaaca6acfb8f9216cc1cd.zip
added function which calculates grades sum with dropped lowest
-rwxr-xr-xGradeBook_lib.tcl50
1 files changed, 50 insertions, 0 deletions
diff --git a/GradeBook_lib.tcl b/GradeBook_lib.tcl
index d189acd..dff6624 100755
--- a/GradeBook_lib.tcl
+++ b/GradeBook_lib.tcl
@@ -203,6 +203,56 @@ proc calculteMaxPointsInCategory { category } {
return [list $max_points($category) $col_number_in_category $all_col_in($category)]
}
+proc listSum { l } {
+ set sum 0
+ foreach e $l {
+ set sum [ expr {$e + $sum}]
+ }
+ return $sum
+}
+
+proc dropTheLowestGrades {num_to_drop grades grades_max_possible} {
+ # this procedure drops the grade with the lowest weight i.e. grade/max_grade
+
+ # this is recursively called so 1st to check is exit condition
+ if { $num_to_drop <= 0 } {
+ set grades_sum [listSum $grades]
+ set grades_max_sum [listSum $grades_max_possible]
+ return [list $grades_sum $grades_max_sum]
+ }
+
+ # let's find the index of grade with the smallest grade/max_possible ratio
+ set sm_ind -1; # non existing
+ set smallest_ratio 10000; # something very big (larger than 1)
+ set i 0
+ foreach max_val $grades_max_possible {
+ # grades with zero max_possible belong to bonuses
+ # and it is impossible to calculate its weight anyway
+ if { $max_val != 0 } {
+ set grade [lindex $grades $i]
+ set grade_weight [expr {1.0*$grade/$max_val}]
+ } else {
+ # we cannot divide by zero
+ # so we just put something very big (much larger than 1)
+ set grade_weight 1000000; # larger than default smallest_ratio
+ }
+ # update lowest contribution
+ if { $grade_weight < $smallest_ratio } {
+ set sm_ind $i
+ set smallest_ratio $grade_weight
+ }
+ incr i
+ }
+ if { $sm_ind >=0 } {
+ # let's remove lowest contribution
+ set grades [lreplace $grades $sm_ind $sm_ind]
+ set grades_max_possible [lreplace $grades_max_possible $sm_ind $sm_ind]
+ }
+ incr num_to_drop -1
+
+ return [dropTheLowestGrades $num_to_drop $grades $grades_max_possible]
+}
+
proc calculteSumOfPointsForStudentInCategory { student category } {
set all_col_in($category) [ findColumnNamesInCategory $category ]
set gained_points 0