# HG changeset patch # User Nattee Niparnan # Date 2014-08-28 16:44:29 # Node ID 889d5737bb5f976bffdff09300e5d69ad9feb49e # Parent cee35860e68948924d3bd773fc9347cd04cad872 add submission report diff --git a/app/controllers/report_controller.rb b/app/controllers/report_controller.rb --- a/app/controllers/report_controller.rb +++ b/app/controllers/report_controller.rb @@ -1,18 +1,70 @@ class ReportController < ApplicationController def login_stat @logins = Array.new - login = Login.all - date_and_time = '%y-%m-%d %H:%M' - since_time = strptime(params[:since_datetime],date_and_time) - until_time = strptime(params[:until_datetime],date_and_time) + date_and_time = '%Y-%m-%d %H:%M' + begin + @since_time = DateTime.strptime(params[:since_datetime],date_and_time) + rescue + @since_time = DateTime.new(1000,1,1) + end + begin + @until_time = DateTime.strptime(params[:until_datetime],date_and_time) + rescue + @until_time = DateTime.new(3000,1,1) + end User.all.each do |user| @logins << { login: user.login, full_name: user.full_name, - count: Login.where(user_id: user.id).count(:id), - min: Login.where(user_id: user.id).maximum(:created_at), - max: Login.where(user_id: user.id).minimum(:created_at) } + count: Login.where("user_id = ? AND created_at >= ? AND created_at <= ?", + user.id,@since_time,@until_time) + .count(:id), + min: Login.where("user_id = ? AND created_at >= ? AND created_at <= ?", + user.id,@since_time,@until_time) + .minimum(:created_at), + max: Login.where("user_id = ? AND created_at >= ? AND created_at <= ?", + user.id,@since_time,@until_time) + .maximum(:created_at) + } + end + end + + def submission_stat + + date_and_time = '%Y-%m-%d %H:%M' + begin + @since_time = DateTime.strptime(params[:since_datetime],date_and_time) + rescue + @since_time = DateTime.new(1000,1,1) + end + begin + @until_time = DateTime.strptime(params[:until_datetime],date_and_time) + rescue + @until_time = DateTime.new(3000,1,1) + end + + @submissions = {} + + User.find_each do |user| + @submissions[user.id] = { login: user.login, full_name: user.full_name, count: 0, sub: { } } + end + + Submission.where("submitted_at >= ? AND submitted_at <= ?",@since_time,@until_time).find_each do |s| + if not @submissions[s.user_id][:sub].has_key?(s.problem_id) + a = nil + begin + a = Problem.find(s.problem_id) + rescue + a = nil + end + @submissions[s.user_id][:sub][s.problem_id] = + { prob_name: (a ? a.full_name : '(NULL)'), + sub_ids: [s.id] } + else + @submissions[s.user_id][:sub][s.problem_id][:sub_ids] << s.id + end + @submissions[s.user_id][:count] += 1 end end end diff --git a/app/views/report/_date_range.html.haml b/app/views/report/_date_range.html.haml --- a/app/views/report/_date_range.html.haml +++ b/app/views/report/_date_range.html.haml @@ -3,7 +3,7 @@ .submitbox %table %tr - %td{colspan: 6, style: 'font-weight: bold'} Query maximum score in submission range + %td{colspan: 6, style: 'font-weight: bold'}= title %tr %td{style: 'width: 120px; font-weight: bold'}= param_text %td{align: 'right'} since: @@ -15,5 +15,9 @@ %tr %td %td + %td Blank mean no condition + %tr + %td + %td %td= submit_tag 'query' diff --git a/app/views/report/_report_menu.html.haml b/app/views/report/_report_menu.html.haml new file mode 100644 --- /dev/null +++ b/app/views/report/_report_menu.html.haml @@ -0,0 +1,6 @@ + +.task-menu + Reports + %br/ + = link_to '[Submission]', :action => 'submission_stat' + = link_to '[Login]', :action => 'login_stat' diff --git a/app/views/report/login_stat.html.haml b/app/views/report/login_stat.html.haml --- a/app/views/report/login_stat.html.haml +++ b/app/views/report/login_stat.html.haml @@ -11,19 +11,8 @@ %h1 Login status - -.task-menu - Reports - %br/ - = link_to '[Submission]', :action => 'submit_stat' - = link_to '[Login]', :action => 'login_stat' - - -=render partial: 'date_range', locals: {param_text: 'Submission range:' } - -hahaha - -=params[:since_datetime] +=render partial: 'report_menu' +=render partial: 'date_range', locals: {param_text: 'Login date range:', title: 'Query login stat in the range' } %table.info %thead @@ -39,6 +28,6 @@ %td= l[:login] %td= l[:full_name] %td= l[:count] - %td= l[:min] - %td= l[:max] + %td= l[:min] ? l[:min].in_time_zone.strftime('%Y-%m-%d %H:%M') : '' + %td= l[:max] ? l[:max].in_time_zone.strftime('%Y-%m-%d %H:%M') : '' diff --git a/app/views/report/submission_stat.html.haml b/app/views/report/submission_stat.html.haml new file mode 100644 --- /dev/null +++ b/app/views/report/submission_stat.html.haml @@ -0,0 +1,41 @@ +- content_for :header do + = javascript_include_tag 'new' + +%script{:type=>"text/javascript"} + $(function () { + $('#since_datetime').datetimepicker({ showButtonPanel: true, dateFormat: "yy-mm-dd", controlType: "slider"} ); + $('#until_datetime').datetimepicker({ showButtonPanel: true, dateFormat: "yy-mm-dd", controlType: "slider"} ); + }); + + +%h1 Login status + + + + +=render partial: 'report_menu' +=render partial: 'date_range', locals: {param_text: 'Submission date range:', title: 'Query submission stat in the range' } + +%table.info + %thead + %tr.info-head + %th login + %th full name + %th total submissions + %th submissions + %tbody + - @submissions.each do |user_id,data| + %tr{class: cycle('info-even','info-odd')} + %td= data[:login] + %td= data[:full_name] + %td= data[:count] + %td + - data[:sub].each do |prob_id,sub_data| + = "#{sub_data[:prob_name]}: [" + - st = [] + - sub_data[:sub_ids].each do |id| + - st << link_to(id, controller: 'graders' , action: 'submission', id: id) + = raw st.join ', ' + = ']' + %br/ + diff --git a/db/schema.rb b/db/schema.rb --- a/db/schema.rb +++ b/db/schema.rb @@ -173,6 +173,9 @@ t.text "grader_comment" t.integer "number" t.string "source_filename" + t.float "max_runtime" + t.integer "peak_memory" + t.integer "effective_code_length" end add_index "submissions", ["user_id", "problem_id", "number"], :name => "index_submissions_on_user_id_and_problem_id_and_number", :unique => true