<commit_before>// import LogWatcher from 'hearthstone-log-watcher';

import {setWinCondition, setMatchId, setFor, setAgainst, setPlayerId, resetData, setStartTime, setEndTime} from './match-data-manipulation';
import {parseFriendlyPlayer, parseFriendlyPlayerById} from './parse-friendly-player';
import {isMyHero, isHeroCard} from './is-my-hero';
import findClass from './find-class';
import hasWon from './win-condition';

import debug from 'debug';

// TODO: case to be made whereby we turn the for and against values into object
// { playerName: 'foo', playerId: 1}
let dataStructure = {
  _id: "",
  playerId: "",
  startTime: "",
  endTime: "",
  for: "",
  against: "",
  log: [],
  hasWon: ""
};
let database = [];

// Define some debug logging functions for easy and readable debug messages.
let log = {
  main: debug('HT:LV')
};


//TODO: should live somewhere else;
const setHeroValues = (data) => {
  //TODO: write a test to cover the issue resolved in commit 8fcc506
  if (isHeroCard(data)) {
    if (isMyHero(data)) {
      dataStructure = setFor(dataStructure, findClass(data.cardName));
      dataStructure = setPlayerId(dataStructure, data.playerId);
    } else {
      dataStructure = setAgainst(dataStructure, findClass(data.cardName));
    }
  }
  return dataStructure;
};

const fixStartTime = (dataStructure) => {
  dataStructure.startTime = dataStructure.log[0].id;

  return dataStructure;
};

export function dataLogger (logWatcher, db) {

  logWatcher.on('game-start', () => {
    dataStructure = setMatchId(dataStructure);
    dataStructure = setStartTime(dataStructure);
    log.main('game start: %s', dataStructure._id);
  });

  logWatcher.on('game-over', (data) => {
    var winCondition;
    if(!dataStructure._id) {
      log.main('no game start event');
      log.main(data);
      log.main(parseFriendlyPlayerById(data, dataStructure.playerId));
      log.main(hasWon(parseFriendlyPlayerById(data, dataStructure.playerId)));
      dataStructure = setMatchId(dataStructure);
      dataStructure = fixStartTime(dataStructure);
      winCondition = hasWon(parseFriendlyPlayerById(data, dataStructure.playerId));<commit_msg>Add todo<commit_after>// import LogWatcher from 'hearthstone-log-watcher';

import {setWinCondition, setMatchId, setFor, setAgainst, setPlayerId, resetData, setStartTime, setEndTime} from './match-data-manipulation';
import {parseFriendlyPlayer, parseFriendlyPlayerById} from './parse-friendly-player';
import {isMyHero, isHeroCard} from './is-my-hero';
import findClass from './find-class';
import hasWon from './win-condition';

import debug from 'debug';

// TODO: case to be made whereby we turn the for and against values into object
// { playerName: 'foo', playerId: 1}
let dataStructure = {
  _id: "",
  playerId: "",
  startTime: "",
  endTime: "",
  for: "",
  against: "",
  log: [],
  hasWon: ""
};
let database = [];

// Define some debug logging functions for easy and readable debug messages.
let log = {
  main: debug('HT:LV')
};


//TODO: should live somewhere else;
const setHeroValues = (data) => {
  //TODO: write a test to cover the issue resolved in commit 8fcc506
  if (isHeroCard(data)) {
    if (isMyHero(data)) {
      dataStructure = setFor(dataStructure, findClass(data.cardName));
      dataStructure = setPlayerId(dataStructure, data.playerId);
    } else {
      dataStructure = setAgainst(dataStructure, findClass(data.cardName));
    }
  }
  return dataStructure;
};

//TODO: write a test to cover this
const fixStartTime = (dataStructure) => {
  dataStructure.startTime = dataStructure.log[0].id;

  return dataStructure;
};

export function dataLogger (logWatcher, db) {

  logWatcher.on('game-start', () => {
    dataStructure = setMatchId(dataStructure);
    dataStructure = setStartTime(dataStructure);
    log.main('game start: %s', dataStructure._id);
  });

  logWatcher.on('game-over', (data) => {
    var winCondition;
    if(!dataStructure._id) {
      log.main('no game start event');
      log.main(data);
      log.main(parseFriendlyPlayerById(data, dataStructure.playerId));
      log.main(hasWon(parseFriendlyPlayerById(data, dataStructure.playerId)));
      dataStructure = setMatchId(dataStructure);
      dataStructure = fixStartTime(dataStructure);
      winCondition = hasWon(parseFriendlyPlayerById(data, dataStructure.playerId));
{'fraction_non_alphanumeric': 0.13439372982941447, 'fraction_numerical': 0.0027662517289073307, 'mean_word_length': 4.297924297924298, 'pattern_counts': {'":': 0, '<': 3, '<?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': '1503576', 'n_tokens_mistral': 1359, 'n_tokens_neox': 1332, 'n_words': 331}