<commit_before>module WatchTower
  module Server
    class TimeEntry < ::ActiveRecord::Base
      PAUSE_TIME = 30.minutes

      validates :file_id, presence: true
      validates :mtime, presence: true

      belongs_to :file, counter_cache: true

      after_create :calculate_work_time

      protected
        def calculate_work_time
          # Gather information about this and last time entry for this file
          this_time_entry = self
          last_time_entry = file.time_entries.where('id < ?', this_time_entry.id).order('id DESC').first

          # Calculate the time difference (0 if cannot calculate)
          time_entry_elapsed = this_time_entry.mtime - last_time_entry.mtime rescue 0
          # Record the last time entry we looked at
          file.last_id = this_time_entry.id
          # Not to be added to elapsed_time if it is considered a PAUSE
          unless time_entry_elapsed > PAUSE_TIME
            # Add the time
            file.elapsed_time += time_entry_elapsed
            file.project.elapsed_time += time_entry_elapsed

            file.save
          end
        end

    end
  end
end<commit_msg>Server: Give the function a more telling name.<commit_after>module WatchTower
  module Server
    class TimeEntry < ::ActiveRecord::Base
      PAUSE_TIME = 30.minutes

      validates :file_id, presence: true
      validates :mtime, presence: true

      belongs_to :file, counter_cache: true

      after_create :calculate_elapsed_time

      protected
        def calculate_elapsed_time
          # Gather information about this and last time entry for this file
          this_time_entry = self
          last_time_entry = file.time_entries.where('id < ?', this_time_entry.id).order('id DESC').first

          # Calculate the time difference (0 if cannot calculate)
          time_entry_elapsed = this_time_entry.mtime - last_time_entry.mtime rescue 0
          # Record the last time entry we looked at
          file.last_id = this_time_entry.id
          # Not to be added to elapsed_time if it is considered a PAUSE
          unless time_entry_elapsed > PAUSE_TIME
            # Add the time
            file.elapsed_time += time_entry_elapsed
            file.project.elapsed_time += time_entry_elapsed

            file.save
          end
        end

    end
  end
end
{'fraction_non_alphanumeric': 0.053471323846485556, 'fraction_numerical': 0.0034497628288055198, 'mean_word_length': 2.3285509325681493, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, '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': '2356391', 'n_tokens_mistral': 659, 'n_tokens_neox': 634, 'n_words': 196}