summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEugeniy Mikhailov <evgmik@gmail.com>2011-03-07 00:05:59 -0500
committerEugeniy Mikhailov <evgmik@gmail.com>2011-03-07 00:05:59 -0500
commit44cd737ec0b2335be76b83ecc122f31bbb5d2720 (patch)
treed909e9efbf8817dc9983d7fb1b24ef1735114d3d
parent669ce6247d613809a619283d122e43b141cc8c08 (diff)
downloadGradeBook-44cd737ec0b2335be76b83ecc122f31bbb5d2720.tar.gz
GradeBook-44cd737ec0b2335be76b83ecc122f31bbb5d2720.zip
added proc needed for calculteWeightedTotals
Ignore-this: f681c2af5b1d67308441ea7a08d600b9 darcs-hash:20110307050559-067c0-28de9c9bb4138e02d3c74884f375391c8f59e0e9.gz
-rwxr-xr-xGradeBook_lib.tcl149
1 files changed, 145 insertions, 4 deletions
diff --git a/GradeBook_lib.tcl b/GradeBook_lib.tcl
index 11c3ddd..b2c08f4 100755
--- a/GradeBook_lib.tcl
+++ b/GradeBook_lib.tcl
@@ -18,6 +18,120 @@ set grades_category [list \
FinalExam\
]
+
+
+# ########################## procs begin #################################
+proc isCalculateTotalForCategorySet { category } {
+ switch $category {
+ "unset" {set flag false}
+ Quiz {set flag true}
+ HomeWork {set flag true}
+ LabReport {set flag true}
+ MidTerm {set flag false}
+ FinalExam {set flag false}
+ default {set flag false}
+ }
+ return $flag
+}
+
+proc allColumnNames {table} {
+ set eval_str [concat SELECT * FROM \'$table\']
+ set err [catch {
+ db eval $eval_str v {
+ set all_column_names $v(*)
+ }
+ } errStat ]
+ if { $err } {
+ dbg "we should never be here if GradesTable exists" 1
+ dbg $errStat 1
+ htmlErrorMsg $errStat
+ }
+ return $all_column_names
+}
+
+proc doesColumnExists {col table} {
+ if { $col in [allColumnNames $table] } {
+ return true;
+ } else {
+ return false;
+ }
+}
+
+proc allUserNamesInGroup { group } {
+ set eval_str [concat SELECT UserName FROM \'GradesTable\' WHERE GroupName == \'$group\']
+ set username_list {}
+ set err [catch {
+ db eval $eval_str v {
+ lappend username_list $v(UserName)
+ }
+ } errStat ]
+ if { $err } {
+ dbg "we should never be here if UserName in GradesTable exists" 1
+ dbg $errStat 1
+ htmlErrorMsg $errStat
+ }
+ return $username_list
+}
+
+
+proc calculteWeightedTotals { } {
+ global grades_category
+ set all_column_names [allColumnNames GradesTable]
+ # 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 CategoryWeightedTolalName ${category}Total
+ if { [llength $all_col_in($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 } {
+ dbg "Column $CategoryWeightedTolalName does not exist, will create it now" 1
+ AddColumnNonWeb $CategoryWeightedTolalName weighted_column 0
+ }
+ }
+ 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
+ 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
+ }
+ set points_sum [expr { $points_sum + $col_val}]
+ }
+ if { $max_points($category) != 0 } {
+ # normalizing
+ set points_sum [expr { 1. * $points_sum / $max_points($category) } ]
+ }
+ UpdateColValue4UserNameNonWeb $CategoryWeightedTolalName $student $points_sum
+ }
+ }
+ }
+ }
+}
+
proc grade_Category2html_name { category } {
switch $category {
"unset" {set html_name --Select--}
@@ -31,8 +145,19 @@ proc grade_Category2html_name { category } {
return $html_name
}
+proc grade_Category2html_name { category } {
+ switch $category {
+ "unset" {set html_name --Select--}
+ Quiz {set html_name Quiz}
+ HomeWork {set html_name HomeWork}
+ LabReport {set html_name LabReport}
+ MidTerm {set html_name MidTerm}
+ FinalExam {set html_name FinalExam}
+ default {set html_name unknown}
+ }
+ return $html_name
+}
-# ########################## procs begin #################################
proc dbg {msg {level 1}} {
if { $level <=2 } {
set fid [open log a+]
@@ -254,12 +379,12 @@ proc htmlDBout {db permission_list user {sort_col {}}} {
}
if { $sql_column_str ne "" } {
# assign type cast for different sort_col
- if { [SelectColValue4User $sort_col _Col_Category_] in $grades_category } {
+ if { [SelectColValue4User $sort_col _Col_Category_] in [list $grades_category weighted_column]} {
set ordered_by_str [concat CAST(\"$sort_col\" AS REAL)]
} else {
set ordered_by_str \"$sort_col\"
}
- r get all allowed columns and rows
+ #get all allowed columns and rows
set eval_str [concat SELECT $sql_column_str FROM GradesTable $where_statement ORDER BY $ordered_by_str]
set err [catch {
db eval $eval_str v {
@@ -313,7 +438,17 @@ proc htmlDBout {db permission_list user {sort_col {}}} {
if { $index != "*" } {
# detect what column category it is
set category [SelectColValue4User $index _Col_Category_]
- set col_value [htmlReplaceEmptyString $v($index)]
+ set max_points [SelectColValue4User $index _Max_Points_]
+ set col_value $v($index)
+ if { ([SelectColValue4User GroupName $user_shown] ne "inforow") && ($category eq "weighted_column") && ($max_points != 0) } {
+ if { $col_value eq "" } {
+ set col_value 0
+ }
+ # promote to percent format
+ set col_value [format "%.1f" [expr {100.* $col_value} ] ]
+ set col_value [concat $col_value "%"]
+ }
+ set col_value [htmlReplaceEmptyString $col_value]
switch $index {
GroupName {
if { [isActionGranted changegroupname $permission_list $user] && ($user_shown ne "_UNSET_") } {
@@ -835,6 +970,8 @@ proc UpdateColumn { permission_list user } {
UpdateColValue4UserNameNonWeb $oldcolumnname _Col_Category_ $column_category
UpdateColValue4UserNameNonWeb $oldcolumnname _Max_Points_ $maxpointpossible
+ calculteWeightedTotals
+
if { $newcolumnname eq $oldcolumnname } {
# no need to mess with renaming
return
@@ -904,6 +1041,8 @@ proc UpdateGrades { permission_list user } {
dbg "the following error happen: $errStat" 3
}
}
+
+ calculteWeightedTotals
}
proc ChangeGrades { permission_list user } {
@@ -1021,6 +1160,8 @@ proc DeleteColumnNonWeb { columnname } {
htmlErrorMsg "empty column names are not permitted"
}
+
+ calculteWeightedTotals
}
proc DeleteColumn { permission_list user } {