Show More
Commit Description:
add golden submit button...
Commit Description:
add golden submit button - When the user submit more than or equal to 100 times the submit button will turn gold - Add golden-btn tag in applications.css.scss
References:
File last commit:
Show/Diff file:
Action:
app/controllers/report_controller.rb | 566 lines | 18.3 KiB | text/x-ruby | RubyLexer |
- start adding testcases into database...
r607 require 'csv'
add login stat
r410 class ReportController < ApplicationController
add problem stat
r400
more test and clean up authorization
r756 before_action :check_valid_login
- DRY score table...
r601
- login report...
r792 before_action :admin_authorization, only: [:login_stat,:submission, :submission_query,
:login, :login_detail_query, :login_summary_query,
update cheat scrutinize
r793 :stuck, :cheat_report, :cheat_scrutinize, :show_max_score, :current_score]
add cheat detail
r507
change depricated before_filter to before_action
r745 before_action(only: [:problem_hof]) { |c|
more test and clean up authorization
r756 return false unless check_valid_login
add options to allow hall of fame viewing by any user...
r424
change find(:xxx) to correct syntax for rails 4
r619 admin_authorization unless GraderConfiguration["right.user_view_submission"]
save point
r423 }
add problem stat
r400
- update show max score
r594 def max_score
- fix authorization for viewing submission, only admin can view all problems all the time, normal user depends on right.view_submission and problem.available?...
r593 end
- remove inplace editor from view...
r598 def current_score
change find(:xxx) to correct syntax for rails 4
r619 @problems = Problem.available_problems
update max_score / current_score to property use group filter
r802 if params[:group_id] && params[:users] == 'group'
add current score by group
r762 @group = Group.find(params[:group_id])
@users = @group.users.where(enabled: true)
else
@users = User.includes(:contests).includes(:contest_stat).where(enabled: true)
end
- DRY score table...
r601 @scorearray = calculate_max_score(@problems, @users,0,0,true)
- remove inplace editor from view...
r598
#rencer accordingly
- start adding testcases into database...
r607 if params[:button] == 'download' then
- remove inplace editor from view...
r598 csv = gen_csv_from_scorearray(@scorearray,@problems)
send_data csv, filename: 'max_score.csv'
else
#render template: 'user_admin/user_stat'
render 'current_score'
end
end
- update show max score
r594 def show_max_score
#process parameters
#problems
@problems = []
make report max_score remember user options
r647 if params[:problem_id]
params[:problem_id].each do |id|
next unless id.strip != ""
pid = Problem.find_by_id(id.to_i)
@problems << pid if pid
end
- update show max score
r594 end
- fix authorization for viewing submission, only admin can view all problems all the time, normal user depends on right.view_submission and problem.available?...
r593
- update show max score
r594 #users
update max_score / current_score to property use group filter
r802 @users = if params[:users] == "group" then
Group.find(params[:group_id]).users.all
elsif params[:users] == 'enabled'
User.includes(:contests).includes(:contest_stat).where(enabled: true)
else
change find(:xxx) to correct syntax for rails 4
r619 User.includes(:contests).includes(:contest_stat)
- update show max score
r594 end
#set up range from param
make report max_score remember user options
r647 @since_id = params.fetch(:from_id, 0).to_i
@until_id = params.fetch(:to_id, 0).to_i
- after submission, redirecto to edit_submission_path...
r696 @since_id = nil if @since_id == 0
@until_id = nil if @until_id == 0
- update show max score
r594
- remove inplace editor from view...
r598 #calculate the routine
make report max_score remember user options
r647 @scorearray = calculate_max_score(@problems, @users, @since_id, @until_id)
- fix authorization for viewing submission, only admin can view all problems all the time, normal user depends on right.view_submission and problem.available?...
r593
- remove inplace editor from view...
r598 #rencer accordingly
- start adding testcases into database...
r607 if params[:button] == 'download' then
- fix authorization for viewing submission, only admin can view all problems all the time, normal user depends on right.view_submission and problem.available?...
r593 csv = gen_csv_from_scorearray(@scorearray,@problems)
send_data csv, filename: 'max_score.csv'
else
- update show max score
r594 #render template: 'user_admin/user_stat'
render 'max_score'
- fix authorization for viewing submission, only admin can view all problems all the time, normal user depends on right.view_submission and problem.available?...
r593 end
end
- add problem toggle test js reponse (it was forgotten)...
r570 def score
if params[:commit] == 'download csv'
@problems = Problem.all
else
change find(:xxx) to correct syntax for rails 4
r619 @problems = Problem.available_problems
- add problem toggle test js reponse (it was forgotten)...
r570 end
change find(:xxx) to correct syntax for rails 4
r619 @users = User.includes(:contests, :contest_stat).where(enabled: true)
- add problem toggle test js reponse (it was forgotten)...
r570 @scorearray = Array.new
@users.each do |u|
ustat = Array.new
ustat[0] = u
@problems.each do |p|
sub = Submission.find_last_by_user_and_problem(u.id,p.id)
if (sub!=nil) and (sub.points!=nil) and p and p.full_score
ustat << [(sub.points.to_f*100/p.full_score).round, (sub.points>=p.full_score)]
else
ustat << [0,false]
end
end
@scorearray << ustat
end
if params[:commit] == 'download csv' then
csv = gen_csv_from_scorearray(@scorearray,@problems)
send_data csv, filename: 'last_score.csv'
else
render template: 'user_admin/user_stat'
end
end
- login report...
r792 def login
end
def login_summary_query
@users = Array.new
date_and_time = '%Y-%m-%d %H:%M'
begin
md = params[:since_datetime].match(/(\d+)-(\d+)-(\d+) (\d+):(\d+)/)
@since_time = Time.zone.local(md[1].to_i,md[2].to_i,md[3].to_i,md[4].to_i,md[5].to_i)
rescue
@since_time = DateTime.new(1000,1,1)
end
begin
md = params[:until_datetime].match(/(\d+)-(\d+)-(\d+) (\d+):(\d+)/)
@until_time = Time.zone.local(md[1].to_i,md[2].to_i,md[3].to_i,md[4].to_i,md[5].to_i)
rescue
@until_time = DateTime.new(3000,1,1)
end
record = User
.left_outer_joins(:logins).group('users.id')
.where("logins.created_at >= ? AND logins.created_at <= ?",@since_time, @until_time)
case params[:users]
when 'enabled'
record = record.where(enabled: true)
when 'group'
record = record.joins(:groups).where(groups: {id: params[:groups]}) if params[:groups]
end
record = record.pluck("users.id,users.login,users.full_name,count(logins.created_at),min(logins.created_at),max(logins.created_at)")
record.each do |user|
x = Login.where("user_id = ? AND created_at >= ? AND created_at <= ?",
user[0],@since_time,@until_time)
.pluck(:ip_address).uniq
@users << { id: user[0],
login: user[1],
full_name: user[2],
count: user[3],
min: user[4],
max: user[5],
ip: x
}
end
end
def login_detail_query
add login stat
r410 @logins = Array.new
(in progress) add date range
r412
add submission report
r413 date_and_time = '%Y-%m-%d %H:%M'
begin
fix date time
r443 md = params[:since_datetime].match(/(\d+)-(\d+)-(\d+) (\d+):(\d+)/)
@since_time = Time.zone.local(md[1].to_i,md[2].to_i,md[3].to_i,md[4].to_i,md[5].to_i)
add submission report
r413 rescue
@since_time = DateTime.new(1000,1,1)
end
begin
fix date time
r443 md = params[:until_datetime].match(/(\d+)-(\d+)-(\d+) (\d+):(\d+)/)
@until_time = Time.zone.local(md[1].to_i,md[2].to_i,md[3].to_i,md[4].to_i,md[5].to_i)
add submission report
r413 rescue
@until_time = DateTime.new(3000,1,1)
end
report ip
r442
- login report...
r792 @logins = Login.includes(:user).where("logins.created_at >= ? AND logins.created_at <= ?",@since_time, @until_time)
case params[:users]
when 'enabled'
@logins = @logins.where(users: {enabled: true})
when 'group'
@logins = @logins.joins(user: :groups).where(user: {groups: {id: params[:groups]}}) if params[:groups]
add submission report
r413 end
end
submission stat
r788 def submission
end
add submission report
r413
submission stat
r788 def submission_query
@submissions = Submission
submission report
r790 .includes(:problem).includes(:user).includes(:language)
- login report...
r792 case params[:users]
when 'enabled'
@submissions = @submissions.where(users: {enabled: true})
when 'group'
@submissions = @submissions.joins(user: :groups).where(user: {groups: {id: params[:groups]}}) if params[:groups]
submission report
r790 end
- login report...
r792 case params[:problems]
submission report
r790 when 'enabled'
- login report...
r792 @submissions = @submissions.where(problems: {available: true})
when 'selected'
@submissions = @submissions.where(problem_id: params[:problem_id])
submission report
r790 end
#set default
params[:since_datetime] = Date.today.to_s if params[:since_datetime].blank?
submission stat
r788
@submissions, @recordsTotal, @recordsFiltered = process_query_record( @submissions,
global_search: ['user.login','user.full_name','problem.name','problem.full_name','points'],
date_filter: 'submitted_at',
date_param_since: 'since_datetime',
date_param_until: 'until_datetime',
submission report
r790 hard_limit: 100_000
submission stat
r788 )
add login stat
r410 end
add problem stat
r400
- login report...
r792 def login
end
add problem stat
r400 def problem_hof
# gen problem list
@user = User.find(session[:user_id])
@problems = @user.available_problems
# get selected problems or the default
if params[:id]
begin
@problem = Problem.available.find(params[:id])
rescue
redirect_to action: :problem_hof
flash[:notice] = 'Error: submissions for that problem are not viewable.'
return
end
end
add more problem stat
r457 return unless @problem
@by_lang = {} #aggregrate by language
add problem stat
r400
add more problem stat
r457 range =65
@histogram = { data: Array.new(range,0), summary: {} }
@summary = {count: 0, solve: 0, attempt: 0}
user = Hash.new(0)
Submission.where(problem_id: @problem.id).find_each do |sub|
#histogram
d = (DateTime.now.in_time_zone - sub.submitted_at) / 24 / 60 / 60
@histogram[:data][d.to_i] += 1 if d < range
add problem stat
r400
fix hof when submissions is not graded...
r465 next unless sub.points
add more problem stat
r457 @summary[:count] += 1
user[sub.user_id] = [user[sub.user_id], (sub.points >= @problem.full_score) ? 1 : 0].max
add problem stat
r400
add more problem stat
r457 lang = Language.find_by_id(sub.language_id)
next unless lang
next unless sub.points >= @problem.full_score
add problem stat
r400
add more problem stat
r457 #initialize
unless @by_lang.has_key?(lang.pretty_name)
@by_lang[lang.pretty_name] = {
runtime: { avail: false, value: 2**30-1 },
memory: { avail: false, value: 2**30-1 },
length: { avail: false, value: 2**30-1 },
first: { avail: false, value: DateTime.new(3000,1,1) }
}
end
add problem stat
r400
add more problem stat
r457 if sub.max_runtime and sub.max_runtime < @by_lang[lang.pretty_name][:runtime][:value]
@by_lang[lang.pretty_name][:runtime] = { avail: true, user_id: sub.user_id, value: sub.max_runtime, sub_id: sub.id }
add problem stat
r400 end
add more problem stat
r457 if sub.peak_memory and sub.peak_memory < @by_lang[lang.pretty_name][:memory][:value]
@by_lang[lang.pretty_name][:memory] = { avail: true, user_id: sub.user_id, value: sub.peak_memory, sub_id: sub.id }
end
- fix hof when user is deleted...
r664 if sub.submitted_at and sub.submitted_at < @by_lang[lang.pretty_name][:first][:value] and sub.user and
add more problem stat
r457 !sub.user.admin?
@by_lang[lang.pretty_name][:first] = { avail: true, user_id: sub.user_id, value: sub.submitted_at, sub_id: sub.id }
end
if @by_lang[lang.pretty_name][:length][:value] > sub.effective_code_length
@by_lang[lang.pretty_name][:length] = { avail: true, user_id: sub.user_id, value: sub.effective_code_length, sub_id: sub.id }
end
end
#process user_id
@by_lang.each do |lang,prop|
prop.each do |k,v|
v[:user] = User.exists?(v[:user_id]) ? User.find(v[:user_id]).full_name : "(NULL)"
end
end
#sum into best
if @by_lang and @by_lang.first
@best = @by_lang.first[1].clone
@by_lang.each do |lang,prop|
if @best[:runtime][:value] >= prop[:runtime][:value]
@best[:runtime] = prop[:runtime]
@best[:runtime][:lang] = lang
end
if @best[:memory][:value] >= prop[:memory][:value]
@best[:memory] = prop[:memory]
@best[:memory][:lang] = lang
end
if @best[:length][:value] >= prop[:length][:value]
@best[:length] = prop[:length]
@best[:length][:lang] = lang
end
if @best[:first][:value] >= prop[:first][:value]
@best[:first] = prop[:first]
@best[:first][:lang] = lang
add problem stat
r400 end
end
end
add more problem stat
r457
@histogram[:summary][:max] = [@histogram[:data].max,1].max
@summary[:attempt] = user.count
user.each_value { |v| @summary[:solve] += 1 if v == 1 }
add problem stat
r400 end
add more problem stat
r457
add struggle report
r463 def stuck #report struggling user,problem
# init
user,problem = nil
solve = true
tries = 0
@struggle = Array.new
record = {}
Submission.includes(:problem,:user).order(:problem_id,:user_id).find_each do |sub|
fix bug for "stuck" and add authorization
r464 next unless sub.problem and sub.user
add struggle report
r463 if user != sub.user_id or problem != sub.problem_id
@struggle << { user: record[:user], problem: record[:problem], tries: tries } unless solve
record = {user: sub.user, problem: sub.problem}
user,problem = sub.user_id, sub.problem_id
solve = false
tries = 0
end
if sub.points >= sub.problem.full_score
solve = true
else
tries += 1
end
end
@struggle.sort!{|a,b| b[:tries] <=> a[:tries] }
@struggle = @struggle[0..50]
end
check multiple login
r500
def multiple_login
grafted from 2b2663ff0e59
r501 #user with multiple IP
check multiple login
r500 raw = Submission.joins(:user).joins(:problem).where("problems.available != 0").group("login,ip_address").order(:login)
last,count = 0,0
grafted from 2b2663ff0e59
r501 first = 0
@users = []
check multiple login
r500 raw.each do |r|
if last != r.user.login
count = 1
grafted from 2b2663ff0e59
r501 last = r.user.login
first = r
check multiple login
r500 else
grafted from 2b2663ff0e59
r501 @users << first if count == 1
@users << r
count += 1
end
end
#IP with multiple user
raw = Submission.joins(:user).joins(:problem).where("problems.available != 0").group("login,ip_address").order(:ip_address)
last,count = 0,0
first = 0
@ip = []
raw.each do |r|
if last != r.ip_address
count = 1
last = r.ip_address
first = r
else
@ip << first if count == 1
@ip << r
count += 1
check multiple login
r500 end
end
end
fix logins user_id from string to integer
r504 def cheat_report
add cheat report prototype
r506 date_and_time = '%Y-%m-%d %H:%M'
begin
md = params[:since_datetime].match(/(\d+)-(\d+)-(\d+) (\d+):(\d+)/)
@since_time = Time.zone.local(md[1].to_i,md[2].to_i,md[3].to_i,md[4].to_i,md[5].to_i)
rescue
add cheat detail
r507 @since_time = Time.zone.now.ago( 90.minutes)
add cheat report prototype
r506 end
begin
md = params[:until_datetime].match(/(\d+)-(\d+)-(\d+) (\d+):(\d+)/)
@until_time = Time.zone.local(md[1].to_i,md[2].to_i,md[3].to_i,md[4].to_i,md[5].to_i)
rescue
add cheat detail
r507 @until_time = Time.zone.now
add cheat report prototype
r506 end
#multi login
@ml = Login.joins(:user).where("logins.created_at >= ? and logins.created_at <= ?",@since_time,@until_time).select('users.login,count(distinct ip_address) as count,users.full_name').group("users.id").having("count > 1")
st = <<-SQL
SELECT l2.*
FROM logins l2 INNER JOIN
(SELECT u.id,COUNT(DISTINCT ip_address) as count,u.login,u.full_name
FROM logins l
INNER JOIN users u ON l.user_id = u.id
WHERE l.created_at >= '#{@since_time.in_time_zone("UTC")}' and l.created_at <= '#{@until_time.in_time_zone("UTC")}'
GROUP BY u.id
HAVING count > 1
) ml ON l2.user_id = ml.id
WHERE l2.created_at >= '#{@since_time.in_time_zone("UTC")}' and l2.created_at <= '#{@until_time.in_time_zone("UTC")}'
UNION
SELECT l2.*
FROM logins l2 INNER JOIN
(SELECT l.ip_address,COUNT(DISTINCT u.id) as count
FROM logins l
INNER JOIN users u ON l.user_id = u.id
WHERE l.created_at >= '#{@since_time.in_time_zone("UTC")}' and l.created_at <= '#{@until_time.in_time_zone("UTC")}'
GROUP BY l.ip_address
HAVING count > 1
) ml on ml.ip_address = l2.ip_address
INNER JOIN users u ON l2.user_id = u.id
WHERE l2.created_at >= '#{@since_time.in_time_zone("UTC")}' and l2.created_at <= '#{@until_time.in_time_zone("UTC")}'
ORDER BY ip_address,created_at
SQL
@mld = Login.find_by_sql(st)
st = <<-SQL
SELECT s.id,s.user_id,s.ip_address,s.submitted_at,s.problem_id
FROM submissions s INNER JOIN
(SELECT u.id,COUNT(DISTINCT ip_address) as count,u.login,u.full_name
FROM logins l
INNER JOIN users u ON l.user_id = u.id
WHERE l.created_at >= ? and l.created_at <= ?
GROUP BY u.id
HAVING count > 1
) ml ON s.user_id = ml.id
WHERE s.submitted_at >= ? and s.submitted_at <= ?
UNION
SELECT s.id,s.user_id,s.ip_address,s.submitted_at,s.problem_id
FROM submissions s INNER JOIN
(SELECT l.ip_address,COUNT(DISTINCT u.id) as count
FROM logins l
INNER JOIN users u ON l.user_id = u.id
WHERE l.created_at >= ? and l.created_at <= ?
GROUP BY l.ip_address
HAVING count > 1
) ml on ml.ip_address = s.ip_address
WHERE s.submitted_at >= ? and s.submitted_at <= ?
ORDER BY ip_address,submitted_at
SQL
@subs = Submission.joins(:problem).find_by_sql([st,@since_time,@until_time,
@since_time,@until_time,
@since_time,@until_time,
@since_time,@until_time])
add cheat detail
r507 end
update cheat scrutinize
r793 def cheat_scrutinize
add cheat detail
r507 #convert date & time
date_and_time = '%Y-%m-%d %H:%M'
begin
md = params[:since_datetime].match(/(\d+)-(\d+)-(\d+) (\d+):(\d+)/)
@since_time = Time.zone.local(md[1].to_i,md[2].to_i,md[3].to_i,md[4].to_i,md[5].to_i)
rescue
@since_time = Time.zone.now.ago( 90.minutes)
end
begin
md = params[:until_datetime].match(/(\d+)-(\d+)-(\d+) (\d+):(\d+)/)
@until_time = Time.zone.local(md[1].to_i,md[2].to_i,md[3].to_i,md[4].to_i,md[5].to_i)
rescue
@until_time = Time.zone.now
end
#convert sid
@sid = params[:SID].split(/[,\s]/) if params[:SID]
unless @sid and @sid.size > 0
return
update cheat scrutinize
r793 redirect_to actoin: :cheat_scrutinize
add cheat detail
r507 flash[:notice] = 'Please enter at least 1 student id'
end
mark = Array.new(@sid.size,'?')
condition = "(u.login = " + mark.join(' OR u.login = ') + ')'
@st = <<-SQL
SELECT l.created_at as submitted_at ,-1 as id,u.login,u.full_name,l.ip_address,"" as problem_id,"" as points,l.user_id
FROM logins l INNER JOIN users u on l.user_id = u.id
WHERE l.created_at >= ? AND l.created_at <= ? AND #{condition}
UNION
SELECT s.submitted_at,s.id,u.login,u.full_name,s.ip_address,s.problem_id,s.points,s.user_id
FROM submissions s INNER JOIN users u ON s.user_id = u.id
WHERE s.submitted_at >= ? AND s.submitted_at <= ? AND #{condition}
ORDER BY submitted_at
SQL
p = [@st,@since_time,@until_time] + @sid + [@since_time,@until_time] + @sid
@logs = Submission.joins(:problem).find_by_sql(p)
fix logins user_id from string to integer
r504 end
- remove inplace editor from view...
r598 protected
def calculate_max_score(problems, users,since_id,until_id, get_last_score = false)
fix whitelisting bugs...
r784 #scorearray[i] = user #i's user stat where i is the index (not id)
- remove inplace editor from view...
r598 scorearray = Array.new
users.each do |u|
ustat = Array.new
ustat[0] = u
problems.each do |p|
unless get_last_score
#get max score
max_points = 0
Submission.find_in_range_by_user_and_problem(u.id,p.id,since_id,until_id).each do |sub|
max_points = sub.points if sub and sub.points and (sub.points > max_points)
end
ustat << [(max_points.to_f*100/p.full_score).round, (max_points>=p.full_score)]
else
#get latest score
sub = Submission.find_last_by_user_and_problem(u.id,p.id)
if (sub!=nil) and (sub.points!=nil) and p and p.full_score
ustat << [(sub.points.to_f*100/p.full_score).round, (sub.points>=p.full_score)]
else
ustat << [0,false]
- fix syntax error
r599 end
- remove inplace editor from view...
r598 end
end
scorearray << ustat
end
return scorearray
end
add cheat report prototype
r506
- start adding testcases into database...
r607 def gen_csv_from_scorearray(scorearray,problem)
CSV.generate do |csv|
#add header
header = ['User','Name', 'Activated?', 'Logged in', 'Contest']
problem.each { |p| header << p.name }
header += ['Total','Passed']
csv << header
#add data
scorearray.each do |sc|
total = num_passed = 0
row = Array.new
sc.each_index do |i|
if i == 0
row << sc[i].login
row << sc[i].full_name
row << sc[i].activated
row << (sc[i].try(:contest_stat).try(:started_at)!=nil ? 'yes' : 'no')
row << sc[i].contests.collect {|c| c.name}.join(', ')
else
row << sc[i][0]
total += sc[i][0]
num_passed += 1 if sc[i][1]
end
end
row << total
row << num_passed
csv << row
end
end
end
add login stat
r410 end