learning-progress.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.tcl
- Author:
- Gustaf Neumann
Related Files
- packages/xotcl-request-monitor/www/learning-progress.tcl
- packages/xotcl-request-monitor/www/learning-progress.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 ""} {kind:naturalnum 0} {interval:naturalnum 7} } -properties { title:onevalue context:onevalue } set title "Learning Progress" 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)"} } } { kind "Kind:" 0 { {0 "Students"} {1 "Activities"} } } { interval "Interval:" 7 { {1 "Last Day"} {7 "Last Week"} {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'" } 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)"} } 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)" } switch $kind { 0 { ################################################################## # # Students # ################################################################## 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->'form_id'), ic.hkey->'creator_id' as creator_id, $time_group as time from items ic where $filter_clause group by creator_id, time having count(ic.hkey->'form_id') > 0 order by time asc } set items [::xo::db::Object instantiate_objects -sql [subst $sql] -initialize false] foreach t [$items children] { set user_id [$t set creator_id] set count [$t set count] set js_time [js_time [$t set time]] acs_user::get -user_id $user_id -array user_info set user_label "$user_info(first_names) $user_info(last_name)" set user_link [export_vars -base learning-activity [list user_id package_id]] lappend counts($user_label) [subst {{x: $js_time, y: $count, url: "$user_link"}}] } set count_label "Activities" set chart_title "Students working on Learning Activities" } 1 { ################################################################## # # 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 ic.hkey->'form_id' as activity_id, count(ic.hkey->'creator_id'), $time_group as time from items ic where $filter_clause group by activity_id, time having count(ic.hkey->'creator_id') > 0 order by time asc } set items [::xo::db::Object instantiate_objects -sql [subst $sql] -initialize false] foreach t [$items children] { set activity_id [$t set activity_id] set count [$t set count] set js_time [js_time [$t set time]] ::xo::db::CrClass get_instance_from_db -item_id $activity_id set activity_label [$activity_id title] set activity_link [export_vars -base learning-activity [list [list page_id $activity_id] package_id]] lappend counts($activity_label) [subst {{x: $js_time, y: $count, url: "$activity_link"}}] } set count_label "Students" set chart_title "Learning Activities used by Students" } } set series {} foreach u [array names counts] { lappend series [subst {{ 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: