From b2b1294e97634c0b9fdd8ec71f5d2e4d04b6f2f3 Mon Sep 17 00:00:00 2001 From: Eugeniy Mikhailov Date: Fri, 28 Mar 2014 19:10:50 -0400 Subject: added max and min calculation --- GradeBook_lib.tcl | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) (limited to 'GradeBook_lib.tcl') 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 } } -- cgit v1.2.3