<commit_before>class Topic < ActiveRecord::Base
  has_many :charts
  has_many :responses, through: :charts

  validates_presence_of :name

  include ResponsesHelper

  # def responses_json
  #   self.charts.map { |c| { chart: c, responses: bucketize_responses(c.responses) } }
  # end

  def responses_json
    keyed_json = {}
    self.charts.each do |c|
      sorted_responses = c.responses.order("date ASC").limit(3).sort_by { |r| r.percentage.to_f }
      keyed_json[c.state] = { responses: sorted_responses,
                              fillKey: sorted_responses.last.answer }
    end
    return keyed_json
  end

end<commit_msg>Update responses_json method to return a timeline of data<commit_after>class Topic < ActiveRecord::Base
  has_many :charts
  has_many :responses, through: :charts

  validates_presence_of :name

  include ResponsesHelper

  def responses_json
    timeline_array = Array.new(30) { Hash.new }
    self.charts.each do |c|
      response_chunks = bucketize_responses(c.responses)
      response_chunks.each_with_index do |chunk, index|
        timeline_array[index][c.state] = chunk
      end
    end
    return timeline_array
  end

end
{'fraction_non_alphanumeric': 0.08654670094258783, 'fraction_numerical': 0.002570694087403599, 'mean_word_length': 3.342007434944238, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '1831849', 'n_tokens_mistral': 398, 'n_tokens_neox': 378, 'n_words': 85}