From 1b9d810d6be0180bfd9859be97b73d4d97038bc0 Mon Sep 17 00:00:00 2001 From: "Eugeniy E. Mikhailov" Date: Thu, 10 May 2018 18:21:01 -0400 Subject: added text histogram generation --- GradeBook_lib.tcl | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'GradeBook_lib.tcl') 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 } { -- cgit v1.2.3