Description:
fix utf8 for java
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r462:c960ef68f0b1 - - 2 files changed: 3 inserted, 1 deleted

@@ -54,25 +54,26
54 def help
54 def help
55 @user = User.find(session[:user_id])
55 @user = User.find(session[:user_id])
56 end
56 end
57
57
58 def submit
58 def submit
59 user = User.find(session[:user_id])
59 user = User.find(session[:user_id])
60
60
61 @submission = Submission.new
61 @submission = Submission.new
62 @submission.problem_id = params[:submission][:problem_id]
62 @submission.problem_id = params[:submission][:problem_id]
63 @submission.user = user
63 @submission.user = user
64 @submission.language_id = 0
64 @submission.language_id = 0
65 if (params['file']) and (params['file']!='')
65 if (params['file']) and (params['file']!='')
66 - @submission.source = params['file'].read
66 + @submission.source = File.open(params['file'].path,'r:UTF-8',&:read)
67 + @submission.source.encode!('UTF-8','UTF-8',invalid: :replace, replace: '')
67 @submission.source_filename = params['file'].original_filename
68 @submission.source_filename = params['file'].original_filename
68 end
69 end
69 @submission.submitted_at = Time.new.gmtime
70 @submission.submitted_at = Time.new.gmtime
70 @submission.ip_address = request.remote_ip
71 @submission.ip_address = request.remote_ip
71
72
72 if GraderConfiguration.time_limit_mode? and user.contest_finished?
73 if GraderConfiguration.time_limit_mode? and user.contest_finished?
73 @submission.errors.add_to_base "The contest is over."
74 @submission.errors.add_to_base "The contest is over."
74 prepare_list_information
75 prepare_list_information
75 render :action => 'list' and return
76 render :action => 'list' and return
76 end
77 end
77
78
78 if @submission.valid?
79 if @submission.valid?
@@ -115,24 +115,25
115
115
116 range = 120
116 range = 120
117 @histogram = { data: Array.new(range,0), summary: {} }
117 @histogram = { data: Array.new(range,0), summary: {} }
118 @summary = {count: 0, solve: 0, attempt: 0}
118 @summary = {count: 0, solve: 0, attempt: 0}
119 problem = Hash.new(0)
119 problem = Hash.new(0)
120
120
121 @submission.find_each do |sub|
121 @submission.find_each do |sub|
122 #histogram
122 #histogram
123 d = (DateTime.now.in_time_zone - sub.submitted_at) / 24 / 60 / 60
123 d = (DateTime.now.in_time_zone - sub.submitted_at) / 24 / 60 / 60
124 @histogram[:data][d.to_i] += 1 if d < range
124 @histogram[:data][d.to_i] += 1 if d < range
125
125
126 @summary[:count] += 1
126 @summary[:count] += 1
127 + next unless sub.problem
127 problem[sub.problem] = [problem[sub.problem], (sub.points >= sub.problem.full_score) ? 1 : 0].max
128 problem[sub.problem] = [problem[sub.problem], (sub.points >= sub.problem.full_score) ? 1 : 0].max
128 end
129 end
129
130
130 @histogram[:summary][:max] = [@histogram[:data].max,1].max
131 @histogram[:summary][:max] = [@histogram[:data].max,1].max
131 @summary[:attempt] = problem.count
132 @summary[:attempt] = problem.count
132 problem.each_value { |v| @summary[:solve] += 1 if v == 1 }
133 problem.each_value { |v| @summary[:solve] += 1 if v == 1 }
133 end
134 end
134
135
135 protected
136 protected
136
137
137 def verify_online_registration
138 def verify_online_registration
138 if !GraderConfiguration['system.online_registration']
139 if !GraderConfiguration['system.online_registration']
You need to be logged in to leave comments. Login now