<commit_before>import logger from '../common/js/tools/logger';

// Don't log any gesture that is shorter than 0.3s to avoid noise.
const MIN_GESTURE_DURATION = 0.3; // s

export default class GesturesLogger {
  constructor() {
    this._prevGestureTimestamp = null;
    this._prevGesture = null;
    this._prevDay = null;
  }

  logGesture(data, gestureDetected, currentDay) {
    let newGesture = null;
    if (gestureDetected && data.numberOfHands === 1) {
      newGesture = 'Gesture:SetAngle';
    } else if (gestureDetected && data.numberOfHands === 1) {
      newGesture = 'Gesture:SetDistance';
    } else if (data.numberOfHands === 1 && data.handType === 'left') {
      newGesture = 'Gesture:OneHandNotAligned';
    } else if (data.numberOfHands === 1 && data.handType === 'right') {
      newGesture = 'Gesture:OneHandNotAligned';
    } else if (data.numberOfHands === 2 && !data.handsVertical) {
      newGesture = 'Gesture:TwoHandsNotVertical';
    } else if (data.numberOfHands === 2 && data.handsVertical) {
      newGesture = 'Gesture:TwoHandsNotAligned';
    }
    if (this._prevGesture && this._prevGesture !== newGesture) {
      const duration = (Date.now() - this._prevGestureTimestamp) / 1000;
      if (duration > MIN_GESTURE_DURATION) {
        logger.log(this._prevGesture, {
          duration,
          day: currentDay,
          prevDay: this._prevDay
        });
      }
      this._prevGestureTimestamp = null;
    }
    this._prevGesture = newGesture;
    if (this._prevGestureTimestamp === null && newGesture !== null) {
      this._prevGestureTimestamp = Date.now();
      this._prevDay = currentDay;
    }
  }
}
<commit_msg>Log hands interaction statistics<commit_after>import logger from '../common/js/tools/logger';

// Don't log any gesture that is shorter than 0.3s to avoid noise.
const MIN_GESTURE_DURATION = 0.3; // s

export default class GesturesLogger {
  constructor() {
    this._prevGestureTimestamp = null;
    this._prevGesture = null;
    this._prevDay = null;
    this._stats = {};
    this._statsTimestamp = null;
  }

  logGesture(data, gestureDetected, currentDay) {
    const now = performance.now();
    let newGesture = null;
    if (gestureDetected && data.numberOfHands === 1) {
      newGesture = 'Gesture:SetAngle';
    } else if (gestureDetected && data.numberOfHands === 2) {
      newGesture = 'Gesture:SetDistance';
    } else if (data.numberOfHands === 1 && data.handType === 'left') {
      newGesture = 'Gesture:OneHandNotAligned';
    } else if (data.numberOfHands === 1 && data.handType === 'right') {
      newGesture = 'Gesture:OneHandNotAligned';
    } else if (data.numberOfHands === 2 && !data.handsVertical) {
      newGesture = 'Gesture:TwoHandsNotVertical';
    } else if (data.numberOfHands === 2 && data.handsVertical) {
      newGesture = 'Gesture:TwoHandsNotAligned';
    }
    // Setup stats when some gesture is detected (and there were no hands visible before).
    if (this._prevGesture === null && newGesture !== null) {
      this._stats = {};
      this._statsTimestamp = now;
    }
    // Collect statistics on single gesture and try to log them.
    if (this._prevGesture && this._prevGesture !== newGesture) {
      const duration = (now - this._prevGestureTimestamp) / 1000;
      if (duration > MIN_GESTURE_DURATION) {
        logger.log(this._prevGesture, {
          duration,
          day: currentDay,
          prevDay: this._prevDay
        });
      }
      if (!this._stats[this._prevGesture]) {
        this._stats[this._prevGesture] = 0;
      }
      this._stats[this._prevGesture] += duration;
      this._prevGestureTimestamp = null;
    }
    // Log statistic when hands interaction is finished.
    if (this._prevGesture !== null && newGesture === null) {
      const duration = (now - this._statsTimestamp) / 1000;
      Object.keys(this._stats).forEach(key => {
        this._stats[key] = (this._stats[key] / duration) * 100;
      });
      logger.log('HandsInteractionSummary', {
        duration,
        stats: this._stats
      });
    }

    this._prevGesture = newGesture;
    if (this._prevGestureTimestamp === null && newGesture !== null) {
      this._prevGestureTimestamp = now;
      this._prevDay = currentDay;
    }
  }
}

{'fraction_non_alphanumeric': 0.12973863903932187, 'fraction_numerical': 0.008476571697668942, 'mean_word_length': 2.8794520547945206, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 6, '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': '4544961', 'n_tokens_mistral': 1430, 'n_tokens_neox': 1320, 'n_words': 295}