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

 <instance of xowf::test_item::Answer_manager[i]> exam_results \
    [ -manual_gradings manual_gradings ] \
    [ -gradingScheme gradingScheme ] [ -only_grades on|off ] \
    [ -reply ] [ -format format ] [ -orderby orderby ] results_dict

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

Return results either as HTML table, as HTML chart or as csv. When "reply" is set. the result is returned directly to the browser (for downloading). When "gradingScheme" is empty, this method returns the following fields: participant, question, achieved_points, achievable points, comment When the "gradingScheme" is specified the results are per-participant. In this cases, when the "gradingScheme" is "....::none", the fields are participant, achieved, percentage otherwise the grade and rounding of achieved points and percentage are exported based on the rules of the grading scheme. participant, achieved, percentage, grade When additionally "only_grades" is specified, just participant and grad are returned/exported.

Switches:
-manual_gradings
(optional)
-gradingScheme
(optional)
needed for reporting grades, can be empty
-only_grades
(boolean) (defaults to "false") (optional)
-reply
(defaults to "false") (optional)
when false, csv will be returned as text, when true, it will be returned as response to the browser.
-format
(defaults to "csv") (optional)
-orderby
(defaults to "participant,desc") (optional)
Parameters:
results_dict - the results to format as csv, every key in the dict represents a user_id.
Returns:
csv as value or as response to the client

Partial Call Graph (max 5 caller/called nodes):
%3 _ _ (public) ad_decode ad_decode (public) ad_script_abort ad_script_abort (public) lc_get lc_get (public) xowf::test_item::Answer_manager instproc exam_results xowf::test_item::Answer_manager instproc exam_results xowf::test_item::Answer_manager instproc exam_results->_ xowf::test_item::Answer_manager instproc exam_results->ad_decode xowf::test_item::Answer_manager instproc exam_results->ad_script_abort xowf::test_item::Answer_manager instproc exam_results->lc_get

Testcases:
No testcase defined.
Source code:
set result ""
if {$gradingScheme eq ""} {
  set t [:result_table per_question  -manual_gradings $manual_gradings  $results_dict]
} else {
  set t [:result_table per_participant  -gradingScheme $gradingScheme  -only_grades $only_grades  -manual_gradings $manual_gradings  $results_dict]
}

lassign [split $orderby ,] att order

$t orderby  -order [expr {$order eq "asc" ? "increasing" : "decreasing"}]  -type [ad_decode $att achieved real achievable real grade integer dictionary]  $att

#
# XLS export requires OOXML
#
# See https://fossil.sowaswie.de/ooxml/index
#
if {$format eq "xls" &&
    [::namespace which ::ooxml::xl_write] eq ""} {
  set format csv
}

if {$reply} {
  switch $format {
    html    {
      ns_return 200 "text/html; charset=utf-8" [$t asHTML]
      ad_script_abort
    }
    xls {
      set s [::ooxml::xl_write new]
      set sheet [$s worksheet {1}]
      set decimal [lc_get "decimal_point"]
      set doublestyle [$s style -numfmt [$s numberformat -decimal -format "#${decimal}##"]]
      set stringstyle [$s style -numfmt [$s numberformat -string]]
      set datestyle [$s style -numfmt [$s numberformat -date]]
      set cellformat {}

      #iterate cols of table
      $s row $sheet
      set displayColumns [lmap column [${t}::__columns children] {
        if {[$column exists no_csv]} continue
        if {[$column istype ::xo::Table::BulkAction]} continue
        if {[$column istype ::xo::Table::HiddenField]} continue
        set column
      }]
      foreach column $displayColumns {
        if {[$column name] in {"achieved" "achievable" "percentage"}} {
          lappend cellformat double
        } else {
          lappend cellformat string
        }
        set label [$column label]
        if {[regexp {^#([a-zA-Z0-9_:-]+\.[a-zA-Z0-9_:-]+)#$} $label _ message_key]} {
          set label [_ $message_key]
        }
        set value [string map {\" \\\" \n \r} $label]
        $s cell $sheet $value
      }
      #iterate row content
      foreach row [$t children] {
        $s row $sheet
        set i 0
        foreach column $displayColumns {
          set value [string map {\" \\\" \n \r} [$row set [$column set name]]]
          set format [lindex $cellformat $i]
          $s cell $sheet $value -style [set [set format]style]
          incr i
        }
      }
      $s write results.xlsx
      ad_script_abort
    }
    default {set result [$t write_csv]}
  }
} else {
  switch $format {
    chart   {set result [:grading_table [$t set __grade_dict]]}
    html    {set result [$t asHTML]}
    default {set result [$t format_csv]}
  }
}
$t destroy
return $result
XQL Not present:
Generic, PostgreSQL, Oracle
[ hide source ] | [ make this the default ]
Show another procedure: