<commit_before>var influx = require('influx')
var _ = require('lodash')

var client = influx({
  host : process.env.INFLUXDB_HOST ? process.env.INFLUXDB_HOST : 'influxdb.chacal.online',
  protocol : 'https',
  username : process.env.INFLUXDB_USERNAME,
  password : <PASSWORD>,
  database : process.env.INFLUXDB_DB
})

function start(sensorStream) {
  sensorStream.onValue(event => {
    const series = {
      sensorVoltage: eventPoint(event, e => ({ value: e.vcc / 1000 })),
      measurementDuration: eventPoint(event, e => ({ value: e.previousSampleTimeMicros / 1000 / 1000 }))
    }

    switch (event.tag) {
      case 't':
        series.temperature = eventPoint(event, e => ({ value: e.temperature }))
        break;
      case 'p':
        series.pressure = eventPoint(event, e => ({ value: e.pressure }))
        break;
      case 'c':
        series.current = eventPoint(event, e => ({
          value: e.current,
          shuntVoltage: e.shuntVoltageMilliVolts / 1000,
          rawMeasurement: e.rawMeasurement
        }))
        break;
    }

    client.writeSeries(series, {}, (err, res) => {
      if(err) {
        console.log(err)
      }
    })
  })
}


function eventPoint(event, valuesExtractor) {
  return [[_.assign({ time: event.ts }, valuesExtractor(event)), { instance: event.instance }]]
}


module.exports = {<commit_msg>Save 5 second averages of currents to InfluxDB<commit_after>var influx = require('influx')
var _ = require('lodash')
var util = require('./util.js')

var client = influx({
  host : process.env.INFLUXDB_HOST ? process.env.INFLUXDB_HOST : 'influxdb.chacal.online',
  protocol : 'https',
  username : process.env.INFLUXDB_USERNAME,
  password : <PASSWORD>_PASSWORD,
  database : process.env.INFLUXDB_DB
})

function start(rawSensorStream) {
  var loggedSensorStream = createLoggedSensorStream(rawSensorStream)
  loggedSensorStream.onValue(event => {
    const series = {
      sensorVoltage: eventPoint(event, e => ({ value: e.vcc / 1000 })),
      measurementDuration: eventPoint(event, e => ({ value: e.previousSampleTimeMicros / 1000 / 1000 }))
    }

    switch (event.tag) {
      case 't':
        series.temperature = eventPoint(event, e => ({ value: e.temperature }))
        break;
      case 'p':
        series.pressure = eventPoint(event, e => ({ value: e.pressure }))
        break;
      case 'c':
        series.current = eventPoint(event, e => ({
          value: e.current,
          shuntVoltage: e.shuntVoltageMilliVolts / 1000,
          rawMeasurement: e.rawMeasurement
        }))
        break;
    }

    client.writeSeries(series, {}, (err, res) => {
      if(err) {
        console.log(err)
      }
    })
  })
}


function eventPoint(event, valuesExtractor) {
  return [[_.assign({ time: event.ts }, valuesExtractor(event)), { instance: event.instance }]]
}

function createLoggedSensorStream(sensorStream) {
  var CURRENT_AVERAGING_TIME = 5000
  var withoutCurrent = sensorStream.filter(event => event.tag !== 'c')
  var currents = util.averagedCurrents(sensorStream, stream => stream.bufferWithTime(CURRENT_AVERAGING_TIME))
  return withoutCurrent.merge(currents)
}

module.exports = {
{'fraction_non_alphanumeric': 0.13824739006643466, 'fraction_numerical': 0.01170515659601392, 'mean_word_length': 3.0905562742561448, 'pattern_counts': {'":': 0, '<': 5, '<?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': '7117823', 'n_tokens_mistral': 1064, 'n_tokens_neox': 1007, 'n_words': 200}