diff options
author | Eugeniy E. Mikhailov <evgmik@gmail.com> | 2018-05-10 18:21:01 -0400 |
---|---|---|
committer | Eugeniy E. Mikhailov <evgmik@gmail.com> | 2018-05-10 18:21:01 -0400 |
commit | 1b9d810d6be0180bfd9859be97b73d4d97038bc0 (patch) | |
tree | 5303ed096e99bac423e154ab0de2ef0607238ed8 /GradeBook_lib.tcl | |
parent | b208e0fe6a5c8866164489fab3bee703e47f3a2c (diff) | |
download | GradeBook-1b9d810d6be0180bfd9859be97b73d4d97038bc0.tar.gz GradeBook-1b9d810d6be0180bfd9859be97b73d4d97038bc0.zip |
added text histogram generation
Diffstat (limited to 'GradeBook_lib.tcl')
-rwxr-xr-x | GradeBook_lib.tcl | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/GradeBook_lib.tcl b/GradeBook_lib.tcl index 45bb025..52bb0bd 100755 --- a/GradeBook_lib.tcl +++ b/GradeBook_lib.tcl @@ -2295,6 +2295,24 @@ proc UpdateAndCreateAsNeededInfoRow { columnname inforow val } { UpdateColValue4UserNameNonWeb $columnname $inforow $val } +proc data2txtPlot { data } { + set maxVal [::math::statistics::max $data ] + set minVal [::math::statistics::min $data ] + set diffVal [expr {$maxVal-$minVal}] + if { $diffVal == 0 } { + set diffVal 1 + } + set chars {▁ ▂ ▃ ▄ ▅ ▆ ▇ █}; # 8 bars + set barsNum 8; + foreach x $data { + # funky 1.1 are needed to convert it to floats + set cnt [expr { round((1.0*$x-$minVal)/(1.1*$diffVal)*(1.1*($barsNum-1.0))) }] + set bar [lrange $chars $cnt $cnt] + lappend strPlot $bar + } + return [join $strPlot ""] +} + proc UpdateColumnGradesHistogram { columnname } { # find maximum in the column with a given name among active students set hist "N/A" @@ -2304,13 +2322,14 @@ proc UpdateColumnGradesHistogram { columnname } { if { 0 != [llength $col_values] } { set maxVal [::math::statistics::max $col_values ]; # fixme should it be _Max_Points_? set minVal 0 - set barsNum 5; + set barsNum 10; set limits [::math::statistics::minmax-histogram-limits $minVal $maxVal [incr barsNum]] set limits [lrange $limits 1 end-1]; # shave first and last interval limits set hist [::math::statistics::histogram $limits $col_values ] } UpdateAndCreateAsNeededInfoRow $columnname _The_Grades_Histogram_ $hist UpdateAndCreateAsNeededInfoRow $columnname _The_Grades_Hist_Limits_ $limits + UpdateAndCreateAsNeededInfoRow $columnname _The_Grades_Hist_Text_Plot_ [data2txtPlot $hist] } proc UpdateColumnHighestGrade { columnname } { |