<commit_before>import TournamentStatsChangeEmitter from './../event-emitters/stats-change-emitter';
import TournamentStatsChangeEvent from './../events/TournamentStatsChangeEvent';
import { StatsReportManager as StatsReportManager } from './../managers/stats-models/report';
import tournamentManager from './../managers/model-managers/tournament';
import StatReportType from './../enums/stat-report-type';

const tournamentStatsChangeEmitter = new TournamentStatsChangeEmitter();

export const events = {
  TOURNAMENT_STAT_CHANGE_EVENT: 'tournamentStatsChangedEvent',
}

const tournamentCalculationTimeouts = new Map();

export const bufferTournamentStatsChangedEmittion = ({ tournamentId }) => {
  console.log('Buffering stats calculations for tournament ' + tournamentId);
  if (tournamentCalculationTimeouts.has(tournamentId)) {
    clearTimeout(tournamentCalculationTimeouts.get(tournamentId));
    tournamentCalculationTimeouts.delete(tournamentId);
  }
  const timeout = setTimeout(() => {
      tournamentCalculationTimeouts.delete(tournamentId);
      tournamentStatsChangeEmitter.emit(events.TOURNAMENT_STAT_CHANGE_EVENT, new TournamentStatsChangeEvent(tournamentId));
  }, 2000);
  tournamentCalculationTimeouts.set(tournamentId, timeout);
}

tournamentStatsChangeEmitter.on(events.TOURNAMENT_STAT_CHANGE_EVENT, recalculateStats);

async function recalculateStats(statsChangeEvent) {
  console.log('Received request to re-generate stats for tournament ' + statsChangeEvent.tournamentId);
  const statsReportManager = new StatsReportManager(statsChangeEvent.tournamentId);
  const tournamentPhases = await tournamentManager.getPhases(statsChangeEvent.tournamentId);
  for (const phase of tournamentPhases) {
    const phaseId = phase.id;
    statsReportManager.generateAndSavePlayerFullReport(phaseId);
  }
  statsReportManager.generateAndSavePlayerFullReport(null);
}

export default tournamentStatsChangeEmitter;
<commit_msg>Don't recalculate stats on match change<commit_after>import TournamentStatsChangeEmitter from './../event-emitters/stats-change-emitter';
import TournamentStatsChangeEvent from './../events/TournamentStatsChangeEvent';
import { StatsReportManager as StatsReportManager } from './../managers/stats-models/report';
import tournamentManager from './../managers/model-managers/tournament';
import StatReportType from './../enums/stat-report-type';

const tournamentStatsChangeEmitter = new TournamentStatsChangeEmitter();

export const events = {
  TOURNAMENT_STAT_CHANGE_EVENT: 'tournamentStatsChangedEvent',
}

const tournamentCalculationTimeouts = new Map();

export const bufferTournamentStatsChangedEmittion = ({ tournamentId }) => {
  console.log('Buffering stats calculations for tournament ' + tournamentId);
  if (tournamentCalculationTimeouts.has(tournamentId)) {
    clearTimeout(tournamentCalculationTimeouts.get(tournamentId));
    tournamentCalculationTimeouts.delete(tournamentId);
  }
  const timeout = setTimeout(() => {
      tournamentCalculationTimeouts.delete(tournamentId);
      tournamentStatsChangeEmitter.emit(events.TOURNAMENT_STAT_CHANGE_EVENT, new TournamentStatsChangeEvent(tournamentId));
  }, 2000);
  tournamentCalculationTimeouts.set(tournamentId, timeout);
}

tournamentStatsChangeEmitter.on(events.TOURNAMENT_STAT_CHANGE_EVENT, recalculateStats);

async function recalculateStats(statsChangeEvent) {
  console.log('No-op for stats calculation: ' + statsChangeEvent.tournamentId);
}

export default tournamentStatsChangeEmitter;

{'fraction_non_alphanumeric': 0.09668192219679633, 'fraction_numerical': 0.002288329519450801, 'mean_word_length': 6.947727272727272, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '3309914', 'n_tokens_mistral': 978, 'n_tokens_neox': 934, 'n_words': 170}