<commit_before>class ApiController < ApplicationController

  # GET
  def harvest_data
    harvest = Harvest.client(subdomain: ENV["HARVEST_SUBDOMAIN"],
                             username: ENV["HARVEST_USERNAME"],
                             password: ENV["HARVEST_PASSWORD"])

    today = Date.today
    today -= 1.day if Time.now.hour < 7
    today += params[:days].to_i.days
    human_today = today.to_time.strftime("%A, #{today.to_time.day.ordinalize}")

    monday = today
    monday -= 1.day until monday.monday?
    days_and_hours_this_week = (monday..today).map do |date|
      harvest_time_data = harvest.time.all(date)
      total_hours_this_date = harvest_time_data.map{|x| x[:hours] }.inject(:+)
      { date: date,
        hours: (harvest_time_data.map{ |x| {x[:project] => x[:hours]} } <<
          { "Total" => total_hours_this_date || 0 }).
          inject(:merge)
      }
    end

    days_and_hours_this_week.each do |hash|
      hash.values.each do |value|
        value ||= 0
      end
    end

    hours_this_week = 0
    days_and_hours_this_week.each do |hash|
      hours_this_day = hash[:hours]["Total"]
      hours_this_week += hours_this_day if hours_this_day.respond_to?(:+)
    end

    hours_today = days_and_hours_this_week.last[:hours]["Total"]
    hours_today ||= 0

    hours_owed =  (8 * (days_and_hours_this_week.length - 1)) -
      (hours_this_week - hours_today)

    hours_needed_today = 40 - hours_this_week
    unless today.friday? || today.sunday? || today.saturday?
      if hours_needed_today > (8 + hours_owed)
        hours_needed_today = (8 + hours_owed)
      end
      hours_needed_today -= hours_today<commit_msg>Fix silly bug (a < was a >)<commit_after>class ApiController < ApplicationController

  # GET
  def harvest_data
    harvest = Harvest.client(subdomain: ENV["HARVEST_SUBDOMAIN"],
                             username: ENV["HARVEST_USERNAME"],
                             password: ENV["<PASSWORD>"])

    today = Date.today
    today -= 1.day if Time.now.hour < 7
    today += params[:days].to_i.days
    human_today = today.to_time.strftime("%A, #{today.to_time.day.ordinalize}")

    monday = today
    monday -= 1.day until monday.monday?
    days_and_hours_this_week = (monday..today).map do |date|
      harvest_time_data = harvest.time.all(date)
      total_hours_this_date = harvest_time_data.map{|x| x[:hours] }.inject(:+)
      { date: date,
        hours: (harvest_time_data.map{ |x| {x[:project] => x[:hours]} } <<
          { "Total" => total_hours_this_date || 0 }).
          inject(:merge)
      }
    end

    days_and_hours_this_week.each do |hash|
      hash.values.each do |value|
        value ||= 0
      end
    end

    hours_this_week = 0
    days_and_hours_this_week.each do |hash|
      hours_this_day = hash[:hours]["Total"]
      hours_this_week += hours_this_day if hours_this_day.respond_to?(:+)
    end

    hours_today = days_and_hours_this_week.last[:hours]["Total"]
    hours_today ||= 0

    hours_owed =  (8 * (days_and_hours_this_week.length - 1)) -
      (hours_this_week - hours_today)

    hours_needed_today = 40 - hours_this_week
    unless today.friday? || today.sunday? || today.saturday?
      if hours_needed_today < (8 + hours_owed)
        hours_needed_today = (8 + hours_owed)
      end
      hours_needed_today -= hours_today
{'fraction_non_alphanumeric': 0.12200956937799043, 'fraction_numerical': 0.00777511961722488, 'mean_word_length': 2.716666666666667, 'pattern_counts': {'":': 0, '<': 14, '<?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': '2115534', 'n_tokens_mistral': 1227, 'n_tokens_neox': 1133, 'n_words': 209}