<commit_before>Sensor.Vehicle = SC.Object.extend
  init: ->
    @set('_journeys', Sensor.Journeys.create(content: []))
    @set('messages', SC.ArrayProxy.create(content: []))
    @set('_stops', SC.ArrayProxy.create(content: []))
    @_super()
  updateWithMessages: (messages) ->
    messages = [messages] if !$.isArray(messages)
    @get('messages').pushObjects(messages)
    messages.forEach( ((message) ->
      if message.get('usn') == Sensor.IGNITION_ON
        journey = @createJourney(message)
        journey.addMessage(message)
      if message.get('usn') == Sensor.IGNITION_OFF
        journey = @getPath('_journeys.lastObject')
        if journey
          journey.addMessage(message)
          @finishJourney(journey)
      if message.get('usn') == Sensor.MOVING
        if journey = @getPath('_journeys.lastObject')
          if journey.state(message.get('datetime')) == 'unfinished'
            journey.addMessage(message)
        else
          if previousStagedMessage = @stagedMessage(message.get('datetime'))
            journey = @createJourney(previousStagedMessage)
            journey.addMessage(previousStagedMessage)
        @staged = message
    ), this)
  stops: ( ->
    # Need to account for the fact that a journey may not have
    # had an ignition off and hence become 'stopped' due to 
    # timing out.  If this has happened then we will be one stop
    # short and we need to create the last stop
    # _stops = @get('_stops')
    # if lastJourney = @getPath('_journeys.lastObject')
    #   if (lastJourney.state() == 'finished') && (lastJourney.getPath('endTime.milliseconds') != @getPath('_stops.lastObject.arriveTime.milliseconds'))
    #     @createStop(lastJourney.getPath('messages.lastObject'))
    # _stops
    console.log "calculating stops"
    journeys = @getPath('journeys.content').slice(0)
    if journeys
      journeys.filter((j) -> j.state() == 'finished').map (j) -> j.get('stop')
  ).property('_journeys.length').cacheable()
  journeys: ( ->
    console.log "calculating journeys"
    _journeys = @get('_journeys')
    if _journeys
      filteredJourneys = _journeys.filter (j) -> j.valid()
      @setPath('_journeys.content', filteredJourneys)
      @get('_journeys')
  ).property('_journeys.length').cacheable()
  lastMessageBinding: '.messages.lastObject'
  latBinding: '.lastMessage.lat'
  lonBinding: '.lastMessage.lon'
  headingBinding: '.lastMessage.heading'
  moved: ( ->
    !!@getPath('_journeys.length')
  ).property('_journeys.length').cacheable()
  createJourney: (message) ->
    if lastJourney = @getPath('_journeys.lastObject')
      lastJourney.finish()
    if lastStop = @getPath('_stops.lastObject')
      lastStop.set('leaveMessage',message)
    journey = Sensor.Journey.create(vehicle: this)
    journey.get('messages').pushObject(message)
    @get('_journeys').pushObject(journey)
    journey
  createStop: (message) ->
    stop = Sensor.Stop.create arriveMessage: message
    @get('_stops').pushObject stop
    stop
  finishJourney: (journey) ->
    journey.finish()
    @createStop(journey.getPath('messages.lastObject'))
  state: SC.computed( ->
    console.log "calculating state"
    lastMessage = @getPath('messages.lastObject')<commit_msg>removed unused create stops methods<commit_after>Sensor.Vehicle = SC.Object.extend
  init: ->
    @set('_journeys', Sensor.Journeys.create(content: []))
    @set('messages', SC.ArrayProxy.create(content: []))
    @set('_stops', SC.ArrayProxy.create(content: []))
    @_super()
  updateWithMessages: (messages) ->
    messages = [messages] if !$.isArray(messages)
    @get('messages').pushObjects(messages)
    messages.forEach( ((message) ->
      if message.get('usn') == Sensor.IGNITION_ON
        journey = @createJourney(message)
        journey.addMessage(message)
      if message.get('usn') == Sensor.IGNITION_OFF
        journey = @getPath('_journeys.lastObject')
        if journey
          journey.addMessage(message)
          @finishJourney(journey)
      if message.get('usn') == Sensor.MOVING
        if journey = @getPath('_journeys.lastObject')
          if journey.state(message.get('datetime')) == 'unfinished'
            journey.addMessage(message)
        else
          if previousStagedMessage = @stagedMessage(message.get('datetime'))
            journey = @createJourney(previousStagedMessage)
            journey.addMessage(previousStagedMessage)
        @staged = message
    ), this)
  stops: ( ->
    console.log "calculating stops"
    journeys = @getPath('journeys.content').slice(0)
    if journeys
      journeys.filter((j) -> j.state() == 'finished').map (j) -> j.get('stop')
  ).property('_journeys.length').cacheable()
  journeys: ( ->
    console.log "calculating journeys"
    _journeys = @get('_journeys')
    if _journeys
      filteredJourneys = _journeys.filter (j) -> j.valid()
      @setPath('_journeys.content', filteredJourneys)
      @get('_journeys')
  ).property('_journeys.length').cacheable()
  lastMessageBinding: '.messages.lastObject'
  latBinding: '.lastMessage.lat'
  lonBinding: '.lastMessage.lon'
  headingBinding: '.lastMessage.heading'
  moved: ( ->
    !!@getPath('_journeys.length')
  ).property('_journeys.length').cacheable()
  createJourney: (message) ->
    if lastJourney = @getPath('_journeys.lastObject')
      lastJourney.finish()
    if lastStop = @getPath('_stops.lastObject')
      lastStop.set('leaveMessage',message)
    journey = Sensor.Journey.create(vehicle: this)
    journey.get('messages').pushObject(message)
    @get('_journeys').pushObject(journey)
    journey
  finishJourney: (journey) ->
    journey.finish()
  state: SC.computed( ->
    console.log "calculating state"
    lastMessage = @getPath('messages.lastObject')
{'fraction_non_alphanumeric': 0.14684826261568013, 'fraction_numerical': 0.00034922297887200976, 'mean_word_length': 3.5173501577287065, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 28, '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': '1650018', 'n_tokens_mistral': 1795, 'n_tokens_neox': 1813, 'n_words': 310}