<commit_before>module Graphable
  module ClassMethods
    
  end
  
  module InstanceMethods

    def lines
      [{
        :name => "actual temperature", 
        :data => self.chart_hash
      },
      {
        :name => "legal minimum", 
        :data => self.legal_hash
      }]
    end
    
    def bars
      {"Avg Day" => avg_day_temp, "Avg Night" => avg_night_temp}
    end

    def chart_hash
      if readings.empty?
        return {Time.now => 0} 
      else
        reading_hash
      end
    end

    def legal_hash
      reading_time_array.each_with_object({}) do |time, legal_hash|
        hour = time.hour + time_offset_in_hours
        
        if day_time_hours_include?(hour)
          legal_hash[time] = day_time_legal_requirement
        else
          legal_hash[time] = night_time_legal_requirement
        end
      end
    end

    def temps_with_legal_requirement
      temps | legal_requirement_array
    end

    def legal_requirement_array
      [day_time_legal_requirement, night_time_legal_requirement]
    end

    def day_time_legal_requirement
      68
    end

    def night_time_legal_requirement
      55
    end

    def temps
      readings.pluck(:temp)
    end

    def range(margin = 5)
      {min: self.range_min - margin, max: self.range_max + margin}
    end

    def range_min
      self.temps_with_legal_requirement.min
    end

    def range_max
      self.temps_with_legal_requirement.max
    end

    def reading_time_array
      readings.pluck(:created_at)
    end

    def reading_hash
      readings.pluck(:created_at, :temp).to_h
    end

    def avg_day_temp
      day_temps = self.get_day_temps
      return 0 if day_temps.empty?

      sum_of_temps = day_temps.sum <commit_msg>replace to_h function for backwards compatibility to ruby 1.9<commit_after>module Graphable
  module ClassMethods
    
  end
  
  module InstanceMethods

    def lines
      [{
        :name => "actual temperature", 
        :data => self.chart_hash
      },
      {
        :name => "legal minimum", 
        :data => self.legal_hash
      }]
    end
    
    def bars
      {"Avg Day" => avg_day_temp, "Avg Night" => avg_night_temp}
    end

    def chart_hash
      if readings.empty?
        return {Time.now => 0} 
      else
        reading_hash
      end
    end

    def legal_hash
      reading_time_array.each_with_object({}) do |time, legal_hash|
        hour = time.hour + time_offset_in_hours
        
        if day_time_hours_include?(hour)
          legal_hash[time] = day_time_legal_requirement
        else
          legal_hash[time] = night_time_legal_requirement
        end
      end
    end

    def temps_with_legal_requirement
      temps | legal_requirement_array
    end

    def legal_requirement_array
      [day_time_legal_requirement, night_time_legal_requirement]
    end

    def day_time_legal_requirement
      68
    end

    def night_time_legal_requirement
      55
    end

    def temps
      readings.pluck(:temp)
    end

    def range(margin = 5)
      {min: self.range_min - margin, max: self.range_max + margin}
    end

    def range_min
      self.temps_with_legal_requirement.min
    end

    def range_max
      self.temps_with_legal_requirement.max
    end

    def reading_time_array
      readings.pluck(:created_at)
    end

    def reading_hash
      # readings.pluck(:created_at, :temp).to_h // done with helper methods until tristan upgrades to ruby 2.1
      hashify(reading_nested_array)
    end

    def reading_nested_array
      readings.pluck(:created_at, :temp)
    end

    def hashify(nested_array)
      nested_array.each_with_object({}) { |pair, hsh| hsh[pair[0]] = pair[1] }
    end

    def avg_day_temp
      day_temps = self.get_day_temps
      return 0 if day_temps.empty?

      sum_of_temps = day_temps.sum 
{'fraction_non_alphanumeric': 0.06554798112218144, 'fraction_numerical': 0.005243838489774515, 'mean_word_length': 2.184474123539232, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, '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': '4489979', 'n_tokens_mistral': 1286, 'n_tokens_neox': 1228, 'n_words': 268}