<commit_before>require 'open-uri'
require 'hpricot'
require 'sqlite3'
require 'time'

class Dupe < Linkbot::Plugin
  
  Linkbot::Plugin.register('dupe', self,
    {
      :message => {:regex => /!stats/, :handler => :on_message, :help => :help}
    }
  )
  
  def self.on_message(user, message, matches, msg) 
    rows = Linkbot.db.execute("select u.username,s.total,s.dupes,k.karma,u.showname from stats s, users u, karma k where u.user_id = s.user_id AND u.user_id = k.user_id order by k.karma desc")
    mess = "Link stats:\n--------------------------\n"

    #find the maximum length karma total
    max = rows.collect { |row| row[1].to_s }.map(&:length).max

    rows.each {|row|
      username = (row[4].nil? || row[4] == '') ? row[0] : row[4]
      dupe = row[2] == 1 ? 'dupe' : 'dupes'
      mess = mess + sprintf("%#{max}d: #{row[4]} (%d links, %d %s, %.2f%% new)\n", row[3], row[1], row[2], dupe, (row[1]/(row[1]+row[2]).to_f)*100)
    }
    [mess]
  end
  <commit_msg>maybe fix !stats. maybe not.<commit_after>require 'open-uri'
require 'hpricot'
require 'sqlite3'
require 'time'

class Dupe < Linkbot::Plugin
  
  Linkbot::Plugin.register('dupe', self,
    {
      :message => {:regex => /!stats/, :handler => :on_message, :help => :help}
    }
  )
  
  def self.on_message(user, message, matches, msg) 
    rows = Linkbot.db.execute("select u.username,s.total,s.dupes,k.karma,u.showname from stats s, users u, karma k where u.user_id = s.user_id AND u.user_id = k.user_id order by k.karma desc")
    mess = "Link stats:\n--------------------------\n"

    #find the maximum length karma total
    max = rows.collect { |row| row[1].to_s }.map(&:length).max

    rows.each {|row|
      username = (row[4].nil? || row[4] == '') ? row[0] : row[4]
      dupe = row[2] == 1 ? 'dupe' : 'dupes'
      mess = mess + sprintf("%#{max}d: #{username} (%d links, %d %s, %.2f%% new)\n", row[3], row[1], row[2], dupe, (row[1]/(row[1]+row[2]).to_f)*100)
    }
    [mess]
  end
  
{'fraction_non_alphanumeric': 0.22126582278481013, 'fraction_numerical': 0.018734177215189874, 'mean_word_length': 2.8974358974358974, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, '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': '297723', 'n_tokens_mistral': 781, 'n_tokens_neox': 764, 'n_words': 180}