Skip to content

Commit

Permalink
Merge pull request alaashafaee#308 from alaashafaee/CX_Rami_192_Execu…
Browse files Browse the repository at this point in the history
…te_Line_By_Line_3.8

CX: Implementing Solution File Naming Methods
  • Loading branch information
KhaledHelmy committed Apr 22, 2014
2 parents 4446de5 + 15c4fea commit c42e0c0
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 18 deletions.
46 changes: 34 additions & 12 deletions tutor/app/assets/javascripts/solutions.js.coffee
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# The list of variables
Variables = null
variables = null
# The number of the current index of the line to be executed
IndexNumber = 0
indexNumber = 0

# [Debugger: Debug - Story 3.6]
# Sends the code to the server and changes the Variables to the data recieved
Expand All @@ -12,23 +12,17 @@ IndexNumber = 0
@start_debug = (problem_id) ->
input = $('#solution_code').val()
test = $('#testcases').val()
alert input
alert test
start_spin()
$.ajax
type: "POST"
url: '/debuggers/' + problem_id
data: {code : input , case : test}
datatype: 'json'
success: (data) ->
$('#nextButton').attr "disabled", false
$('#previousButton').attr "disabled", true
toggleDebug()
Variables = data
variables = data
stop_spin()
for datum in data
alert "#{datum['line']}=>#{datum['locals']}locals is Empty for now"
return
highlight_line data[0]['line']
error: ->
stop_spin()
return
Expand Down Expand Up @@ -82,7 +76,12 @@ IndexNumber = 0
# Returns: none
# Author: Rami Khalil
@next = () ->
alert "Next Step"
if indexNumber + 1 < variables.length
jump_state ++indexNumber
else if(indexNumber == 99)
alert "The online debugger can only step forward 100 times."
else
alert "The program has terminated."

# [Execute Line By Line - Story 3.8]
# Moves to the previous state of execution.
Expand All @@ -91,7 +90,28 @@ IndexNumber = 0
# Returns: none
# Author: Rami Khalil
@previous = () ->
alert "Previous Step"
if indexNumber > 0
jump_state --indexNumber
else
alert "This is the first step in the program."

# [Execute Line By Line - Story 3.8]
# Highlights the target line number in the editor
# Parameters:
# line: The line number to highlight.
# Returns: none
# Author: Rami Khalil
@highlight_line = (line) ->
alert "At line: " + line

# [Execute Line By Line - Story 3.8]
# Jumps to the target state by highlighting the line and showing variables
# Parameters:
# stateNumber: The target state number.
# Returns: none
# Author: Rami Khalil
@jump_state = (stateNumber) ->
highlight_line variables[stateNumber]['line']

# [Debug - Story 3.6]
# Stops the debugging session.
Expand All @@ -101,3 +121,5 @@ IndexNumber = 0
# Author: Rami Khalil (Temporary)
@stop = () ->
toggleDebug()
indexNumber = 0;
variables = null;
6 changes: 3 additions & 3 deletions tutor/app/models/debugger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Debugger < ActiveRecord::Base
# regex : The input regex to be encountered to return
# Returns: A String of the buffer
# Author: Rami Khalil
def buffer_until regex
def buffer_until(regex)
buffer = ""
until !$wait_thread.alive? or regex.any? { |expression| buffer =~ expression } do
begin
Expand Down Expand Up @@ -53,7 +53,7 @@ def buffer_until_complete
# input : The input to be written in the sub stream
# Returns: none
# Author: Rami Khalil
def input input
def input(input)
$input.puts input
end

Expand All @@ -64,7 +64,7 @@ def input input
# file_path : The path of the file to debugged
# input : The arguments to be passed to the main method
# Returns: A List of all 100 steps ahead
# Author: Mussab ElDash
# Authors: Mussab ElDash + Rami Khalil
def start(file_path, input)
to_be_compiled = file_path
if file_path =~ /.*\.java/
Expand Down
52 changes: 52 additions & 0 deletions tutor/app/models/solution.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,61 @@ class Solution < ActiveRecord::Base
#Scoops

#Methods
# [
# Compiler: Compile - Story 3.4
# Compiler: Validate - Story 3.5
# Debugger: Debug - Story 3.6
# Compiler: Test - Story 3.15
# ]
# Returns the file name associated with this solution code.
# Parameters:
# append_extension: A boolean value deciding whether the file extension should be appended.
# Returns: The solution's java file name
# Author: Rami Khalil
def file_name
return 'st' + student_id.to_s + 'pr' + problem_id.to_s + 'so' + id.to_s
end

# [
# Compiler: Compile - Story 3.4
# Compiler: Validate - Story 3.5
# Debugger: Debug - Story 3.6
# Compiler: Test - Story 3.15
# ]
# Returns the java file name associated with this solution code.
# Parameters:
# append_extension: A boolean value deciding whether the file extension should be appended.
# Returns: The solution's java file name
# Author: Rami Khalil
def java_file_name(prepend_path = false, append_extension = false)
jfile_name = file_name
jfile_name += ".java" if append_extension
jfile_name = JAVA_PATH + jfile_name if prepend_path
return jfile_name
end

# [
# Compiler: Compile - Story 3.4
# Compiler: Validate - Story 3.5
# Debugger: Debug - Story 3.6
# Compiler: Test - Story 3.15
# ]
# Returns the class file name associated with this solution code.
# Parameters:
# append_extension: A boolean value deciding whether the file extension should be appended.
# Returns: The solution's class file name
# Author: Rami Khalil
def class_file_name(prepend_path = false, append_extension = false)
jfile_name = file_name
jfile_name += ".class" if append_extension
jfile_name = CLASS_PATH + jfile_name if prepend_path
return jfile_name
end

#Constants
STATUS_SUBMITTED = 0
STATUS_ACCEPTED = 1

JAVA_PATH = 'students_solutions/Java/'
CLASS_PATH = 'students_solutions/Class/'
end
2 changes: 1 addition & 1 deletion tutor/app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
<div class="row">
<%= render "layouts/right_side_bar"%>
<div class="well main-content">
<%= render "problems/system_recommendation" if student_signed_in?%>
<%= render "problems/system_recommendation" if student_signed_in? %>
<%= yield %>
</div>
</div>
Expand Down
4 changes: 2 additions & 2 deletions tutor/db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@
Solution.create(code:"println(My third solution)", length:5, status:3)

puts("# -----------------------TrackProgression---------------------------")
TrackProgression.create(level: 2, student_id: 1, topic_id: 1)
TrackProgression.create(level: 0, student_id: 1, topic_id: 2)
TrackProgression.create(level: 0, student_id: 1, topic_id: 1)
TrackProgression.create(level: 2, student_id: 1, topic_id: 2)

puts("# -----------------------Attempts---------------------------")
Attempt.create(success: true)
Expand Down

0 comments on commit c42e0c0

Please sign in to comment.