 UserHandler = require '../server/users/user_handler'
 User = require '../server/users/User'
 
-#startDate = new Date 2015, 11, 1
-startDate = new Date 2015, 11, 8  # Testing
+startDate = new Date 2015, 11, 1
 
 query = dateCreated: {$gt: startDate}, emailLower: {$exists: true}
 selection = 'name emailLower schoolName courseInstances clans ageRange dateCreated referrer points lastIP hourOfCode preferredLanguage lastLevel'

      categories[value].push user
  categories

getDomain = (user) ->
  domain = user.emailLower.split('@')[1]
  return null if commonEmailDomainMap[domain]
  typo = _.find commonEmailDomains, (commonDomain) -> stringScore(commonDomain, domain, 0.8) > 0.9
  return null if typo
  domain

# https://github.com/joshaven/string_score
stringScore = (_a, word, fuzziness) ->

sortUsers = (users) ->
  users = _.sortBy users, (u) -> -u.points
  users = _.sortBy users, ['schoolName', 'lastIP']
  for field in ['courseInstances', 'lastIP', 'schoolName', 'domain', 'clans', 'referrer']
    userCategories[field] = categorizeUsers users, field
    topGroups[field] = _.sortBy _.keys(userCategories[field]), (key) -> -userCategories[field][key].length
    topGroups[field] = (group for group in topGroups[field] when 2 < userCategories[field][group].length < (if field is 'clans' then 30 else 5000))
