<commit_before>{argv} = require 'optimist'
KONFIG = require('koding-config-manager').load("main.#{argv.c}")

registeredUsers = {}
allUsers = {}

redisClient = null

publishToRedis = ->
  uniqueKeysRegistered = Object.keys registeredUsers
  uniqueKeysAll = Object.keys allUsers

  dateObj = new Date()
  month = dateObj.getUTCMonth() + 1
  day   = dateObj.getUTCDate()
  year  = dateObj.getUTCFullYear()

  # return if we dont have any registeredUsers for this iteration
  if uniqueKeysRegistered.length > 0
    # clear the previous ones
    registeredUsers = {}

    hllDailyKey = "registered_visitingusers:#{argv.c}:daily:#{year}:#{month}:#{day}"

    redisClient?.pfadd hllDailyKey, uniqueKeysRegistered..., ->

  if uniqueKeysAll.length > 0
    # clear the previous ones
    allUsers = {}

    hllDailyKey = "all_visitingusers:#{argv.c}:daily:#{year}:#{month}:#{day}"

    redisClient?.pfadd hllDailyKey, uniqueKeysAll..., ->


module.exports.track = (username)->
  # if user is a registered one track them seperately
  registeredUsers[username] = ""  unless /guest-/.test username

  allUsers[username] = ""

module.exports.start = ->
  redis = require "redis"
  redisClient = redis.createClient(
    KONFIG.redis.split(":")[1]
    KONFIG.redis.split(":")[0]
    {}
  )

  redisClient.on "error", (err)-> console.log "redis err", err
  redisClient.on "connect", -> console.log "connected to redis"
<commit_msg>Usertracker: code cleanup<commit_after>{argv} = require 'optimist'
KONFIG = require('koding-config-manager').load("main.#{argv.c}")

registeredUsers = {}
allUsers = {}

redisClient = null

sendData = (prefix, keys)->
  hllDailyKey = "#{prefix}_visitingusers:#{argv.c}:daily:#{year}:#{month}:#{day}"
  redisClient?.pfadd hllDailyKey, keys..., ->

publishToRedis = ->
  uniqueKeysRegistered = Object.keys registeredUsers
  uniqueKeysAll = Object.keys allUsers

  dateObj = new Date()
  month = dateObj.getUTCMonth() + 1
  day   = dateObj.getUTCDate()
  year  = dateObj.getUTCFullYear()

  # return if we dont have any registeredUsers for this iteration
  if uniqueKeysRegistered.length > 0
    # clear the previous ones
    registeredUsers = {}
    sendData "registered", uniqueKeysRegistered

  if uniqueKeysAll.length > 0
    # clear the previous ones
    allUsers = {}
    sendData "all", uniqueKeysAll

module.exports.track = (username)->
  # if user is a registered one track them seperately
  registeredUsers[username] = ""  unless /guest-/.test username

  allUsers[username] = ""

module.exports.start = ->
  redis = require "redis"
  redisClient = redis.createClient(
    KONFIG.redis.split(":")[1]
    KONFIG.redis.split(":")[0]
    {}
  )

  redisClient.on "error", (err)-> console.log "redis err", err
  redisClient.on "connect", -> console.log "connected to redis"

{'fraction_non_alphanumeric': 0.14050179211469535, 'fraction_numerical': 0.0035842293906810036, 'mean_word_length': 3.9750445632798574, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 21, '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': '1751847', 'n_tokens_mistral': 935, 'n_tokens_neox': 917, 'n_words': 204}