diff options
author | Eugeniy Mikhailov <evgmik@gmail.com> | 2014-03-28 19:10:50 -0400 |
---|---|---|
committer | Eugeniy Mikhailov <evgmik@gmail.com> | 2014-03-28 19:10:50 -0400 |
commit | b2b1294e97634c0b9fdd8ec71f5d2e4d04b6f2f3 (patch) | |
tree | 029f3a1e1795f696d7860b3b657972b095bf98fc | |
parent | 1fe1faf77ad852ea33e5bcf9feee1e026ae68fa9 (diff) | |
download | GradeBook-b2b1294e97634c0b9fdd8ec71f5d2e4d04b6f2f3.tar.gz GradeBook-b2b1294e97634c0b9fdd8ec71f5d2e4d04b6f2f3.zip |
added max and min calculation
-rwxr-xr-x | GradeBook_lib.tcl | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/GradeBook_lib.tcl b/GradeBook_lib.tcl index 31fefca..12d044c 100755 --- a/GradeBook_lib.tcl +++ b/GradeBook_lib.tcl @@ -697,6 +697,32 @@ proc EditGradesCategories { db permission_list user } { } +proc isThereUserNameInTheGradesTable { username } { + set eval_str [concat SELECT UserName FROM \'GradesTable\' WHERE UserName == \'$username\'] + 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" msg_level_critical + dbg $errStat msg_level_critical + htmlErrorMsg $errStat + return false + } + if { 0 == [llength $username_list] } { + return false + } else { + return true + } +} + +proc CheckAndCreateAsNeededInfoRow { row_name } { + if { ![isThereUserNameInTheGradesTable $row_name] } { + AddUserNonWeb {} {} $row_name inforow + } +} proc CreateGradesTable {db} { # construct sql string for table creation @@ -1793,6 +1819,57 @@ proc UpdateColValue4GroupNameNonWeb { columnname groupname val } { } } +proc LeaveOnlyNumbersInList { l } { + set new_list {} + foreach {el} $l { + if { [string is double -strict $el] } { + lappend new_list $el + } + } + return $new_list +} + +proc GetGroupValuesInColumn { group_name columnname } { + set col_values {} + set eval_str "SELECT \"$columnname\" FROM GradesTable WHERE GroupName=\"$group_name\"" + set err [catch { + db eval $eval_str v { + if { [info exist v($columnname)] } { + lappend col_values $v($columnname) + } + } + } errStat ] + if { $err } { + htmlErrorMsg $errStat + dbg "the following error happen: $errStat" msg_level_critical + } + return $col_values +} + +proc UpdateColumnHighestGrade { columnname } { + # find maximum in the column with a given name among active students + set val "N/A" + set col_values [GetGroupValuesInColumn student $columnname] + set col_values [LeaveOnlyNumbersInList $col_values] + if { 0 != [llength $col_values] } { + set val [expr max([join $col_values ,])] + } + CheckAndCreateAsNeededInfoRow _The_Highest_Grade_ + UpdateColValue4UserNameNonWeb $columnname _The_Highest_Grade_ $val +} + +proc UpdateColumnLowestGrade { columnname } { + # find minimum in the column with a given name among active students + set val "N/A" + set col_values [GetGroupValuesInColumn student $columnname] + set col_values [LeaveOnlyNumbersInList $col_values] + if { 0 != [llength $col_values] } { + set val [expr min([join $col_values ,])] + } + CheckAndCreateAsNeededInfoRow _The_Lowest_Grade_ + UpdateColValue4UserNameNonWeb $columnname _The_Lowest_Grade_ $val +} + proc UpdateGrades { permission_list user } { global script_name set subaction [::ncgi::value subaction {}] @@ -1815,6 +1892,8 @@ proc UpdateGrades { permission_list user } { dbg "the following error happen: $errStat" msg_level_critical } else { calculteWeightedTotals + UpdateColumnHighestGrade $columnname + UpdateColumnLowestGrade $columnname } } |