diff options
author | Eugeniy Mikhailov <evgmik@gmail.com> | 2014-05-08 09:39:15 -0400 |
---|---|---|
committer | Eugeniy Mikhailov <evgmik@gmail.com> | 2014-05-08 09:39:15 -0400 |
commit | e1e483138e923a641f4a14fcb518a959bf5d3d44 (patch) | |
tree | fdcd0919140c5579b102ce07776ea244e213ae62 | |
parent | bba2a21775e66e701910ade0261468245e2d5054 (diff) | |
download | GradeBook-e1e483138e923a641f4a14fcb518a959bf5d3d44.tar.gz GradeBook-e1e483138e923a641f4a14fcb518a959bf5d3d44.zip |
added capabilities to calculate mean and media for grades
-rwxr-xr-x | GradeBook_lib.tcl | 53 |
1 files changed, 49 insertions, 4 deletions
diff --git a/GradeBook_lib.tcl b/GradeBook_lib.tcl index 41b3f86..82591d5 100755 --- a/GradeBook_lib.tcl +++ b/GradeBook_lib.tcl @@ -5,6 +5,7 @@ exec tclsh "$0" "$@" # require Tcl version of at least 8.5 since I use 'ni' and 'in' in expressions for lists package require Tcl 8.5 +package require math::statistics source ./libBasicTableOperations.tcl @@ -751,6 +752,8 @@ proc CreateGradesTable {db} { CheckAndCreateAsNeededInfoRow _Visible_To_Students_ CheckAndCreateAsNeededInfoRow _The_Highest_Grade_ CheckAndCreateAsNeededInfoRow _The_Lowest_Grade_ + CheckAndCreateAsNeededInfoRow _The_Mean_Grade_ + CheckAndCreateAsNeededInfoRow _The_Median_Grade_ # reasonable defaults for hidden columns #set instructor_hidden_columns [list UserHiddenColums UserHiddenGroups IdNum] @@ -1103,11 +1106,13 @@ proc htmlFormatMaxPossibleRaw { sql_column_str hidden_columns } { puts "</tr>" } -proc htmlFormatTheHighOrLowGradeRaw { stats_needed sql_column_str hidden_columns } { +proc htmlFormatTheStatsForGradeRaw { stats_needed sql_column_str hidden_columns } { # show max or min point values in html format switch $stats_needed { "high" {set sql_user_name _The_Highest_Grade_} "low" {set sql_user_name _The_Lowest_Grade_} + "mean" {set sql_user_name _The_Mean_Grade_} + "median" {set sql_user_name _The_Median_Grade_} default { htmlErrorMsg "Required stats ($stats_needed) to output is not known" return "" @@ -1127,6 +1132,8 @@ proc htmlFormatTheHighOrLowGradeRaw { stats_needed sql_column_str hidden_columns switch $stats_needed { "high" {set col_value "High"} "low" {set col_value "Low"} + "mean" {set col_value "Mean"} + "median" {set col_value "Median"} default {set col_value "UNKNOWN"} } } @@ -1156,7 +1163,7 @@ proc htmlFormatColVal { col_value columnname user user_shown permission_list {fo } set category [SelectColValue4User $columnname _Col_Category_] set max_points [SelectColValue4User $columnname _Max_Points_] - set special_user_names [list _Max_Points_ _The_Highest_Grade_ _The_Lowest_Grade_] + set special_user_names [list _Max_Points_ _The_Highest_Grade_ _The_Lowest_Grade_ _The_Mean_Grade_ _The_Median_Grade_] if { (([SelectColValue4User GroupName $user_shown] ne "inforow") || ($user in $special_user_names)) && ($category eq "weighted_column") && ($max_points != 0) } { if { $col_value eq "" } { set col_value 0 @@ -1288,8 +1295,10 @@ proc htmlDBout {db permission_list user {sort_col {}}} { set v_array_list [array get v] htmlGradesTableHeadersRaw $permission_list $user $sql_column_str $hidden_columns $v_array_list htmlFormatMaxPossibleRaw $sql_column_str $hidden_columns - puts [htmlFormatTheHighOrLowGradeRaw high $sql_column_str $hidden_columns] - puts [htmlFormatTheHighOrLowGradeRaw low $sql_column_str $hidden_columns] + puts [htmlFormatTheStatsForGradeRaw high $sql_column_str $hidden_columns] + puts [htmlFormatTheStatsForGradeRaw mean $sql_column_str $hidden_columns] + puts [htmlFormatTheStatsForGradeRaw median $sql_column_str $hidden_columns] + puts [htmlFormatTheStatsForGradeRaw low $sql_column_str $hidden_columns] } puts "<tr>" @@ -2022,6 +2031,40 @@ proc UpdateColumnLowestGrade { columnname } { UpdateColValue4UserNameNonWeb $columnname _The_Lowest_Grade_ $val } +proc UpdateColumnMeanGrade { 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 [::math::statistics::mean $col_values ] + # rounding value to 2 digits + set val [format "%04.2f" $val ] + } + CheckAndCreateAsNeededInfoRow _The_Mean_Grade_ + + set column_category [SelectColValue4User $columnname _Col_Category_] + + UpdateColValue4UserNameNonWeb $columnname _The_Mean_Grade_ $val +} + +proc UpdateColumnMedianGrade { 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 [::math::statistics::median $col_values ] + # rounding value to 2 digits + set val [format "%04.2f" $val ] + } + CheckAndCreateAsNeededInfoRow _The_Median_Grade_ + + set column_category [SelectColValue4User $columnname _Col_Category_] + + UpdateColValue4UserNameNonWeb $columnname _The_Median_Grade_ $val +} + proc UpdateGradesTableStatistic { permission_list user } { set grades_categories [get_grades_category] @@ -2059,6 +2102,8 @@ proc UpdateColumnStatistic { columnname {update_parent_flag true} } { } UpdateColumnHighestGrade $columnname UpdateColumnLowestGrade $columnname + UpdateColumnMeanGrade $columnname + UpdateColumnMedianGrade $columnname # check recursion exit conditions if { !$update_parent_flag } return |