Index: openacs-4/packages/xowf/tcl/test-item-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/xowf/tcl/test-item-procs.tcl,v diff -u -N -r1.7.2.57 -r1.7.2.58 --- openacs-4/packages/xowf/tcl/test-item-procs.tcl 28 Apr 2020 22:29:41 -0000 1.7.2.57 +++ openacs-4/packages/xowf/tcl/test-item-procs.tcl 28 Apr 2020 22:58:04 -0000 1.7.2.58 @@ -1142,6 +1142,8 @@ # - marked_results # - answers_panel # - results_table + # - grading_table + # - grade # - participants_table # - revisions_up_to # @@ -1592,7 +1594,61 @@ } } + :public method grading_table {grade_count_dict} { + # + # Produce HTML markup based on a dict with grades as keys and + # counts as values. + # + set gradingTable {
} + append gradingTable \ + "" \ + "\n" + set nrGrades 0 + foreach v [dict values $grade_count_dict] { incr nrGrades $v} + foreach k [lsort [dict keys $grade_count_dict]] { + set count [dict get $grade_count_dict $k] + set countPercentage [format %.2f [expr {$count *100.0 / $nrGrades}]] + append gradingTable \ + \ + [subst {}] \ + [subst {
#xowf.Grade##
$k$count
$countPercentage%
\n + } + append gradingTable "
\n" + return $gradingTable + } + :public method grade {-achieved_points -percentage_boundaries} { + # + # Return a numeric grade based on achieved_points dict and + # percentage_mapping. On invalid data, return 0. + # + # achieved_points: {achievedPoints 4.0 achieveablePoints 4 totalPoints 4} + # percentage_mapping: {50.0 60.0 70.0 80.0} + # + if {[dict exists $achieved_points totalPoints] && [dict get $achieved_points totalPoints] > 0} { + set percentage [format %.2f [expr { + [dict get $achieved_points achievedPoints]*100/ + [dict get $achieved_points totalPoints] + }]] + set grade 1 + set gradePos 0 + foreach boundary $percentage_boundaries { + #ns_log notice "compare $percentage < $boundary" + if {$percentage < $boundary} { + set grade [expr {5-$gradePos}] + #ns_log notice "setting grade to $grade" + break + } + incr gradePos + } + } else { + set grade 0 + } + return $grade + } + :public method results_table { -package_id:integer -items:object,required