Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pull Request: C1_Akram_491_solve_contest_problem_5.20 #552

Closed
wants to merge 37 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
20caa37
Issue #455, fixing the console css
ahmedhagii May 9, 2014
9d56283
Issue #455, pushing input to stdin
ahmedhagii May 9, 2014
e2afb86
Issue #455, css modification
ahmedhagii May 9, 2014
7eaa903
Issue #491, ading the table_print gem
ahmedhagii May 12, 2014
c4fa541
Issue #491, generating the contests controller
ahmedhagii May 12, 2014
11a3586
Issue #491, dividing the problem page view
ahmedhagii May 13, 2014
2b66585
Issue #491, contest controller
ahmedhagii May 13, 2014
85c438a
Issue #491, modifying scripts
ahmedhagii May 13, 2014
a121d92
Issue #491, organizing problem page
ahmedhagii May 13, 2014
9a8404d
Issue #491, fxing conflicts
ahmedhagii May 13, 2014
00b8de1
Issue #491, fixing conflicts with master
ahmedhagii May 13, 2014
05efd40
Issue #491, grouping editor related stuff
ahmedhagii May 13, 2014
b7b0321
START
ahmedhagii May 13, 2014
5932274
fixing conflicts
ahmedhagii May 13, 2014
db1eb53
END
ahmedhagii May 13, 2014
5f9aa3f
Issue #491, fixing some functionalities
ahmedhagii May 13, 2014
60989dc
Issue #433, generalizing validate method and building a general rspec…
May 14, 2014
8b1699d
Issue #433, updating validate script for all types of problems in add…
May 14, 2014
b6f6da8
Issue #433, Adding logic of assignment problem in script
May 14, 2014
3454190
Issue #491, creating contest problem controller and views
ahmedhagii May 14, 2014
fb2c8c3
Issue #433, Fixing conflicts with master
May 14, 2014
9435be3
Issue #491, fixing conflicts with master
ahmedhagii May 14, 2014
7561655
Issue #433, Fixing bugs after resolving with master
May 14, 2014
91037d2
Issue #491, submit contest problem
ahmedhagii May 14, 2014
166c374
START
ahmedhagii May 14, 2014
1a73c8a
fixing
ahmedhagii May 14, 2014
e804d24
END
ahmedhagii May 14, 2014
dc88632
Issue #491, linking a student submission to the database
ahmedhagii May 14, 2014
71f2903
Issue #491, fixing conflicts with master
ahmedhagii May 14, 2014
a3ea990
Issue #491, adding documentation
ahmedhagii May 15, 2014
b47c48b
Issue #491, mofifying seeds
ahmedhagii May 15, 2014
b23329b
START
ahmedhagii May 15, 2014
f391dcf
fixing
ahmedhagii May 15, 2014
94aeda6
END
ahmedhagii May 15, 2014
36ccb5d
Issue #491, contest problems test cases are working now!
ahmedhagii May 15, 2014
49e4863
Issue #491, adding rspec tests
ahmedhagii May 16, 2014
61f8d00
Issue #491, fixing a bug
ahmedhagii May 16, 2014
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions tutor/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ gem 'rails', '4.0.4'

# User authentication
gem 'devise'
gem 'table_print'

# File uploading
gem 'carrierwave'
Expand Down Expand Up @@ -70,5 +71,4 @@ gem 'paperclip'

group :development, :test do
gem 'rspec-rails', '~> 3.0.0.beta'
end

end
2 changes: 2 additions & 0 deletions tutor/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ GEM
activesupport (>= 3.0)
sprockets (~> 2.8)
sqlite3 (1.3.9)
table_print (1.5.1)
thor (0.19.1)
thread_safe (0.3.3)
tilt (1.4.1)
Expand Down Expand Up @@ -203,6 +204,7 @@ DEPENDENCIES
sass-rails (~> 4.0.2)
sdoc
sqlite3
table_print
tire
uglifier (>= 1.3.0)
unicorn
Expand Down
3 changes: 3 additions & 0 deletions tutor/app/assets/javascripts/contests.js.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/
3 changes: 3 additions & 0 deletions tutor/app/assets/javascripts/cproblems.js.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/
27 changes: 24 additions & 3 deletions tutor/app/assets/javascripts/solutions.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ status = null
data: {code: input, problem_id: problem_id,\
class_name: class_name, problem_type: problem_type}
datatype: 'json'

success: (unique) ->
clear_console()
stop_spin()
Expand Down Expand Up @@ -328,14 +329,27 @@ debug_console = ->
variables = null;


# [Compiler: Validate - Story 3.5]
@contest_problem_submission = (status, contest_id, problem_id) ->
$.ajax
type: "POST"
url: '/cproblems/submit'
data: {cproblem_id: problem_id, contest_id: contest_id, status: status}
datatype: 'json'
success: (data) ->
return
return
# [
# Compiler: Validate - Story 3.5
# Compiler: Validare - Story X.7
# ]
# submits a solution in the form without refreshing
# using ajax showing an alert box for success and failure scenarios
# Parameters:
# problem_id: the id of the problem being solved
# problem_type: The type of the problem to be submitted
# Returns: a json object containing two arrays one for the errors
# of the current code and the other containing success messages
# in addition to the status of the submitted solution
# and the success and failure messages are displayed in a table
# Author: MOHAMEDSAEED
@validate_code = (problem_id, problem_type) ->
Expand All @@ -361,13 +375,19 @@ debug_console = ->
toggle_code_area()
if data['compiler_error']
compilation_error(data['compiler_output'])
contest_id = document.getElementById('contest_id').innerHTML
contest_problem_submission(0, contest_id, problem_id)
return
out = $('#validate_case')
out.html("")
content = ""
content = '<table class="table table-striped table-bordered
table-condensed table-hover" border="3">'
content += "<tr class='info'><th>TestCase</th><th>Status</th></tr>"
if problem_type == "Cproblem" || problem_type == "AssignmentProblem"
contest_id = document.getElementById('contest_id').innerHTML
contest_problem_submission(data[data.length - 1]['status'], contest_id, problem_id)
return
for i in data
if i['success']
content += "<tr><td>" + "<font color ='green'>#{i['test_case']}</font>" +
Expand All @@ -379,7 +399,7 @@ debug_console = ->
"</td>"
content += "<td>" + "<font color ='red'>#{i['response']}</font>"+
"</td></tr>"
out.html(content)
out.html(content)
return
error: (data) ->
clear_console()
Expand All @@ -394,7 +414,8 @@ debug_console = ->
# Returns: none
# Author: MOHAMEDSAEED
@reload_template = () ->
disabled = $('#solution_code').prop 'disabled'
editor = get_editor()
disabled = editor.getReadOnly()
unless disabled
template = "public class CoolSoft {\n"
template += "\tpublic static void main(String [] args) {\n\t\t\n\t}\n}"
Expand Down
3 changes: 3 additions & 0 deletions tutor/app/assets/stylesheets/contests.css.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Place all the styles related to the Contests controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
3 changes: 3 additions & 0 deletions tutor/app/assets/stylesheets/cproblems.css.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Place all the styles related to the Cproblems controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
13 changes: 11 additions & 2 deletions tutor/app/assets/stylesheets/solutions.css
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,11 @@ textarea {
border: #999999;
border-style: solid;
border-width: thin;
max-height: 150px;
min-height: 150px;
max-height: 100px;
min-height: 100px;
background: white;
overflow-y: scroll;
overflow-x: scroll;
overflow: auto;
max-width: 750px;
min-width: 750px;
Expand Down Expand Up @@ -114,4 +116,11 @@ textarea {

.hidden {
visibility: false;
}

.output {
white-space: pre;
color: black;
font-weight: bold;
font-size: 20px
}
6 changes: 6 additions & 0 deletions tutor/app/controllers/contests_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class ContestsController < ApplicationController

def create
end

end
1 change: 0 additions & 1 deletion tutor/app/controllers/courses_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,6 @@ def course_params
def find_state courses
states = Hash.new
student_id = current_student.id
puts student_id
courses.each do |c|
course_id = c.id
result = CourseStudent.where("student_id = ? AND course_id = ?",
Expand Down
56 changes: 56 additions & 0 deletions tutor/app/controllers/cproblems_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
class CproblemsController < ApplicationController

# [Solve Contest Problem - Story 5.20]
# View the selected problem from the contest
# Parameters:
# none
# Returns:
# @contest: the current opened contest
# @problem: the curretn opened problem
# Author: Ahmed Akram
def show
@contest = Contest.find_by_id(4)
@problem = Cproblem.find_by_id(params[:id])
if @problem.nil?
render "problem_not_found"
end
end

# [Solve Contest Problem - Story 5.20]
# Passes the information to the model to be inserted into the ContestProgress table
# Parameters:
# none
# Returns:
# none
# Author: Ahmed Akram
def submit
contest_id = get_params[:contest_id]
student_id = current_student.id
cproblem_id = get_params[:cproblem_id]
status = get_params[:status]
Cproblem.submit(contest_id, cproblem_id, student_id, status)
render json: {}
end

def create
end

def new
end

def index
end

# [Solve Contest Problem - Story 5.20]
# Permits the selected attributes
# Parameters:
# none
# Returns:
# a hash consisting of contest_id, problem_id and status
# Author: Ahmed Akram
private
def get_params
params.permit(:contest_id, :cproblem_id, :status)
end

end
1 change: 1 addition & 0 deletions tutor/app/controllers/problems_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class ProblemsController < ApplicationController
# Returns: none
# Author: MIMI
def show
@contest = Contest.find_by_id(params[:contest_id])
@problem = Problem.find_by_id(params[:id])
if @problem.nil?
render "problem_not_found"
Expand Down
3 changes: 3 additions & 0 deletions tutor/app/controllers/solutions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ class SolutionsController < ApplicationController
# Returns: none
# Author: MOHAMEDSAEED
def create
if lecturer_signed_in? || teaching_assistant_signed_in?
render json: {}
end
param = solution_params
code = param[:code]
student = current_student.id
Expand Down
3 changes: 1 addition & 2 deletions tutor/app/controllers/topics_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,7 @@ def sort
new_Order_Array = params[:methodParam]

@tracks.each do |track|
track.difficulty = (params[:methodParam]).index(track.id.to_s) + 1
puts(track.save)
track.difficulty = (params[:methodParam]).index(track.id.to_s) + 1
end
render :nothing => true
end
Expand Down
2 changes: 2 additions & 0 deletions tutor/app/helpers/contests_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module ContestsHelper
end
2 changes: 2 additions & 0 deletions tutor/app/helpers/cproblems_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module CproblemsHelper
end
37 changes: 36 additions & 1 deletion tutor/app/models/cproblem.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,40 @@ class Cproblem < ActiveRecord::Base
#Scoops

#Methods
# [Solve Contest Problem - Story 5.20]
# Passes the information to the model to be inserted into the ContestProgress table
# Parameters:
# contest_id: the id of the contest
# cproblem_id: the id of the problem being solved
# student_id: the solver id
# _status: the status of the solution
# Returns:
# none
# Author: Ahmed Akram
def self.submit(contest_id, cproblem_id, student_id, _status)
contest_end_time = Contest.find_by_id(contest_id).end_time.to_time
problem_submission_time = DateTime.now.to_time
if _status.to_i == 1
status = 1
else
status = 0
end
cp = ContestProgress.where(student_id: student_id, contest_id: contest_id,
cproblem_id: cproblem_id)[0]
if !cp
cp = ContestProgress.create(contest_id: contest_id, student_id: student_id,
cproblem_id: cproblem_id, status: false, trials: 0)
cp.save
end
if cp.status == false
if(contest_end_time - problem_submission_time > 0)
if status == 1
cp.status = true
end
cp.trials = cp.trials + 1
cp.save
end
end
end

end
end
19 changes: 10 additions & 9 deletions tutor/app/models/java_executer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ def self.execute(sol, input)
folder_name = @solution.folder_name
validity = check_input_validity(input, @solution.problem.id)
if validity[:status]
echo_input = 'echo ' + '\'' + input + '\'' + ' | '
Dir.chdir(Solution::SOLUTION_PATH + folder_name) {
@execute_res = %x[#{'java ' + file_name + ' ' + input + ' 2>&1'}]
@execute_res = %x[#{echo_input + 'java ' + file_name}]
}
if @execute_res.include?("Exception")
return {executer_feedback: false, executer_output: get_runtime_error()}
Expand Down Expand Up @@ -56,14 +57,14 @@ def self.create_solution(student_id, problem_id, code, input)
# A hash [status, msg], where status is true or false and msg is costume explaining message
# Author: Ahmed Akram
def self.check_input_validity(input, problem_id)
variables_number = Problem.find_by_id(problem_id).test_cases.first.input.split(" ").count
if input.include?("\n")
return {status: false, msg: "Input can not have line breaks \"don't use enter\""}
end
if input.split(" ").count != variables_number
msg = "Enter only " + variables_number.to_s + " numbers"
return {status: false, msg: msg}
end
variables_number = Cproblem.find_by_id(problem_id).test_cases.first.input.split(" ").count
# if input.include?("\n")
# return {status: false, msg: "Input can not have line breaks \"don't use enter\""}
# end
# if input.split(" ").count != variables_number
# msg = "Enter only " + variables_number.to_s + " numbers"
# return {status: false, msg: msg}
# end
return {status: true, msg: nil}
end

Expand Down
15 changes: 10 additions & 5 deletions tutor/app/models/solution.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,18 @@ class Solution < ActiveRecord::Base
# Parameters:
# solution: the solution to be validated
# testcases: the testcases that will test the submitted code
# langauge: the language of the submitted solution
# Returns: a hash response containing status for the solution,
# solution errors or success message.
# Author: MOHAMEDSAEED
def self.validate(solution, test_cases)
def self.validate(solution, test_cases, language)
executer = language.capitalize + "Executer"
executer = eval(executer)
response = []
test_cases.each do |testcase|
input = testcase.input
expected_output = testcase.output
runtime_check = JavaExecuter.execute(solution, input)
runtime_check = executer.execute(solution, input)
if(runtime_check[:executer_feedback])
output = runtime_check[:executer_output][:message]
if (output != expected_output)
Expand All @@ -35,13 +38,14 @@ def self.validate(solution, test_cases)
end
response << {success: false, test_case: input,
response: "Logic error: Expected output: " +
expected_output.to_s.strip + ", but your output was: " + output}
expected_output.to_s.strip + ", but your output was: " + output,
last: false}
unless solution.status == 4
solution.status = 5
end
else
response << {success: true, test_case: input,
response: "Passed!"}
response: "Passed!", last: false}
unless solution.status == 4 | 5
solution.status = 1
end
Expand All @@ -51,9 +55,10 @@ def self.validate(solution, test_cases)
explanation = get_response(runtime_error)
solution.status = 4
response << {success: false, test_case: input,
response: "Runtime error: " + explanation}
response: "Runtime error: " + explanation, last: false}
end
end
response << {status: solution.status, last: true}
solution.save
return response
end
Expand Down
Loading