<commit_before># tupelo.coffee
# vim: sts=2 sw=2 et:

T = ($) ->

  my = {}
  my.debug = false

  # some constants
  my.NOLO = 0
  my.RAMI = 1
  my.VOTING = 1
  my.ONGOING = 2

  my.log = (msg) ->
    console.log msg if my.debug

  # Simple ajax timer using jQuery
  my.Timer = (url, interval, callback, params) ->

    @url = url
    @interval = interval
    @callback = callback
    @params = params # extra params for jQuery.ajax
    # to make the object available in callback closures
    me = this

    ajaxCallback = (result) ->
      me.callback result
      me.setTimer()

    ajaxError = (xhr, astatus, error) ->
      my.log "status: " + astatus
      my.log "error: " + error
      me.disable()

    getData = ->
      params =
        url: me.url
        success: ajaxCallback
        error: ajaxError
      
      # set extra params
      for key of me.params
        params[key] = me.params[key]  if me.params.hasOwnProperty(key)

      $.ajax params

    @setTimer = ->
      @timer = window.setTimeout(getData, @interval)
      this

    @setTimer()

  my.Timer::disable = ->
    if @timer
      window.clearTimeout @timer
      @timer = `undefined`
    this

  # Player
  class my.Player
    constructor: (name) ->
      @player_name = name

    fromJSON: (json) ->
      obj = eval("(" + json + ")")
      @fromObj obj

    fromObj: (obj) ->
      for prop of obj
        this[prop] = obj[prop]
      this

    toString: ->
      "" + @player_name + " (" + @id + ")"

  # Card
  suits = [
    name: "spades"
    html: "&#x2660;"
  ,
    name: "diamonds"
    html: "&#x2666;"
  ,
    name: "clubs"
    html: "&#x2663;"
  ,
    name: "hearts"
    html: "&#x2665;"
  ]

  valueToChar = (value) ->
    switch value
      when 11
        "J"
      when 12
        "Q"
      when 13
        "K"
      when 1, 14
        "A"
      else
        value + ""

  class my.Card
    constructor: (suit, value) ->
      @suit = suit
      @value = value

    toString: ->
      "" + valueToChar(@value) + " of " + suits[@suit].name

    toShortString: ->
      "" + valueToChar(@value) + suits[@suit].html

    toShortHtml: ->
      "<span class=\"" + suits[@suit].name + "\">" + @toShortString() + "</span>"

  my

(jQuery)
<commit_msg>Refactor and export T to global object<commit_after># tupelo.coffee
# vim: sts=2 sw=2 et:

root = exports ? this
$ = jQuery

T = {}
T.debug = false

# some constants
T.NOLO = 0
T.RAMI = 1
T.VOTING = 1
T.ONGOING = 2

T.log = (msg) ->
  console?.log msg if T.debug

# Simple ajax timer using jQuery
T.Timer = (url, interval, callback, params) ->

  @url = url
  @interval = interval
  @callback = callback
  @params = params # extra params for jQuery.ajax
  # to make the object available in callback closures
  me = this

  ajaxCallback = (result) ->
    me.callback result
    me.setTimer()

  ajaxError = (xhr, astatus, error) ->
    T.log "status: " + astatus
    T.log "error: " + error
    me.disable()

  getData = ->
    params =
      url: me.url
      success: ajaxCallback
      error: ajaxError

    # set extra params
    for own key of me.params
      params[key] = me.params[key]

    $.ajax params

  @setTimer = ->
    @timer = window.setTimeout(getData, @interval)
    this

  @setTimer()

T.Timer::disable = ->
  if @timer
    window.clearTimeout @timer
    @timer = null
  this

# Player
class T.Player
  constructor: (name) ->
    @player_name = name

  fromJSON: (json) ->
    obj = eval("(" + json + ")")
    @fromObj obj

  fromObj: (obj) ->
    for prop of obj
      this[prop] = obj[prop]
    this

  toString: ->
    "" + @player_name + " (" + @id + ")"

# Card
suits = [
  name: "spades"
  html: "&#x2660;"
,
  name: "diamonds"
  html: "&#x2666;"
,
  name: "clubs"
  html: "&#x2663;"
,
  name: "hearts"
  html: "&#x2665;"
]

valueToChar = (value) ->
  switch value
    when 11
      "J"
    when 12
      "Q"
    when 13
      "K"
    when 1, 14
      "A"
    else
      value + ""

class T.Card
  constructor: (suit, value) ->
    @suit = suit
    @value = value

  toString: ->
    "" + valueToChar(@value) + " of " + suits[@suit].name

  toShortString: ->
    "" + valueToChar(@value) + suits[@suit].html

  toShortHtml: ->
    "<span class=\"" + suits[@suit].name + "\">" + @toShortString() + "</span>"

# finally, export T to global object
root.T = T


{'fraction_non_alphanumeric': 0.14920194309507287, 'fraction_numerical': 0.014341892204487625, 'mean_word_length': 2.0601556970983723, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 40, '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': '5728681', 'n_tokens_mistral': 1609, 'n_tokens_neox': 1514, 'n_words': 406}