<commit_before>import { Component, OnInit, OnDestroy, ViewChild } from '@angular/core';
import { ColumnMode, TableColumn, TableOptions, DataTable } from 'angular2-data-table';
import { ProcessInformation, ProcessesService } from './shared/processes/processes.service';
import { Subscription } from 'rxjs';

@Component({
  selector: 'em-process-explorer',
  templateUrl: './process-explorer.component.html',
  styleUrls: ['process-explorer.component.scss'],
  providers: [
    ProcessesService
  ]
})
export class ProcessExplorerComponent implements OnInit, OnDestroy {
  @ViewChild(DataTable)
  private table: DataTable;

  private dataSubscription: Subscription = null;

  private interval = 5;

  private rows: Array<{pid: string, name: string, cpu: string, memory: string}> = [];

  private options = new TableOptions({
    columnMode: ColumnMode.force,
    headerHeight: 50,
    footerHeight: 50,
    detailRowHeight: 56,
    rowHeight: 'auto',
    columns: [
      new TableColumn({ name: 'Pid', comparator: this.sorter.bind(this) }),
      new TableColumn({ name: 'Name', sortable: true, comparator: this.sorter.bind(this) }),
      new TableColumn({ name: 'Cpu', comparator: this.sorter.bind(this) }),
      new TableColumn({ name: 'Memory', comparator: this.sorter.bind(this) }),
    ]
  });

  constructor(private processes: ProcessesService) {
    this.processes.getProcesses().then(data => this.rows = data.map(row => this.convertProcessInformation(row)));
  }

  ngOnInit() {
    this.setupSubscription();
  }

  convertProcessInformation(inf: ProcessInformation): {pid: string, name: string, cpu: string, memory: string} {
    return {
      pid: inf.pid,
      name: inf.name,
      cpu: `${inf.cpu}%`,
      memory: `${inf.memory.toFixed(2)}GB`
    };
  }

  sorter(rows, dirs) {
    this.processes.sortingProperty = dirs[0].prop;
    this.processes.sortingOrder = dirs[0].dir == 'desc' ? 1 : -1;
    this.processes.getProcesses().then(data =>  this.rows = data.map(row => this.convertProcessInformation(row)));
  }

  killProcess(pid) {
    this.processes.killProcess(pid);
  }

  toggleExpandRow(row) {
    this.toggleSubscription();
    this.table.toggleExpandRow(row);
  }

  toggleSubscription() {
    if (this.dataSubscription) {
      this.removeSubscription();
    } else {
      this.setupSubscription();
    }
  }

  setupSubscription() {
    this.dataSubscription = this.processes.getProcessesInInterval(this.interval).subscribe(data => {
      this.rows = data.map(row => this.convertProcessInformation(row));
    });
  }

  removeSubscription() {
    this.dataSubscription.unsubscribe();
    this.dataSubscription = null;
  }

  ngOnDestroy() {
    this.removeSubscription();
  }
}<commit_msg>fixing process explorer bug<commit_after>import { Component, OnInit, OnDestroy, ViewChild } from '@angular/core';
import { ColumnMode, TableColumn, TableOptions, DataTable } from 'angular2-data-table';
import { ProcessInformation, ProcessesService } from './shared/processes/processes.service';
import { Subscription } from 'rxjs';

@Component({
  selector: 'em-process-explorer',
  templateUrl: './process-explorer.component.html',
  styleUrls: ['process-explorer.component.scss'],
  providers: [
    ProcessesService
  ]
})
export class ProcessExplorerComponent implements OnInit, OnDestroy {
  @ViewChild(DataTable)
  private table: DataTable;

  private dataSubscription: Subscription = null;

  private interval = 5;

  private rows: Array<{pid: string, name: string, cpu: string, memory: string}> = [];

  private options = new TableOptions({
    columnMode: ColumnMode.force,
    headerHeight: 50,
    footerHeight: 50,
    detailRowHeight: 56,
    rowHeight: 'auto',
    columns: [
      new TableColumn({ name: 'Pid', comparator: this.sorter.bind(this) }),
      new TableColumn({ name: 'Name', sortable: true, comparator: this.sorter.bind(this) }),
      new TableColumn({ name: 'Cpu', comparator: this.sorter.bind(this) }),
      new TableColumn({ name: 'Memory', comparator: this.sorter.bind(this) }),
    ]
  });

  constructor(private processes: ProcessesService) {
    this.processes.getProcesses().then(data => this.rows = data.map(row => this.convertProcessInformation(row)));
  }

  ngOnInit() {
    this.setupSubscription();
  }

  convertProcessInformation(inf: ProcessInformation): {pid: string, name: string, cpu: string, memory: string} {
    return {
      pid: inf.pid,
      name: inf.name,
      cpu: `${inf.cpu}%`,
      memory: `${inf.memory.toFixed(2)}GB`
    };
  }

  sorter(rows, dirs) {
    this.processes.sortingProperty = dirs[0].prop;
    this.processes.sortingOrder = dirs[0].dir == 'desc' ? 1 : -1;
    this.processes.getProcesses().then(data =>  this.rows = data.map(row => this.convertProcessInformation(row)));
  }

  killProcess(pid) {
    this.processes.killProcess(pid);
  }

  toggleExpandRow(row) {
    this.toggleSubscription();
    this.table.toggleExpandRow(row);
  }

  toggleSubscription() {
    if (this.dataSubscription) {
      this.removeSubscription();
    } else {
      this.setupSubscription();
    }
  }

  setupSubscription() {
    this.dataSubscription = this.processes.getProcessesInInterval(this.interval).subscribe(data => {
      this.rows = data.map(row => this.convertProcessInformation(row));
    });
  }

  removeSubscription() {
    if (this.dataSubscription) {
      this.dataSubscription.unsubscribe();
      this.dataSubscription = undefined;
    }
  }

  ngOnDestroy() {
    this.removeSubscription();
  }
}
{'fraction_non_alphanumeric': 0.14371366279069767, 'fraction_numerical': 0.004723837209302325, 'mean_word_length': 3.8759964570416297, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 17, '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': '7389674', 'n_tokens_mistral': 1725, 'n_tokens_neox': 1701, 'n_words': 333}