<commit_before>import {
  Component,
  ElementRef,
  OnInit,
  AfterViewInit,
  ChangeDetectorRef} from 'angular2/core';

import {StaticData} from './StaticData';
import {LogsService} from './logs.service';
import {SpinnerComponent} from './spinner';
import * as API from './soapy.api.interfaces';
import * as Rx from 'rxjs/Rx';

declare var jQuery: JQueryStatic;

interface DisplayLogEvent extends API.LogEvent {
  DisplayTime?: string;
}


@Component({
  directives: [
    SpinnerComponent,
  ],
  selector: 'logs-card',
  template: StaticData.templates.LogsCard,
})
export class LogsCardComponent implements OnInit, AfterViewInit {
  private _currentBathroom: string = null;
  private _currentSubscription: Rx.Subscription = null;
  private _events: DisplayLogEvent[] = [];
  private _dontRerenderLoggings = false;
  private _isPaused: boolean = false;
  private $el: JQuery;

  constructor(private el: ElementRef,
              private _logsService: LogsService,
              private _changeDetector: ChangeDetectorRef) {
    this.$el = jQuery(this.el.nativeElement);
  }

  public ngOnInit() {
    if (this.bathrooms.length > 0) {
      this.chooseBathroom(this.bathrooms[0]);
    }
  }

  public ngAfterViewInit() {
    this.$el.hide().fadeIn();
  }

  public get hasBathrooms(): boolean {
    return this.bathrooms.length > 0;
  }

  public get bathrooms(): string[] {
    return this._logsService.getBathroomNames();
  }

  public get currentBathroom(): string {
    return this._currentBathroom;
  }

  public chooseBathroom(bathroom: string) {
    if (this._currentBathroom === bathroom) {
      return;
    }

    this._currentBathroom = bathroom;

    this.removeCurrentSubscription();
    this._events = [];

    this._dontRerenderLoggings = true;
    this._currentSubscription = this._logsService
      .eventsForBathroom(bathroom)
      .subscribe(this.eventHandler.bind(this));
    this._logsService.subscribeToLog(bathroom);
    this._isPaused = false;

    this._changeDetector.detectChanges();
    this._dontRerenderLoggings = false;
  }

  public pause() {
    if (this._isPaused) {
      return;
    }

    this._logsService.unsubscribeFromAllLogs();
    this._isPaused = true;
  }

  public resume() {
    if (!this._isPaused) {
      return;
    }

    if (this._currentBathroom !== null) {
      this._logsService.subscribeToLog(this._currentBathroom);
    }
    this._isPaused = false;
  }

  public toggleRealtime() {
    if (this.isPaused) {
      this.resume();
    } else {
      this.pause();
    }
  }

  public eventHandler(events: API.LogEvent[]) {
    events.forEach(event => {
      var displayEvent = <DisplayLogEvent> event;
      var date = new Date(displayEvent.Time);
      displayEvent.DisplayTime = date.getMonth() + "/" + date.getDate() +
        " " + date.getHours() + ":" + date.getMinutes() + ":" +
        date.getSeconds();
      this._events.unshift(displayEvent);
    });

    if (!this._dontRerenderLoggings) {
      this._changeDetector.detectChanges();
    }
  }

  public get events(): DisplayLogEvent[] {
    return this._events;
  }

  public get isPaused(): boolean {
    return this._isPaused;
  }

  public get showSpinner(): boolean {
    return this._events.length === 0;
  }

  private removeCurrentSubscription() {
    if (this._currentSubscription) {
      this._currentSubscription.unsubscribe();
      this._currentSubscription = null;
    }
  }
}

<commit_msg>Web: Display correct month in logs.<commit_after>import {
  Component,
  ElementRef,
  OnInit,
  AfterViewInit,
  ChangeDetectorRef} from 'angular2/core';

import {StaticData} from './StaticData';
import {LogsService} from './logs.service';
import {SpinnerComponent} from './spinner';
import * as API from './soapy.api.interfaces';
import * as Rx from 'rxjs/Rx';

declare var jQuery: JQueryStatic;

interface DisplayLogEvent extends API.LogEvent {
  DisplayTime?: string;
}


@Component({
  directives: [
    SpinnerComponent,
  ],
  selector: 'logs-card',
  template: StaticData.templates.LogsCard,
})
export class LogsCardComponent implements OnInit, AfterViewInit {
  private _currentBathroom: string = null;
  private _currentSubscription: Rx.Subscription = null;
  private _events: DisplayLogEvent[] = [];
  private _dontRerenderLoggings = false;
  private _isPaused: boolean = false;
  private $el: JQuery;

  constructor(private el: ElementRef,
              private _logsService: LogsService,
              private _changeDetector: ChangeDetectorRef) {
    this.$el = jQuery(this.el.nativeElement);
  }

  public ngOnInit() {
    if (this.bathrooms.length > 0) {
      this.chooseBathroom(this.bathrooms[0]);
    }
  }

  public ngAfterViewInit() {
    this.$el.hide().fadeIn();
  }

  public get hasBathrooms(): boolean {
    return this.bathrooms.length > 0;
  }

  public get bathrooms(): string[] {
    return this._logsService.getBathroomNames();
  }

  public get currentBathroom(): string {
    return this._currentBathroom;
  }

  public chooseBathroom(bathroom: string) {
    if (this._currentBathroom === bathroom) {
      return;
    }

    this._currentBathroom = bathroom;

    this.removeCurrentSubscription();
    this._events = [];

    this._dontRerenderLoggings = true;
    this._currentSubscription = this._logsService
      .eventsForBathroom(bathroom)
      .subscribe(this.eventHandler.bind(this));
    this._logsService.subscribeToLog(bathroom);
    this._isPaused = false;

    this._changeDetector.detectChanges();
    this._dontRerenderLoggings = false;
  }

  public pause() {
    if (this._isPaused) {
      return;
    }

    this._logsService.unsubscribeFromAllLogs();
    this._isPaused = true;
  }

  public resume() {
    if (!this._isPaused) {
      return;
    }

    if (this._currentBathroom !== null) {
      this._logsService.subscribeToLog(this._currentBathroom);
    }
    this._isPaused = false;
  }

  public toggleRealtime() {
    if (this.isPaused) {
      this.resume();
    } else {
      this.pause();
    }
  }

  public eventHandler(events: API.LogEvent[]) {
    events.forEach(event => {
      var displayEvent = <DisplayLogEvent> event;
      var date = new Date(displayEvent.Time);
      displayEvent.DisplayTime = (date.getMonth() + 1) + "/" + date.getDate() +
        " " + date.getHours() + ":" + date.getMinutes() + ":" +
        date.getSeconds();
      this._events.unshift(displayEvent);
    });

    if (!this._dontRerenderLoggings) {
      this._changeDetector.detectChanges();
    }
  }

  public get events(): DisplayLogEvent[] {
    return this._events;
  }

  public get isPaused(): boolean {
    return this._isPaused;
  }

  public get showSpinner(): boolean {
    return this._events.length === 0;
  }

  private removeCurrentSubscription() {
    if (this._currentSubscription) {
      this._currentSubscription.unsubscribe();
      this._currentSubscription = null;
    }
  }
}


{'fraction_non_alphanumeric': 0.12329363926808017, 'fraction_numerical': 0.001597444089456869, 'mean_word_length': 3.2019524100061014, 'pattern_counts': {'":': 4, '<': 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': '6116479', 'n_tokens_mistral': 2238, 'n_tokens_neox': 2161, 'n_words': 426}