<commit_before>(function () {
// service to handle all processing realted to the QC. Querying the server, processing the information for example.

'use strict';

angular.module('daApp')
  .factory('qcService', qcService);

qcService.$inject = ['$q', 'dataService', 'deliveryService', 'logger', 'utilityService'];

function qcService($q, dataService, deliveryService, logger, utilityService) {
  var qcHandler = {};
  var delService = deliveryService;
  var util = utilityService;

  qcHandler.notifySend = notifySend;

  // counter for the total times recording.controller.js 
  // has notified us of a send during this session
  var totalNotifies = 0;
  // counter to use for QC, counts how many recordings have been sent,
  //   since last reset of counter.
  var modSendCounter = 0;
  // {"module1" : id, ...} 
  var moduleRequestIds = {}

  return qcHandler;

  //////////


  function notifySend(sessionId, tokenCount) {
    // tokenCount is the total count of token reads by current speaker
    // if tokenCount === 0 it is a new speaker
    totalNotifies++;
    modSendCounter++;
    //console.info(totalNotifies + ' totalNotifies'); 

    // if totalNotifies is higher than the token count, it probably means
    //   a new user is recording starting at 0 tokens read.
    if (totalNotifies > tokenCount) {
      totalNotifies = 1;
      modSendCounter = 1;
    }

    if (modSendCounter >= (util.getConstant('QCFrequency' || 5))
       && totalNotifies >= (util.getConstant('QCInitRecThreshold') || 10)) {
      modSendCounter = 0;

      return delService.queryQC(sessionId)
      .then(handleQCReport, util.stdErrCallback);

    } else {
      
      return $q.reject(false);
    }
  }

  function calcAvgAcc(report) {
    /*
      Calculates weighted (right now equally) accuracy of all the modules
      from the QC report.

      parameters:
        report  the QC report as described in client server api.
      return: 
        a in [0.0 .. 1.0]
    */
    var acc = 0;
    var cnt = 0;
    for (var mod in report.modules) {
      if (!report.modules.hasOwnProperty(mod)) continue;

      var module = report.modules[mod];
      acc += module.totalStats.accuracy;
      cnt++;
    }
    return acc/cnt;
  }

  function handleQCReport(response) {
    var report = response.data;

    var result = updateModuleRequestIds(report); // do we have any new reports?

    // calulate average accuracy of all QC modules
    var avgAcc = calcAvgAcc(report);
    report.avgAcc = avgAcc;

    var tokenAnnouncement = handleTokenAnnouncements(report);

    // displayReport is in HTML
    var displayReport = prettify(report);
    dataService.set('QCReport', displayReport);

    // message to send back to recording.controller.js notifying that we wish
    //   results to be displayed.
    var displayResults = tokenAnnouncement
                         || (avgAcc < util.getConstant('QCAccThreshold')
                         && result); // make sure only to display if we have anything new (or token announcement)
    if (displayResults) {
      return $q.when(true);
    } else {
      return $q.reject(false);
    }
  }

  // like for example, display, good job! on each 50 tokens read.
  // adds key tokenCount and tokenCountMsg to report.
  function handleTokenAnnouncements(report) {
    var tokensRead = dataService.get('speakerInfo').tokensRead;
    
    // for tokenAnnouncement to be true modulus of tokenAnnouncement 
    // and TokenAnnouncementFrequency need to be 0
    var tokenAnnouncement = totalNotifies > 0
                            && totalNotifies % util.getConstant('TokenAnnouncementFreq') === 0;

    var totalTokens = util.getConstant('TokenCountGoal') || 260;<commit_msg>Disable qc reporting on frontend.<commit_after>(function () {
// service to handle all processing realted to the QC. Querying the server, processing the information for example.

'use strict';

angular.module('daApp')
  .factory('qcService', qcService);

qcService.$inject = ['$q', 'dataService', 'deliveryService', 'logger', 'utilityService'];

function qcService($q, dataService, deliveryService, logger, utilityService) {
  var qcHandler = {};
  var delService = deliveryService;
  var util = utilityService;

  qcHandler.notifySend = notifySend;

  // counter for the total times recording.controller.js 
  // has notified us of a send during this session
  var totalNotifies = 0;
  // counter to use for QC, counts how many recordings have been sent,
  //   since last reset of counter.
  var modSendCounter = 0;
  // {"module1" : id, ...} 
  var moduleRequestIds = {}

  return qcHandler;

  //////////


  function notifySend(sessionId, tokenCount) {
    // tokenCount is the total count of token reads by current speaker
    // if tokenCount === 0 it is a new speaker
    totalNotifies++;
    modSendCounter++;
    //console.info(totalNotifies + ' totalNotifies'); 

    // if totalNotifies is higher than the token count, it probably means
    //   a new user is recording starting at 0 tokens read.
    if (totalNotifies > tokenCount) {
      totalNotifies = 1;
      modSendCounter = 1;
    }

    if (modSendCounter >= (util.getConstant('QCFrequency' || 5))
       && totalNotifies >= (util.getConstant('QCInitRecThreshold') || 10)) {
      modSendCounter = 0;

      return delService.queryQC(sessionId)
      .then(handleQCReport, util.stdErrCallback);

    } else {
      
      return $q.reject(false);
    }
  }

  function calcAvgAcc(report) {
    /*
      Calculates weighted (right now equally) accuracy of all the modules
      from the QC report.

      parameters:
        report  the QC report as described in client server api.
      return: 
        a in [0.0 .. 1.0]
    */
    var acc = 0;
    var cnt = 0;
    for (var mod in report.modules) {
      if (!report.modules.hasOwnProperty(mod)) continue;

      var module = report.modules[mod];
      acc += module.totalStats.accuracy;
      cnt++;
    }
    return acc/cnt;
  }

  function handleQCReport(response) {
    var report = response.data;

    var result = updateModuleRequestIds(report); // do we have any new reports?

    // calulate average accuracy of all QC modules
    var avgAcc = calcAvgAcc(report);
    report.avgAcc = avgAcc;

    var tokenAnnouncement = handleTokenAnnouncements(report);

    // displayReport is in HTML
    var displayReport = prettify(report);
    dataService.set('QCReport', displayReport);

    // message to send back to recording.controller.js notifying that we wish
    //   results to be displayed.
    var displayResults = tokenAnnouncement;
                         // temporarily disable QC reporting on frontend.
                         /*|| (avgAcc < util.getConstant('QCAccThreshold')
                         && result); // make sure only to display if we have anything new (or token announcement)*/
    if (displayResults) {
      return $q.when(true);
    } else {
      return $q.reject(false);
    }
  }

  // like for example, display, good job! on each 50 tokens read.
  // adds key tokenCount and tokenCountMsg to report.
  function handleTokenAnnouncements(report) {
    var tokensRead = dataService.get('speakerInfo').tokensRead;
    
    // for tokenAnnouncement to be true modulus of tokenAnnouncement 
    // and TokenAnnouncementFrequency need to be 0
    var tokenAnnouncement = totalNotifies > 0
                            && totalNotifies % util.getConstant('TokenAnnouncementFreq') === 0;

    var totalTokens = util.getConstant('TokenCountGoal') || 260;
{'fraction_non_alphanumeric': 0.10161139965374884, 'fraction_numerical': 0.006658676255160474, 'mean_word_length': 2.741903338315894, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, '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': '6429943', 'n_tokens_mistral': 2203, 'n_tokens_neox': 2083, 'n_words': 687}