<commit_before>namespace :scholarsphere do
  namespace :analytic do

    desc "Load data from a file of format # dd/mmm/yyyy /downloads/<id> and stores the appropriate record for each file line in the file_downloads table"
    task :load, [:filename] => :environment  do |t, args|
      File.open(args[:filename]).each(sep="\n") do |line|
        next if line.strip.size == 0
        parts = line.split
        count = parts[0].to_i
        date = Date.parse(parts[1])
        id = parts[2].split( /\//).last
        next if id == "downloads"
        id = "scholarsphere:#{id.split("?").first}"
        stat = FileDownloadStat.where(date: date, file_id: id).first
        if stat.blank?
          FileDownloadStat.create(date: date, downloads: count, file_id: id)
        elsif (stat.downloads < count)
          puts "Updating count"
          stat.downloads = count
          stat.save
        end
      end
    end

  end
end<commit_msg>Adding user id to the FileDownloadStat in rake task now that it is part of the table. refs #9557<commit_after>namespace :scholarsphere do
  namespace :analytic do

    desc "Load data from a file of format # dd/mmm/yyyy /downloads/<id> and stores the appropriate record for each file line in the file_downloads table"
    task :load, [:filename] => :environment  do |t, args|
      File.open(args[:filename]).each(sep="\n") do |line|
        next if line.strip.size == 0
        parts = line.split
        count = parts[0].to_i
        date = Date.parse(parts[1])
        id = parts[2].split( /\//).last
        next if id == "downloads"
        id = "scholarsphere:#{id.split("?").first}"
        stat = FileDownloadStat.where(date: date, file_id: id).first
        if stat.blank?
          file = GenericFile.find(id)
          user = User.where(login:file.depositor).first
          FileDownloadStat.create(date: date, downloads: count, file_id: id, user_id: user.id)
        elsif (stat.downloads < count)
          puts "Updating count"
          stat.downloads = count
          stat.save
        end
      end
    end

  end
end
{'fraction_non_alphanumeric': 0.11566265060240964, 'fraction_numerical': 0.005783132530120482, 'mean_word_length': 2.364667747163695, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 17, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5384220', 'n_tokens_mistral': 653, 'n_tokens_neox': 631, 'n_words': 193}