xowf::test_item::Answer_manager method results_table (public)

 <instance of xowf::test_item::Answer_manager[i]> results_table \
    [ -package_id package_id ] -items items  \
    [ -view_all_method view_all_method ] [ -with_answers on|off ] \
    [ -state state ] [ -grading_scheme grading_scheme ] wf

Defined in packages/xowf/tcl/test-item-procs.tcl

Render the results in format of a table and return HTML. Currently mostly deactivated (but potentially called by online-exam.wf and topic-assignment.wf).

Switches:
-package_id (optional, integer)
-items (required, object)
-view_all_method (optional, defaults to "print-answers")
-with_answers (optional, boolean, defaults to "true")
-state (optional, defaults to "done")
-grading_scheme (optional, defaults to "::xowf::test_item::grading::none")
Parameters:
wf (required, object)

Testcases:
No testcase defined.
Source code:
#set form_info [:combined_question_form -with_numbers $wf]
set form_info [:QM combined_question_form $wf]
set answer_form_field_objs [:answer_form_field_objs -wf $wf $form_info]
set autograde [dict get $form_info autograde]

#if {$autograde && [llength $answer_form_field_objs] > 10} {
#  set with_answers 0
#}

set form_field_objs {}
lappend form_field_objs  [$wf create_raw_form_field  -name _online-exam-userName  -spec text,label=#xowf.participant#]

if {$with_answers} {
  #
  # Create for every answer field a matching grading field
  #
  set ff_dict {}
  foreach answer_field_obj $answer_form_field_objs {
    #ns_log notice "LABEL [$answer_field_obj name] <[$answer_field_obj label]>"
    $answer_field_obj label [string trimright [$answer_field_obj name] _]
    $answer_field_obj mixin ::xowf::test_item::td_pretty_value

    set grading_field_obj [$wf create_raw_form_field  -name [$answer_field_obj name].score  -spec number,label=#xowf.Grading-Score#]
    lappend form_field_objs  $answer_field_obj  $grading_field_obj
    dict set ff_dict [$answer_field_obj name] $answer_field_obj
    dict set ff_dict [$grading_field_obj name] $grading_field_obj
  }
}

# if {0 && $autograde} {
#   lappend form_field_objs  #       [$wf create_raw_form_field  #          -name _online-exam-total-score  #          -spec number,label=#xowf.Total-Score#]  #       [$wf create_raw_form_field  #            -name _online-exam-grade  #            -spec number,label=#xowf.Grade#]
# }

lappend form_field_objs  [$wf create_raw_form_field  -name _online-exam-seconds  -spec number,label=#xowf.Seconds#]  [$wf create_raw_form_field  -name _creation_date  -spec date,label=#xowiki.Page-last_modified#]

#
# Check, if any of the answer form field objects is
# randomized. If so, it is necessary to recreate these eagerly,
# since the full object structure might be personalized.
#
set randomized_fields {}
foreach ff_obj $answer_form_field_objs {
  if {[$ff_obj exists shuffle_kind] && [$ff_obj shuffle_kind] ne "none"} {
    lappend randomized_fields $ff_obj
  }
}

#
# Take "orderby" from the query parameter. If not set, order by
# the first field.
#
set orderby [::$package_id query_parameter orderby:token ""]
if {$orderby eq "" && [llength $form_field_objs] > 0} {
  set orderby [[lindex $form_field_objs 0] name],asc
}

#
# Create table widget.
#
set table_widget [::xowiki::TableWidget create_from_form_fields  -package_id $package_id  -form_field_objs $form_field_objs  -orderby $orderby]
#
# Extend properties of every answer with corresponding ".score"
# values.
#
foreach p [$items children] {
  #
  # If we have randomized fields, we have to
  # recreate/reinitialize these to get proper correction
  # markings for this user. It might be possible to optimize
  # this, when only a few fields are randomized.
  #
  if {[llength $randomized_fields] > 0} {
    #ns_log notice "WORK ON [$p creation_user] "
    :answer_form_field_objs -clear -wf $wf $form_info
    $wf form_field_flush_cache
    xo::cc eval_as_user -user_id [$p creation_user] {
      set answer_form_field_objs [:answer_form_field_objs -wf $wf $form_info]
    }
  }

  set total_score 0
  set total_points 0
  foreach ff_obj $answer_form_field_objs {
    $ff_obj object $p
    set property [$ff_obj name]
    $ff_obj value [$p property $property]

    $ff_obj set_feedback 3

    #ns_log notice "[$p creation_user] [$ff_obj name] [$p property $property] -> [$ff_obj set evaluated_answer_result]"
    set r [expr {[$ff_obj exists grading_score] ? [$ff_obj set grading_score] : ""}]
    #
    # In case, we have a grading score, which is not starred, we
    # can compute points from this.
    #
    if {$r ne "" && ![regexp {[*]$} $r]} {
      #
      # Add exercise score weighted to the total score to
      # compute points.
      #
      if {[$ff_obj exists test_item_points]} {
        #ns_log notice "[$ff_obj name]: grading_score <$r>, test_item_points <[$ff_obj set test_item_points]>"

        set minutes [$ff_obj set test_item_points]
        set total_score [expr {$total_score + ($minutes * [$ff_obj set grading_score])}]
        set total_points [expr {$total_points + $minutes}]
      }
      #ns_log notice "==== [$ff_obj name] grading_score => $r"
    } else {
      set r [expr {[$ff_obj set evaluated_answer_result] eq "correct" ? 100.0 : 0.0}]*
      #ns_log notice [$ff_obj serialize]
    }
    $p set_property -new 1 $property.score $r
  }

  set duration [:get_duration [$p get_revision_sets]]
  $p set_property -new 1 _online-exam-seconds [dict get $duration seconds]

  # if {0 && $autograde && $total_points > 0} {
  #   set final_score [expr {$total_score/$total_points}]
  #   $p set_property -new 1 _online-exam-total-score $final_score
  #
  #   set d [list achievedPoints $total_score achievablePoints $total_points totalPoints $total_points]
  #   set grade [$grading_scheme grade -achieved_points $d]
  #   dict incr grade_count $grade
  #   $p set_property -new 1 _online-exam-grade $grade
  # }
}

if {$state eq "done"} {
  set uc {tcl {[$p state] ne "done"}}
} else {
  set uc {tcl {false}}
}

#
# Render table widget with extended properties.
#
set HTML [$table_widget render_page_items_as_table  -package_id $package_id  -items $items  -form_field_objs $form_field_objs  -csv true  -uc $uc  -view_field _online-exam-userName  -view_filter_link [$wf pretty_link -query m=$view_all_method]  {*}[expr {[info exists generate] ? [list -generate $generate] : ""}]  -return_url [ad_return_url]  -return_url_att local_return_url  ]
$table_widget destroy

if {0 && $autograde} {
  set gradingTable {<div class="table-responsive"><table class="table">}
  append gradingTable  "<thead><th class='text-right col-md-1'>#xowf.Grade#</th><th class='col-md-1 text-right'>#</th></thead>"  "<tbody>\n"
  set nrGrades 0
  foreach v [dict values $grade_count] { incr nrGrades $v}
  foreach k [lsort [dict keys $grade_count]] {
    set count [dict get $grade_count $k]
    set countPercentage [expr {$count*100.0/$nrGrades}]
    append gradingTable  <tr>  [subst {<td class="text-right">$k</td><td class="text-right">$count</td>}]  [subst {<td><div class="progress"><div class="progress-bar"
          style="width:$countPercentage%">$countPercentage%</div></td}]  </tr>\n
  }
  append gradingTable "</tbody></table></div>\n"
  append HTML <p>$gradingTable</p>
}
return $HTML
XQL Not present:
Generic, PostgreSQL, Oracle
[ hide source ] | [ make this the default ]
Show another procedure: