Show More
Commit Description:
fix logins user_id from string to integer
Commit Description:
fix logins user_id from string to integer
References:
File last commit:
Show/Diff file:
Action:
app/controllers/report_controller.rb | 258 lines | 8.1 KiB | text/x-ruby | RubyLexer |
add login stat
r410 class ReportController < ApplicationController
add problem stat
r400
fix bug for "stuck" and add authorization
r464 before_filter :admin_authorization, only: [:login_stat,:submission_stat, :stuck]
prepare for better hall of fame
r425 before_filter(only: [:problem_hof]) { |c|
add options to allow hall of fame viewing by any user...
r424 return false unless authenticate
prepare for better hall of fame
r425 if GraderConfiguration["right.user_view_submission"]
add options to allow hall of fame viewing by any user...
r424 return true;
save point
r423 end
add options to allow hall of fame viewing by any user...
r424
admin_authorization
save point
r423 }
add problem stat
r400
add login stat
r410 def login_stat
@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
(in progress) add date range
r412
add login stat
r410 User.all.each do |user|
add user profile page listing all submission, permission is by 'right.user_view_submission'...
r431 @logins << { id: user.id,
login: user.login,
add login stat
r410 full_name: user.full_name,
add submission report
r413 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)
report ip
r442 .maximum(:created_at),
ip: Login.where("user_id = ? AND created_at >= ? AND created_at <= ?",
user.id,@since_time,@until_time)
.select(:ip_address).uniq
add submission report
r413 }
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|
fix submission report, when submissions belong no non-existing user
r415 if @submissions[s.user_id]
if not @submissions[s.user_id][:sub].has_key?(s.problem_id)
add submission report
r413 a = nil
fix submission report, when submissions belong no non-existing user
r415 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
add submission report
r413 end
fix submission report, when submissions belong no non-existing user
r415 @submissions[s.user_id][:count] += 1
add submission report
r413 end
add login stat
r410 end
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
if sub.submitted_at and sub.submitted_at < @by_lang[lang.pretty_name][:first][:value] and
!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
end
add login stat
r410 end