<commit_before>module Usagewatch

  # Show disk used in GB
  def self.uw_diskused
    df = `df -kl`
    sum = 0.00
    df.each_line.with_index do |line, line_index|
      next if line_index.eql? 0
      line = line.split(" ")
      next if line[0] =~ /localhost/  #ignore backup filesystem
      sum += ((line[2].to_f)/1024)/1024
    end
    sum.round(2)
  end

  # Show the percentage of disk used.
  def self.uw_diskused_perc
    df = `df -kl`
    total = 0.0
    used = 0.0
    df.each_line.with_index do |line, line_index|
      df.split(" ").last.to_f.round(2)
      next if line_index.eql? 0
      line = line.split(" ")
      next if line[0] =~ /localhost/ #ignore backup filesystem
      total  += ((line[3].to_f)/1024)/1024
      used   +=((line[2].to_f)/1024)/1024
    end
    ((used/total) * 100).round(2)
  end

  # todo
  #def uw_cpuused
  #
  #end

  # return hash of top ten proccesses by cpu consumption
  # example [["apache2", 12.0], ["passenger", 13.2]]
  def self.uw_cputop
    ps = `ps aux | awk '{print $11, $3}' | sort -k2nr  | head -n 10`
    array = []
    ps.each_line do |line|
      line = line.chomp.split(" ")
      array << [line.first.gsub(/[\[\]]/, ""), line.last]
    end
    array
  end

  # todo
  #def uw_tcpused
  #
  #end

  # todo
  #def uw_udpused
  #<commit_msg>fixed name of proccesses in mac<commit_after>module Usagewatch

  # Show disk used in GB
  def self.uw_diskused
    df = `df -kl`
    sum = 0.00
    df.each_line.with_index do |line, line_index|
      next if line_index.eql? 0
      line = line.split(" ")
      next if line[0] =~ /localhost/  #ignore backup filesystem
      sum += ((line[2].to_f)/1024)/1024
    end
    sum.round(2)
  end

  # Show the percentage of disk used.
  def self.uw_diskused_perc
    df = `df -kl`
    total = 0.0
    used = 0.0
    df.each_line.with_index do |line, line_index|
      df.split(" ").last.to_f.round(2)
      next if line_index.eql? 0
      line = line.split(" ")
      next if line[0] =~ /localhost/ #ignore backup filesystem
      total  += ((line[3].to_f)/1024)/1024
      used   +=((line[2].to_f)/1024)/1024
    end
    ((used/total) * 100).round(2)
  end

  # todo
  #def uw_cpuused
  #
  #end

  # return hash of top ten proccesses by cpu consumption
  # example [["apache2", 12.0], ["passenger", 13.2]]
  def self.uw_cputop
    ps = `ps aux | awk '{print $11, $3}' | sort -k2nr  | head -n 10`
    array = []
    ps.each_line do |line|
      line = line.chomp.split(" ")
      array << [line.first.gsub(/[\[\]]/, "").split("/").last, line.last]
    end
    array
  end

  # todo
  #def uw_tcpused
  #
  #end

  # todo
  #def uw_udpused
  #
{'fraction_non_alphanumeric': 0.1502649507948524, 'fraction_numerical': 0.04314912944738834, 'mean_word_length': 2.2509225092250924, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, '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': '1164682', 'n_tokens_mistral': 1087, 'n_tokens_neox': 1008, 'n_words': 264}