learning-progress-summary.tcl
Displays Learing Activity Progress Statistics based on workflow instances in the hidden global instance of the tlf-lrn package.
- Location:
- /packages/xotcl-request-monitor/www/learning-progress-summary.tcl
- Author:
- Gustaf Neumann
Related Files
- packages/xotcl-request-monitor/www/learning-progress-summary.tcl
- packages/xotcl-request-monitor/www/learning-progress-summary.adp
[ hide source ] | [ make this the default ]
File Contents
ad_page_contract { Displays Learing Activity Progress Statistics based on workflow instances in the hidden global instance of the tlf-lrn package. @param package_id Package id of the xowiki instance of the course to be displayed @param page_id Optional id of a activity form for filtering @author Gustaf Neumann } -query { {package_id:naturalnum 75595941} {page_id:naturalnum ""} {user_id:naturalnum ""} {interval:naturalnum 7} } -properties { title:onevalue context:onevalue } set title "Learning Progress Summary" set context [list $title] set swa [acs_user::site_wide_admin_p] if {!$swa} { ad_return_forbidden "Permission Denied" \ "<blockquote><p>You don't have permissions to view this page</blockquote>" ad_script_abort } array set course_labels { 75595941 "BIS1 WS/2015" 75611112 "Distributed Development" } # Course_label might provide a link set course_label [ns_quotehtml $course_labels($package_id)] set dimensional [subst { { package_id "Course:" 75595941 { {75595941 "$course_labels(75595941)"} {75611112 "$course_labels(75611112)"} } } { interval "Interval:" 7 { {1 "Last Day"} {7 "Last Week"} {31 "Last Month"} {0 "All"} } } }] set dimensional_html [ad_dimensional $dimensional] set filter_html "" set filter_clause true if {$interval ne "0"} { append filter_clause " and ic.last_modified > now() - interval '$interval days'" } if {$user_id ne ""} { append filter_clause " and ic.hkey->'creator_id' = :user_id" acs_user::get -user_id $user_id -array user_info set user_label "$user_info(first_names) $user_info(last_name)" set no_filter_url [export_vars -base learning-progress-summary [list package_id interval]] append filter_html [subst { <li>Learning activities of $user_info(first_names) $user_info(last_name) (stop <a href="[ns_quotehtml $no_filter_url]">filtering</a>)</li> }] } if {$page_id ne ""} { append filter_clause " and ic.hkey->'form_id' = :page_id" ::xo::db::CrClass get_instance_from_db -item_id $page_id set page_label [$page_id title] set no_filter_url [export_vars -base learning-progress-summary [list package_id user_id]] append filter_html [subst { <li>Users performed activity $page_label (stop <a href="[ns_quotehtml $no_filter_url]">filtering</a>)</li> }] } switch $interval { 0 {set time_group "date_trunc('week', ic.last_modified)"} 1 {set time_group "date_trunc('hour', ic.last_modified)"} 7 {set time_group "date_trunc('day', ic.last_modified)"} 31 {set time_group "date_trunc('day', ic.last_modified)"} } proc js_time {time} { regexp {^([^.]+)[.]} $time _ time set clock [clock scan $time -format "%Y-%m-%d %H:%M:%S%z"] set year [clock format $clock -format %Y] set month [expr {[string trimleft [clock format $clock -format %N]] - 1}] return "Date.UTC($year, $month, [clock format $clock -format {%d, %H, %M, %S}], 0)" } ################################################################## # # Activities # ################################################################## set sql { With RECURSIVE items AS ( select ic.*,o.last_modified from xowiki_form_instance_item_index ic, cr_items cp, acs_objects o where cp.name = :package_id and ic.parent_id = cp.item_id and o.object_id = ic.item_id UNION ALL select ic.*, o.last_modified from xowiki_form_instance_item_index ic, acs_objects o, items where items.item_id = ic.parent_id and o.object_id = ic.item_id ) select count(ic.hkey->'creator_id'), $time_group as time from items ic where $filter_clause group by time having count(ic.hkey->'creator_id') > 0 order by time asc } set yAxis(Activity) 0 set type(Activity) column set color(Activity) "#058DC7" set zIndex(Activity) 1 set items [::xo::db::Object instantiate_objects -sql [subst $sql] -initialize false] foreach t [$items children] { set count [$t set count] set js_time [js_time [$t set time]] set link "#" ;# todo where to point? lappend counts(Activity) [subst {{x: $js_time, y: $count, url: "$link"}}] } ################################################################## # # Scores # ################################################################## set sql { With RECURSIVE items AS ( select ic.*,o.last_modified from xowiki_form_instance_item_index ic, cr_items cp, acs_objects o where cp.name = :package_id and ic.parent_id = cp.item_id and o.object_id = ic.item_id UNION ALL select ic.*, o.last_modified from xowiki_form_instance_item_index ic, acs_objects o, items where items.item_id = ic.parent_id and o.object_id = ic.item_id ) select avg((ic.hkey->'score')::real), $time_group as time from items ic where (ic.hkey->'score')::real > -1 and $filter_clause group by time order by time asc } set yAxis(Score) 1 set type(Score) spline set color(Score) "#ff0000" set zIndex(Score) 2 set items [::xo::db::Object instantiate_objects -sql [subst $sql] -initialize false] foreach t [$items children] { set avg [$t set avg] set js_time [js_time [$t set time]] set link "#" ;# todo where to point? lappend counts(Score) [subst {{x: $js_time, y: $avg, url: "$link"}}] } set y_axis_label "Activities" set y_axis_label_1 "Scores" set chart_title "Learning Activities by Time" set series {} foreach u [array names counts] { lappend series [subst {{ type: '$type($u)', yAxis: $yAxis($u), color: '$color($u)', zIndex: $zIndex($u), name: '$u', data: \[ [join $counts($u) ,] \], events: {click: function (event) {location.href = event.point.url;}} }}] } set series [join $series ,] # Local variables: # mode: tcl # tcl-indent-level: 4 # indent-tabs-mode: nil # End: