aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEugeniy Mikhailov <evgmik@gmail.com>2011-03-11 11:37:35 -0500
committerEugeniy Mikhailov <evgmik@gmail.com>2011-03-11 11:37:35 -0500
commit747ef5058223b74740a4e9855b305902a0a4294b (patch)
tree08eeed19af9e76156c3213ad2a3004043041228c
parent6b1b450910f7056166ff4d7079bc1e439a9406c3 (diff)
downloadGradeBook-747ef5058223b74740a4e9855b305902a0a4294b.tar.gz
GradeBook-747ef5058223b74740a4e9855b305902a0a4294b.zip
weighted total calculation splits in subfunctions
Ignore-this: 22ed06b39d029b6a8dd7a9ebff72468a darcs-hash:20110311163735-067c0-17f202029e8df4e65160943584301b7de1186638.gz
-rwxr-xr-xGradeBook_lib.tcl89
1 files changed, 58 insertions, 31 deletions
diff --git a/GradeBook_lib.tcl b/GradeBook_lib.tcl
index 8ce1dbf..0d77a2f 100755
--- a/GradeBook_lib.tcl
+++ b/GradeBook_lib.tcl
@@ -73,23 +73,70 @@ proc allUserNamesInGroup { group } {
return $username_list
}
+proc findColumnNamesInCategory { category } {
+ set all_column_names [getColListFromTable GradesTable]
+ set all_col_in($category) {}
+
+ foreach col $all_column_names {
+ # detect what column category it is
+ set col_category [SelectColValue4User $col _Col_Category_]
+ if { $col_category eq $category } {
+ lappend all_col_in($category) $col
+ }
+ }
+ return $all_col_in($category)
+}
+
+proc calculteMaxPointsInCategory { category } {
+ set all_col_in($category) [ findColumnNamesInCategory $category ]
+
+ set col_number_in_category [llength $all_col_in($category)]
+ set max_points($category) 0
+
+ foreach col $all_col_in($category) {
+ set col_max [SelectColValue4User $col _Max_Points_]
+ if { $col_max eq "" } {
+ htmlInfoMsg "Column \{$col\} does not have Max Point value set"
+ set col_max 0
+ }
+ set max_points($category) [expr { $max_points($category) + $col_max }]
+ }
+ return [list $max_points($category) $col_number_in_category $all_col_in($category)]
+}
+
+proc calculteSumOfPointsForStudentInCategory { student category } {
+ set all_col_in($category) [ findColumnNamesInCategory $category ]
+ set points_sum 0
+ foreach col $all_col_in($category) {
+ set col_val [SelectColValue4User $col $student]
+ if { $col_val eq "" } {
+ set col_val 0
+ }
+ if { ![string is double -strict $col_val] } {
+ htmlInfoMsg "the cell in column $col contains $col_val which is not number, using 0 instead"
+ set col_val 0
+ }
+ set points_sum [expr { $points_sum + $col_val}]
+ }
+ return $points_sum
+}
proc calculteWeightedTotals { } {
global grades_category
set all_column_names [getColListFromTable GradesTable]
+ calculteMaxPointsInCategory sss
+
# locate all column names of this category
foreach category $grades_category {
if { [isCalculateTotalForCategorySet $category] } {
- set all_col_in($category) {}
- foreach col $all_column_names {
- # detect what column category it is
- set col_category [SelectColValue4User $col _Col_Category_]
- if { $col_category eq $category } {
- lappend all_col_in($category) $col
- }
- }
+ set all_col_in($category) [ findColumnNamesInCategory $category ]
+
+ set tmpList [ calculteMaxPointsInCategory $category ]
+ set max_points($category) [lindex $tmpList 0]
+ set num_of_cols($category) [lindex $tmpList 1]
+
set CategoryWeightedTolalName ${category}Total
- if { [llength $all_col_in($category)] >= 2 } {
+ if { $num_of_cols($category) >= 2 } {
# no weighted total column created for categories which do no have at least 2 columns
# check if Weighted Category Column exists
if { $CategoryWeightedTolalName ni $all_column_names } {
@@ -98,33 +145,13 @@ proc calculteWeightedTotals { } {
}
}
if { [doesColumnExists $CategoryWeightedTolalName GradesTable] } {
- set max_points($category) 0
- foreach col $all_col_in($category) {
- set col_max [SelectColValue4User $col _Max_Points_]
- if { $col_max eq "" } {
- htmlInfoMsg "Column \{$col\} does not have Max Point value set"
- set col_max 0
- }
- set max_points($category) [expr { $max_points($category) + $col_max }]
- }
UpdateColValue4UserNameNonWeb $CategoryWeightedTolalName _Max_Points_ $max_points($category)
- # calculted weighted sum for each student in this category
+ # calculated weighted sum for each student in this category
set students_list [ allUserNamesInGroup student ]
set students_list [concat $students_list [ allUserNamesInGroup dropped ] ]
foreach student $students_list {
- set points_sum 0
- foreach col $all_col_in($category) {
- set col_val [SelectColValue4User $col $student]
- if { $col_val eq "" } {
- set col_val 0
- }
- if { ![string is double -strict $col_val] } {
- htmlInfoMsg "the cell in column $col contains $col_val which is not number, using 0 instead"
- set col_val 0
- }
- set points_sum [expr { $points_sum + $col_val}]
- }
+ set points_sum [ calculteSumOfPointsForStudentInCategory $student $category ]
if { $max_points($category) != 0 } {
# normalizing
set points_sum [expr { 1. * $points_sum / $max_points($category) } ]