<commit_before># Takes in a MeshBlu message object and a Farmbot Object. Determines which
# method to call

TELEMETRY = "api,devices,fromUuid,message"

angular.module("FarmBot").factory 'Router', [
  ->
    route: (data, bot) ->
      routing_key = _(data).pick(_.identity).keys().sort().toString()
      switch
        when TELEMETRY
          @read_status(data, bot)
        else
          console.log "Unknown signature on incoming message: #{routing_key}"
          debugger
      # return if data.payload # "payload" means its telemetry, not message.
      # routing_key = data.message.message_type
      # if @hasOwnProperty(routing_key) and routing_key != 'route'
      #   @[routing_key](data, bot)
      # else
      #   alert  "Got an unknown '#{routing_key}' message from the device."
      #   @['missing'](data, bot)
    confirmation: (data, device) -> yes
    single_command: (data, device) -> yes
    read_status: (data, device) ->
      device[k] = v for k, v of (data.message || {})
    error: (data, device) ->
      msg = data?.message?.error || "Unexpected error. See console for details."
      alert "FarmBot sent back an error: #{msg}. See console for details"
      console.warn data
    missing: (data, device) -> no
    exec_sequence: (data, device) ->
      console.log "Hooray, the sequence was sent off!"
    sync_sequence: (data, device) -> console.log "Sync"
]<commit_msg>[UNSTABLE] Re-implementing router.js.coffee to handle new message protocol<commit_after># Takes in a MeshBlu message object and a Farmbot Object. Determines which
# method to call
TELEMETRY      = "api,message"
SYSTEM_MESSAGE = "payload,topic"
BOT_REPLY      = "id,method,params"
BOT_REPLY2     = "message"
LOG_MESSAGE    = "payload"

angular.module("FarmBot").factory 'Router', [
  ->
    route: (data, bot) ->
      omg = _(data).omit(["devices", "fromUuid"]).pick(_.identity).keys().sort().toString()

      switch omg
        when TELEMETRY      then console.log("Update router to update bot status")
        when SYSTEM_MESSAGE then 'Usually tells you the bot came online.'
        when BOT_REPLY      then '-Probably the one I need to implement-'
        when BOT_REPLY2     then 'Confused about this one?'
        when LOG_MESSAGE    then 'From a `puts` statement on the bot'
        else
          alert 'I just got an unexpected message from MeshBlu. Please send me a copy of the logs.'
          console.log data
      # return if data.payload # "payload" means its telemetry, not message.
      # routing_key = data.message.message_type
      # if @hasOwnProperty(routing_key) and routing_key != 'route'
      #   @[routing_key](data, bot)
      # else
      #   alert  "Got an unknown '#{routing_key}' message from the device."
      #   @['missing'](data, bot)
    confirmation: (data, device) -> yes
    single_command: (data, device) -> yes
    read_status: (data, device) ->
      device[k] = v for k, v of (data.message || {})
    error: (data, device) ->
      msg = data?.message?.error || "Unexpected error. See console for details."
      alert "FarmBot sent back an error: #{msg}. See console for details"
      console.warn data
    missing: (data, device) -> no
    exec_sequence: (data, device) ->
      console.log "Hooray, the sequence was sent off!"
    sync_sequence: (data, device) -> console.log "Sync"
]
{'fraction_non_alphanumeric': 0.121929298981426, 'fraction_numerical': 0.0005991611743559018, 'mean_word_length': 2.85121107266436, 'pattern_counts': {'":': 0, '<': 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': '3954474', 'n_tokens_mistral': 1012, 'n_tokens_neox': 1011, 'n_words': 330}