<commit_before>define [
  'marionette',

  'templates/dashboard/device',
], (
  Marionette,

  template,
) ->
  class DashboardDeviceView extends Marionette.ItemView
    tagName: 'li'
    className: 'device'

    template: template

    dataSeries:
      ecg: new TimeSeries()
      respiratory: new TimeSeries()

    liveCharts:
      ecg: null
      respiratory: null

    initialize: =>
      @model.firebase().child('raw_ecg').on 'child_added', (snapshot) =>
        @dataSeries.ecg.append snapshot.key(), snapshot.val()

    onAttach: =>
      pad2 = (number) ->
        if number < 10 then '0' + number else number

      @liveCharts.ecg = @.$('.ecg-live').liveChart @dataSeries.ecg,
        delay: 1750
        interpolation: 'linear'
        timestampFormatter: (date) ->
          return pad2(date.getSeconds())

      @liveCharts.respiratory = @.$('.respiratory-live').liveChart(@dataSeries.respiratory)

    onDestroy: =>
      _(@liveCharts).each (chart) ->
        chart.stop()<commit_msg>Limit the number of children we fetch from firebase - we don't want thousands<commit_after>define [
  'marionette',

  'templates/dashboard/device',
], (
  Marionette,

  template,
) ->
  class DashboardDeviceView extends Marionette.ItemView
    tagName: 'li'
    className: 'device'

    template: template

    dataSeries:
      ecg: new TimeSeries()
      respiratory: new TimeSeries()

    liveCharts:
      ecg: null
      respiratory: null

    initialize: =>
      @model.firebase().child('raw_ecg').limitToLast(300).on 'child_added', (snapshot) =>
        @dataSeries.ecg.append snapshot.key(), snapshot.val()

    onAttach: =>
      pad2 = (number) ->
        if number < 10 then '0' + number else number

      @liveCharts.ecg = @.$('.ecg-live').liveChart @dataSeries.ecg,
        delay: 1750
        interpolation: 'linear'
        timestampFormatter: (date) ->
          return pad2(date.getSeconds())

      @liveCharts.respiratory = @.$('.respiratory-live').liveChart(@dataSeries.respiratory)

    onDestroy: =>
      _(@liveCharts).each (chart) ->
        chart.stop()
{'fraction_non_alphanumeric': 0.13764988009592327, 'fraction_numerical': 0.010071942446043165, 'mean_word_length': 2.738351254480287, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 19, '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': '1877920', 'n_tokens_mistral': 681, 'n_tokens_neox': 643, 'n_words': 135}