<commit_before>import '/node_modules/whatwg-fetch/fetch.js'
import Datastore from 'datastore.js'

class Motu {
  constructor () {
    this._eTag = -1
    this._datastore = new Datastore()
  }

  connect (address) {
    this._address = address
    this._getNewData()
  }

  disconnect () {
    this._address = null
  }

  get datastore () {
    return this._datastore
  }

  _getNewData () {
    if (!this._address) {
      return
    }

    const url = 'http://' + this._address + '/datastore'
    let headers = {}
    if (this._eTag > 0) {
      headers['If-None-Match'] = this._eTag
    }

    window.fetch(url, {headers: headers})
      .then(response => {
        if (response.status >= 200 && response.status < 300) {
          this._eTag = response.headers.get('ETag')
          return response
        } else if (response.status === 304) {
          // no data was changed on the device, ask again
          setTimeout(() => { this._getNewData() }, 0)
        } else {
          console.log('Invalid http status ' + response.status)
        }
      }).then(response => {
        return response.json()
      }).then(json => {
        this._parseRawDatastore(json)
        setTimeout(() => { this._getNewData() }, 0)
      }).catch(ex => {<commit_msg>made some code prettier<commit_after>import '/node_modules/whatwg-fetch/fetch.js'
import Datastore from 'datastore.js'

class Motu {
  constructor () {
    this._eTag = -1
    this._datastore = new Datastore()
  }

  connect (address) {
    this._address = address
    this._getNewData()
  }

  disconnect () {
    this._address = null
  }

  get datastore () {
    return this._datastore
  }

  _refreshData () {
    setTimeout(() => {
      this._getNewData()
    }, 0)
  }

  _getNewData () {
    if (!this._address) {
      return
    }

    const url = 'http://' + this._address + '/datastore'
    let headers = {}
    if (this._eTag > 0) {
      // MOTU supports long polling:
      // It waits to send response until something has changed, and increases the ETag number.
      headers['If-None-Match'] = this._eTag
    }

    window.fetch(url, {headers: headers})
      .then(response => {
        if (response.status >= 200 && response.status < 300) {
          this._eTag = response.headers.get('ETag')
          return response
        } else if (response.status === 304) {
          // 304 means no data was changed on the device, ask again
          this._refreshData()
        } else {
          console.log('Unexpected http status ' + response.status)
        }
      }).then(response => {
        return response.json()
      }).then(json => {
        this._parseRawDatastore(json)
        this._refreshData()
      }).catch(ex => {
{'fraction_non_alphanumeric': 0.13868343195266272, 'fraction_numerical': 0.010355029585798817, 'mean_word_length': 2.1271676300578033, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 18, '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': '2676353', 'n_tokens_mistral': 874, 'n_tokens_neox': 832, 'n_words': 193}