<commit_before>class StatsController < ApplicationController
  def index
    @title = "Stats for #{current_user.profile.first_name or current_user.username}"
    @h = LazyHighCharts::HighChart.new('graph') do |f|
      records = current_user.workout_records
      records = records.where( :date_performed => (Date.today - 30.days)..Date.today ).order("date_performed DESC")
      points, times = [], []
      records.each do |r|
        # Convert date_performed to number of milliseconds since the epoch for JS charting
        points << [(r.date_performed.to_time.tv_sec * 1000), r.points] if r.points
        times << r.time[:insecs] if r.time
      end
      puts "Points: #{points.to_s}"
      puts "Times: #{times.to_s}"

      f.options[:x_axis] = { :type => 'datetime' }
      f.series :name => 'Points', :data => points
      # f.series :name => 'Times', :data => times<commit_msg>added ternary operation to check if profile is defined before trying to access first_name in stats controller<commit_after>class StatsController < ApplicationController
  def index
    @title = "Stats for #{current_user.profile ? current_user.profile.first_name : current_user.username}"
    @h = LazyHighCharts::HighChart.new('graph') do |f|
      records = current_user.workout_records
      records = records.where( :date_performed => (Date.today - 30.days)..Date.today ).order("date_performed DESC")
      points, times = [], []
      records.each do |r|
        # Convert date_performed to number of milliseconds since the epoch for JS charting
        points << [(r.date_performed.to_time.tv_sec * 1000), r.points] if r.points
        times << r.time[:insecs] if r.time
      end
      puts "Points: #{points.to_s}"
      puts "Times: #{times.to_s}"

      f.options[:x_axis] = { :type => 'datetime' }
      f.series :name => 'Points', :data => points
      # f.series :name => 'Times', :data => times
{'fraction_non_alphanumeric': 0.13343881856540085, 'fraction_numerical': 0.006329113924050633, 'mean_word_length': 3.234375, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 15, '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': '955068', 'n_tokens_mistral': 601, 'n_tokens_neox': 579, 'n_words': 157}