<commit_before>import {Component, Input, ChangeDetectionStrategy, OnInit} from 'angular2/core';
import {CHART_DIRECTIVES} from 'angular2-highcharts/index';
import {Game} from '../models/game.model';
import {Result} from '../models/result.enum';
import {StatsService} from '../services/stats.service';
import * as _ from 'lodash';

@Component({
  selector: 'agot-game-timeline-chart',
  changeDetection: ChangeDetectionStrategy.OnPush,
  template: `
    <div class="row">
      <chart class="col-xs-12" [options]="options"></chart>
    </div>
  `,
  directives: [CHART_DIRECTIVES]
})
export class GameTimelineChart implements OnInit {
  @Input()
  games:Game[];

  @Input()
  playerId:number;
  @Input()
  deckId:number;

  private options:any = {};

  private labels:any = {
    [Result.WON]: 'Won',
    [Result.DREW]: 'Drew',
    [Result.LOST]: 'Lost'
  };
  private colours:any = {
    [Result.WON]: '#356921',
    [Result.DREW]: '#666',
    [Result.LOST]: '#b30001'
  };

  ngOnInit() {
    const series = this.getDataSeries();
    console.log(series);

    this.options = {
      chart: {},
      title: {
        text: null
      },
      xAxis: {
        type: 'datetime',
      },
      yAxis: {
        title: {
          text: 'Games'
        },
        // stackLabels: {
        //   enabled: true
        // },
        min: 0,
        allowDecimals: false,
        crosshair: true
      },
      plotOptions: {
        column: {
          stacking: 'normal',
          dataLabels: {
            enabled: true,
            color: 'white',
            style: {
              textShadow: '0 0 3px black'
            }
          }
        }
      },
      series: series
    };
  }

  private getDataSeries():any[] {
    const sortedGames = this.getSortedGames();

    if (!this.playerId && !this.deckId) {
      return this.getGameOnlyDataSeries(sortedGames);
    }

    const results = this.getDeckPlayerResults(sortedGames);

    return Object.keys(results).map((key) => {
      return {
        type: 'column',
        name: this.labels[key],
        borderWidth: 1,
        borderColor: '#530001',
        color: this.colours[key],
        pointRange: 24 * 3600 * 1000,
        data: results[key]
      };
    });
  }

  private getGameOnlyDataSeries(sortedGames:[number, Game[]][]) {
    return [{
      type: 'column',
      name: 'Games',
      borderWidth: 1,
      borderColor: '#530001',
      color: '#d30001',
      pointRange: 24 * 3600 * 1000,
      data: sortedGames.map(([dateKey, games]:[number, Game[]]) => {
        return [dateKey, games.length];
      })
    }];
  }

  private getDeckPlayerResults(sortedGames:[number, Game[]][]) {
    const results:any = {
      [Result.WON]: [],
      [Result.DREW]: [],
      [Result.LOST]: []
    };
    sortedGames.forEach(([dateKey, games]:[number, Game[]]) => {
      const resultsForDay = this.playerId ?
        getDayResultsForPlayer(games, this.playerId) :
        getDayResultsForDeck(games, this.deckId);
      Object.keys(results).forEach((key) => {
        const dayResults = resultsForDay.get(+key);
        if (dayResults) {
          results[key].push([dateKey, dayResults]);
        }<commit_msg>Temp dance around tsliny errors<commit_after>import {Component, Input, ChangeDetectionStrategy, OnInit} from 'angular2/core';
import {CHART_DIRECTIVES} from 'angular2-highcharts/index';
import {Game} from '../models/game.model';
import {Result} from '../models/result.enum';
import {StatsService} from '../services/stats.service';
import * as _ from 'lodash';

@Component({
  selector: 'agot-game-timeline-chart',
  changeDetection: ChangeDetectionStrategy.OnPush,
  template: `
    <div class="row">
      <chart class="col-xs-12" [options]="options"></chart>
    </div>
  `,
  directives: [CHART_DIRECTIVES]
})
export class GameTimelineChart implements OnInit {
  @Input()
  games:Game[];

  @Input()
  playerId:number;
  @Input()
  deckId:number;

  private options:any = {};

  private labels:any = {
    [Result.WON]: 'Won',
    [Result.DREW]: 'Drew',
    [Result.LOST]: 'Lost'
  };
  private colours:any = {
    [Result.WON]: '#356921',
    [Result.DREW]: '#666',
    [Result.LOST]: '#b30001'
  };

  ngOnInit() {
    const series = this.getDataSeries();
    console.log(series);

    this.options = {
      chart: {},
      title: {
        text: null
      },
      xAxis: {
        type: 'datetime',
      },
      yAxis: {
        title: {
          text: 'Games'
        },
        // stackLabels: {
        //   enabled: true
        // },
        min: 0,
        allowDecimals: false,
        crosshair: true
      },
      plotOptions: {
        column: {
          stacking: 'normal',
          dataLabels: {
            enabled: true,
            color: 'white',
            style: {
              textShadow: '0 0 3px black'
            }
          }
        }
      },
      series: series
    };
  }

  private getDataSeries():any[] {
    const sortedGames = this.getSortedGames();

    if (!this.playerId && !this.deckId) {
      return this.getGameOnlyDataSeries(sortedGames);
    }

    const results = this.getDeckPlayerResults(sortedGames);

    return Object.keys(results).map((key) => {
      return {
        type: 'column',
        name: this.labels[key],
        borderWidth: 1,
        borderColor: '#530001',
        color: this.colours[key],
        pointRange: 24 * 3600 * 1000,
        data: results[key]
      };
    });
  }

  private getGameOnlyDataSeries(sortedGames) {
    return [{
      type: 'column',
      name: 'Games',
      borderWidth: 1,
      borderColor: '#530001',
      color: '#d30001',
      pointRange: 24 * 3600 * 1000,
      data: sortedGames.map(([dateKey, games]) => {
        return [dateKey, games.length];
      })
    }];
  }

  private getDeckPlayerResults(sortedGames:[number, Game[]][]) {
    const results:any = {
      [Result.WON]: [],
      [Result.DREW]: [],
      [Result.LOST]: []
    };
    sortedGames.forEach(([dateKey, games]:[number, Game[]]) => {
      const resultsForDay = this.playerId ?
        getDayResultsForPlayer(games, this.playerId) :
        getDayResultsForDeck(games, this.deckId);
      Object.keys(results).forEach((key) => {
        const dayResults = resultsForDay.get(+key);
        if (dayResults) {
          results[key].push([dateKey, dayResults]);
        }
{'fraction_non_alphanumeric': 0.15457413249211358, 'fraction_numerical': 0.019242902208201892, 'mean_word_length': 2.277002583979328, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 19, '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': '5445687', 'n_tokens_mistral': 2160, 'n_tokens_neox': 2033, 'n_words': 394}