<commit_before>import HubSensor from 'sensors/hub-sensor';

// the amount of ounces required to flow to consider a pour occurred
const pourThreshold = 0.15;

// may require calibration
const pulsesPerLiter = 450;
const ouncesPerLiter = 33.814;
const pulsesPerOunce = 13.308;

/*

*/
export default class FlowMeter extends HubSensor {

  constructor(firebase, id, fiveSensor, display = null) {
    super();
    this._firebase = firebase;
    this._id = id;
    this._sensor = fiveSensor;
    this._display = display;

    // pulses per session - gets reset
    let sessionPulses = 0;

    // state of flow meter
    let isOpen = false;

    this._lastPulse = Date.now();
    this._hertz = 0;
    this._flow = 0;
    this._thisPour = 0;
    this._totalPour = 0;
    
    this._sensor.on('change', (value) => {
      if (!value) {
        return;
      }
      
      // sessionPulses++;
      // isOpen = true;
      
      let currentTime = Date.now();
      this._clickDelta = Math.max([currentTime - this._lastPulse], 1);
      if (this._clickDelta < 1000) {
          this._hertz = 1000 / this._clickDelta;
          this._flow = this._hertz / (60 * 7.5);
          let p = (this._flow * (this._clickDelta / 1000) * 25.11338);
          this._thisPour += p;
          this._totalPour += p;
          console.log(`${id} poured: ${this._thisPour}`);
          setTimeout(() => {
            if (this._lastPulse - Date.now() > 1000) {
              console.log(`the pour was: ${this._thisPour}`);
            }
          }, 1000);
      }
      
      this._lastPulse = currentTime;

      // let currentSession = sessionPulses;
      // setTimeout(() => {
      //   if (currentSession === sessionPulses) {
      //     const ounces = Math.round((sessionPulses / pulsesPerOunce) * 100) / 100;
      //     if (ounces > pourThreshold) {
      //       const message = `${id} poured: ${ounces} oz`;
      //       super.report(message);
      // 
      //       // report to firebase
      //       this.logPour(ounces);
      // 
      //       // write to display
      //       if (this._display && this._display.getIsOn()) {
      //         this._display.write(message);
      //         setTimeout(() => {
      //           this._display.clear();
      //         }, 500);
      //       }<commit_msg>more debug, watching time and hertz<commit_after>import HubSensor from 'sensors/hub-sensor';

// the amount of ounces required to flow to consider a pour occurred
const pourThreshold = 0.15;

// may require calibration
const pulsesPerLiter = 450;
const ouncesPerLiter = 33.814;
const pulsesPerOunce = 13.308;

/*

*/
export default class FlowMeter extends HubSensor {

  constructor(firebase, id, fiveSensor, display = null) {
    super();
    this._firebase = firebase;
    this._id = id;
    this._sensor = fiveSensor;
    this._display = display;

    // pulses per session - gets reset
    let sessionPulses = 0;

    // state of flow meter
    let isOpen = false;

    this._lastPulse = Date.now();
    this._hertz = 0;
    this._flow = 0;
    this._thisPour = 0;
    this._totalPour = 0;
    
    this._sensor.on('change', (value) => {
      if (!value) {
        return;
      }
      
      // sessionPulses++;
      // isOpen = true;
      
      let currentTime = Date.now();
      this._clickDelta = Math.max([currentTime - this._lastPulse], 1);
      if (this._clickDelta < 1000) {
          this._hertz = 1000 / this._clickDelta;
          this._flow = this._hertz / (60 * 7.5);
          let p = (this._flow * (this._clickDelta / 1000)) * 25.11338;
          this._thisPour += p;
          this._totalPour += p;
          console.log(`${id} poured: ${this._thisPour}`);
          setTimeout(() => {
            let now = Date.now();
            console.log(`${id} now: ${now} last: ${this._lastPulse}`);
          }, 1000);
      }
      
      this._lastPulse = currentTime;

      // let currentSession = sessionPulses;
      // setTimeout(() => {
      //   if (currentSession === sessionPulses) {
      //     const ounces = Math.round((sessionPulses / pulsesPerOunce) * 100) / 100;
      //     if (ounces > pourThreshold) {
      //       const message = `${id} poured: ${ounces} oz`;
      //       super.report(message);
      // 
      //       // report to firebase
      //       this.logPour(ounces);
      // 
      //       // write to display
      //       if (this._display && this._display.getIsOn()) {
      //         this._display.write(message);
      //         setTimeout(() => {
      //           this._display.clear();
      //         }, 500);
      //       }
{'fraction_non_alphanumeric': 0.14171006944444445, 'fraction_numerical': 0.026041666666666668, 'mean_word_length': 1.761533852606351, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 14, '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': '4301263', 'n_tokens_mistral': 1534, 'n_tokens_neox': 1375, 'n_words': 331}