<commit_before>class ResponseMap < ActiveRecord::Base
  has_many :response, foreign_key: 'map_id', dependent: :destroy
  belongs_to :reviewer, :class_name => 'Participant', :foreign_key => 'reviewer_id'

  def map_id
    id
  end

  # return latest versions of the responses
  def self.get_assessments_for(participant)
    responses = Array.new
    stime=Time.now
    if participant

      @array_sort=Array.new
      @sort_to=Array.new

      #get all the versions
      maps = where(reviewee_id: participant.id)
      maps.each { |map|
        if !map.response.empty?

          @all_resp=Response.find_by_map_id(map.map_id)
          @array_sort << @all_resp

          #sort all versions in descending order and get the latest one.
          #@sort_to=@array_sort.sort { |m1, m2| (m1.version_num and m2.version_num) ? m2.version_num <=> m1.version_num : (m1.version_num ? -1 : 1) }
          @sort_to=@array_sort.sort #{ |m1, m2| (m1.updated_at and m2.updated_at) ? m2.updated_at <=> m1.updated_at : (m1.version_num ? -1 : 1) }
          responses << @sort_to[0]
          @array_sort.clear
          @sort_to.clear
        end
      }
      responses = responses.sort { |a, b| a.map.reviewer.fullname <=> b.map.reviewer.fullname }
    end<commit_msg>Bug fix: use the new version (updated ones) of review to calculate scores<commit_after>class ResponseMap < ActiveRecord::Base
  has_many :response, foreign_key: 'map_id', dependent: :destroy
  belongs_to :reviewer, :class_name => 'Participant', :foreign_key => 'reviewer_id'

  def map_id
    id
  end

  # return latest versions of the responses
  def self.get_assessments_for(participant)
    responses = Array.new
    stime=Time.now
    if participant

      @array_sort=Array.new
      @sort_to=Array.new

      #get all the versions
      maps = where(reviewee_id: participant.id)
      maps.each { |map|
        if !map.response.empty?

          @all_resp=Response.where(map_id: map.map_id).last
          @array_sort << @all_resp

          #sort all versions in descending order and get the latest one.
          #@sort_to=@array_sort.sort { |m1, m2| (m1.version_num and m2.version_num) ? m2.version_num <=> m1.version_num : (m1.version_num ? -1 : 1) }
          @sort_to=@array_sort.sort #{ |m1, m2| (m1.updated_at and m2.updated_at) ? m2.updated_at <=> m1.updated_at : (m1.version_num ? -1 : 1) }
          responses << @sort_to[0]
          @array_sort.clear
          @sort_to.clear
        end
      }
      responses = responses.sort { |a, b| a.map.reviewer.fullname <=> b.map.reviewer.fullname }
    end
{'fraction_non_alphanumeric': 0.11616161616161616, 'fraction_numerical': 0.014763014763014764, 'mean_word_length': 2.8035450516986704, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4861398', 'n_tokens_mistral': 914, 'n_tokens_neox': 896, 'n_words': 198}