Skip to content

Commit

Permalink
cambios que luego quitare :o
Browse files Browse the repository at this point in the history
  • Loading branch information
mikeki committed Nov 11, 2011
1 parent 464f82c commit 2fd9497
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 5 deletions.
Binary file modified algorithm_app/clib/algorithms.o
Binary file not shown.
Binary file modified algorithm_app/clib/libalgorithms.so
Binary file not shown.
1 change: 1 addition & 0 deletions app/models/exercise.rb
Expand Up @@ -3,5 +3,6 @@ class Exercise < ActiveRecord::Base
belongs_to :course
belongs_to :user
has_many :source_codes, :class_name => "SourceCode", :foreign_key => :exercise_id
has_many :similarities

end
7 changes: 6 additions & 1 deletion app/models/similarity.rb
Expand Up @@ -6,10 +6,12 @@ class Similarity < ActiveRecord::Base
belongs_to :source_code1, :class_name=> "SourceCode", :foreign_key => :source_code1_id
belongs_to :source_code2, :class_name=> "SourceCode", :foreign_key => :source_code2_id
has_many :algorithms
belongs_to :exercise


def self.create_from_response(response)
similarities = []
json = ActiveSupport::JSON
case response
when Net::HTTPSuccess, Net::HTTPRedirection
json.decode(response.body).each do |data_hash|
Expand All @@ -20,7 +22,7 @@ def self.create_from_response(response)
similarity = Similarity.new
similarity.source_code1_id = similarity1_id
similarity.source_code2_id = similarity2_id
similarity.algorithm.build(:type=>key, :percentage=>percentage)
similarity.algorithms.build(:type=>key.to_i, :percentage=>percentage)
#similarity.similarity = percentage
#similarity.save

Expand All @@ -29,6 +31,9 @@ def self.create_from_response(response)
end
end
Similarity.import similarities, :validate => false
similarities.each do |similarity|
Algorithm.import similarity.algorithms
end
else
response.error!
end
Expand Down
10 changes: 7 additions & 3 deletions app/views/source_codes/compare.html.erb
Expand Up @@ -2,15 +2,19 @@
<tr>
<th>File 1</th>
<th>File2</th>
<th>Algoritmo usado</th>
<th>Algoritmo 1</th>
<th>Algoritmo 2</th>
<th>ALgoritmo 3</th>
<th>Porcentaje</th>
</tr>
<% @similarities.each do |sim|%>
<tr>
<td><%= sim.source_code1.student_id%></td>
<td><%= sim.source_code2.student_id%></td>
<td><%= sim.used_algorithm%></td>
<td><%= sim.similarity%></td>
<td><%= sim.algorithms.first.percentage %></td>
<td><%= sim.algorithms.first.percentage %></td>
<td><%= sim.algorithms.first.percentage %></td>
<td><%= sim.algorithms.select("AVG(percentage)").first.percentage %></td>
</tr>
<%end%>
</table>
9 changes: 9 additions & 0 deletions db/migrate/20111106010434_add_exercise_to_similarities.rb
@@ -0,0 +1,9 @@
class AddExerciseToSimilarities < ActiveRecord::Migration
def self.up
add_column :similarities, :exercise_id, :integer
end

def self.down
remove_column :similarities, :exercise
end
end
3 changes: 2 additions & 1 deletion db/schema.rb
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended to check this file into your version control system.

ActiveRecord::Schema.define(:version => 20111031011254) do
ActiveRecord::Schema.define(:version => 20111106010434) do

create_table "algorithms", :force => true do |t|
t.integer "type"
Expand Down Expand Up @@ -43,6 +43,7 @@
t.integer "source_code2_id"
t.datetime "created_at"
t.datetime "updated_at"
t.integer "exercise_id"
end

create_table "source_codes", :force => true do |t|
Expand Down

0 comments on commit 2fd9497

Please sign in to comment.