<commit_before>require 'date'

class GreenhouseController < ApplicationController

  # GET /greenhouse
  # GET /greenhouse.json
  def index
    max_gh_timestamp = Greenhouse::DataPoint.maximum('timestamp');
    @current_gh_data = Greenhouse::DataPoint.where(timestamp: max_gh_timestamp).first
  end

  def hourly_average_temp_last_24_hours
    items = ForecastIo::Forecast.joins(:forecast_io_data).where(" master_timestamp >= ? AND type_id = ?", 1465023583 - 86400, 1).pluck(:time, :temperature)
    current_hour_timestamp = items.first[0]
    current_hour_total_temps = 0
    current_hour_temp_count = 0
    retval = Array.new
    items.each do |item|
      time = item[0]
      temp = item[1]
      if time > (current_hour_timestamp + 60*60)
        if current_hour_temp_count > 0
          ts = (current_hour_timestamp + time)/2
          dt = DateTime.strptime(String(ts),'%s')
          to = dt.to_time
          hour = '%02d' % to.hour
          avg = [hour, (current_hour_total_temps/current_hour_temp_count)]
          retval.push(avg)
          current_hour_timestamp = time
        end
      else
        current_hour_total_temps += temp
        current_hour_temp_count += 1
      end

    end
    return retval
  end

  private

end<commit_msg>Fixes for when data is not there to chart.<commit_after>require 'date'

class GreenhouseController < ApplicationController

  # GET /greenhouse
  # GET /greenhouse.json
  def index
    max_gh_timestamp = Greenhouse::DataPoint.maximum('timestamp');
    @current_gh_data = Greenhouse::DataPoint.where(timestamp: max_gh_timestamp).first
  end

  def hourly_average_temp_last_24_hours
    last_24_hours_timestamp = (Time.now - 86400).to_i
    items = ForecastIo::Forecast.joins(:forecast_io_data).where(" master_timestamp >= ? AND type_id = ?", last_24_hours_timestamp, 1).pluck(:time, :temperature)
    if !items.nil? && items.count > 0
      current_hour_timestamp = items.first[0]
      current_hour_total_temps = 0
      current_hour_temp_count = 0
      retval = Array.new
      items.each do |item|
        time = item[0]
        temp = item[1]
        if time > (current_hour_timestamp + 60*60)
          if current_hour_temp_count > 0
            ts = (current_hour_timestamp + time)/2
            dt = DateTime.strptime(String(ts),'%s')
            to = dt.to_time
            hour = '%02d' % to.hour
            avg = [hour, (current_hour_total_temps/current_hour_temp_count)]
            retval.push(avg)
            current_hour_timestamp = time
          end
        else
          current_hour_total_temps += temp
          current_hour_temp_count += 1
        end

      end
      return retval
    end
    return nil
  end

  private

end
{'fraction_non_alphanumeric': 0.09057301293900184, 'fraction_numerical': 0.021811460258780037, 'mean_word_length': 2.727272727272727, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 10, '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': '3940235', 'n_tokens_mistral': 902, 'n_tokens_neox': 845, 'n_words': 174}