<commit_before>import {Injectable} from '@angular/core';
import {Dimension} from '../models/table-models/dimension';
import {DataTable} from '../models/table-models/data-table';
import {Row} from '../models/table-models/row';
import {ResourceService} from './resource.service';
import {Col} from '../models/table-models/col';
import {ConstraintService} from './constraint.service';
import {CombinationConstraint} from '../models/constraint-models/combination-constraint';
import {HeaderRow} from '../models/table-models/header-row';
import {DimensionValue} from '../models/table-models/dimension-value';

@Injectable()
export class TableService {

  private _prevRowDimensions: Array<Dimension>;
  private _prevColDimensions: Array<Dimension>;
  private _dataTable: DataTable;
  private _currentPage: number;

  constructor(private resourceService: ResourceService,
              private constraintService: ConstraintService) {
    this.dataTable = new DataTable();
    this.prevRowDimensions = [];
    this.prevColDimensions = [];
    this.currentPage = 1;
    this.updateDataTable();
  }

  updateDataTable(targetDataTable?: DataTable) {
    this.dataTable.isDirty = true;
    this.dataTable.isUpdating = true;
    this.dataTable = targetDataTable ? targetDataTable : this.dataTable;
    const constraint_1_2 = this.constraintService.constraint_1_2();
    this.dataTable.constraint = constraint_1_2;
    this.dataTable.offset = this.currentOffset();
    this.resourceService.getDimensions(constraint_1_2)
      .subscribe((availableDimensions: Dimension[]) => {
        // update dimensions
        let availableDimensionNames = new Array<string>();
        availableDimensions.forEach((dim: Dimension) => {
          availableDimensionNames.push(dim.name);
        });
        let takenDimensionNames = new Array<string>();
        let newRowDimensions = new Array<Dimension>();
        this.dataTable.rowDimensions.forEach((dim: Dimension) => {
          if (availableDimensionNames.includes(dim.name)) {
            newRowDimensions.push(dim);
            takenDimensionNames.push(dim.name);
          }
        });
        let newColumnDimensions = new Array<Dimension>();
        this.dataTable.columnDimensions.forEach((dim: Dimension) => {
          if (availableDimensionNames.includes(dim.name)) {
            newColumnDimensions.push(dim);
            takenDimensionNames.push(dim.name);
          }
        });
        availableDimensions.forEach((dim: Dimension) => {
          if (!takenDimensionNames.includes(dim.name)) {
            this.dataTable.rowDimensions.push(dim);
          }
        });
        this.resourceService.getDataTable(this.dataTable)
          .subscribe(
            (newDataTable: DataTable) => {
              this.dataTable = newDataTable;
              this.dataTable.isDirty = false;
              this.dataTable.isUpdating = false;
            }
          );
      });
  }

  public nextPage() {
    if(!this.dataTable.isLastPage) {
      this.currentPage++;
      this.updateDataTable();
    }
  }

  public previousPage() {
    if (this.currentPage > 1) {
      this.currentPage--;
      this.updateDataTable();
    }
  }

  currentOffset(): number {
    return this.dataTable.limit * (this.currentPage - 1)
  }

  get rowDimensions(): Dimension[] {
    return this.dataTable.rowDimensions;
  }

  set rowDimensions(value: Dimension[]) {
    this.dataTable.rowDimensions = value;
  }

  get columnDimensions(): Dimension[] {
    return this.dataTable.columnDimensions;
  }

  set columnDimensions(value: Dimension[]) {
    this.dataTable.columnDimensions = value;
  }

  get rows(): Row[] {
    return this.dataTable.rows;
  }

  get cols(): Col[] {
    return this.dataTable.cols;
  }

  get headerRows(): Array<HeaderRow> {
    return this.dataTable.headerRows;
  }

  get dataTable(): DataTable {
    return this._dataTable;
  }

  set dataTable(value: DataTable) {
    this._dataTable = value;
  }

  get prevRowDimensions(): Array<Dimension> {
    return this._prevRowDimensions;
  }

  set prevRowDimensions(value: Array<Dimension>) {
    this._prevRowDimensions = value;
  }

  get prevColDimensions(): Array<Dimension> {
    return this._prevColDimensions;
  }

  set prevColDimensions(value: Array<Dimension>) {
    this._prevColDimensions = value;
  }

  get currentPage(): number {
    return this._currentPage;
  }

  set currentPage(value: number) {
    this._currentPage = value;
  }

  get isUsingHeaders(): boolean {
    return this.dataTable.isUsingHeaders;
  }

}
<commit_msg>update prev dimensions in table<commit_after>import {Injectable} from '@angular/core';
import {Dimension} from '../models/table-models/dimension';
import {DataTable} from '../models/table-models/data-table';
import {Row} from '../models/table-models/row';
import {ResourceService} from './resource.service';
import {Col} from '../models/table-models/col';
import {ConstraintService} from './constraint.service';
import {CombinationConstraint} from '../models/constraint-models/combination-constraint';
import {HeaderRow} from '../models/table-models/header-row';
import {DimensionValue} from '../models/table-models/dimension-value';

@Injectable()
export class TableService {

  private _prevRowDimensions: Array<Dimension>;
  private _prevColDimensions: Array<Dimension>;
  private _dataTable: DataTable;
  private _currentPage: number;

  constructor(private resourceService: ResourceService,
              private constraintService: ConstraintService) {
    this.dataTable = new DataTable();
    this.prevRowDimensions = [];
    this.prevColDimensions = [];
    this.currentPage = 1;
    this.updateDataTable();
  }

  updateDataTable(targetDataTable?: DataTable) {
    this.dataTable.isDirty = true;
    this.dataTable.isUpdating = true;
    this.dataTable = targetDataTable ? targetDataTable : this.dataTable;
    const constraint_1_2 = this.constraintService.constraint_1_2();
    this.dataTable.constraint = constraint_1_2;
    this.dataTable.offset = this.currentOffset();
    this.resourceService.getDimensions(constraint_1_2)
      .subscribe((availableDimensions: Dimension[]) => {
        // update dimensions
        let availableDimensionNames = new Array<string>();
        availableDimensions.forEach((dim: Dimension) => {
          availableDimensionNames.push(dim.name);
        });
        let takenDimensionNames = new Array<string>();
        let newRowDimensions = new Array<Dimension>();
        this.dataTable.rowDimensions.forEach((dim: Dimension) => {
          if (availableDimensionNames.includes(dim.name)) {
            newRowDimensions.push(dim);
            takenDimensionNames.push(dim.name);
          }
        });
        let newColumnDimensions = new Array<Dimension>();
        this.dataTable.columnDimensions.forEach((dim: Dimension) => {
          if (availableDimensionNames.includes(dim.name)) {
            newColumnDimensions.push(dim);
            takenDimensionNames.push(dim.name);
          }
        });
        availableDimensions.forEach((dim: Dimension) => {
          if (!takenDimensionNames.includes(dim.name)) {
            this.dataTable.rowDimensions.push(dim);
          }
        });
        this.resourceService.getDataTable(this.dataTable)
          .subscribe(
            (newDataTable: DataTable) => {
              this.dataTable = newDataTable;
              this.dataTable.isDirty = false;
              this.dataTable.isUpdating = false;
              this.updatePrevDimensions();
            }
          );
      });
  }

  public nextPage() {
    if(!this.dataTable.isLastPage) {
      this.currentPage++;
      this.updateDataTable();
    }
  }

  public previousPage() {
    if (this.currentPage > 1) {
      this.currentPage--;
      this.updateDataTable();
    }
  }

  currentOffset(): number {
    return this.dataTable.limit * (this.currentPage - 1)
  }

  public updatePrevDimensions() {
    this.prevRowDimensions = [];
    this.rowDimensions.forEach((dim: Dimension) => {
      this.prevRowDimensions.push(new Dimension(dim.name));
    });
    this.prevColDimensions = [];
    this.columnDimensions.forEach((dim: Dimension) => {
      this.prevColDimensions.push(new Dimension(dim.name));
    });
  }

  get rowDimensions(): Dimension[] {
    return this.dataTable.rowDimensions;
  }

  set rowDimensions(value: Dimension[]) {
    this.dataTable.rowDimensions = value;
  }

  get columnDimensions(): Dimension[] {
    return this.dataTable.columnDimensions;
  }

  set columnDimensions(value: Dimension[]) {
    this.dataTable.columnDimensions = value;
  }

  get rows(): Row[] {
    return this.dataTable.rows;
  }

  get cols(): Col[] {
    return this.dataTable.cols;
  }

  get headerRows(): Array<HeaderRow> {
    return this.dataTable.headerRows;
  }

  get dataTable(): DataTable {
    return this._dataTable;
  }

  set dataTable(value: DataTable) {
    this._dataTable = value;
  }

  get prevRowDimensions(): Array<Dimension> {
    return this._prevRowDimensions;
  }

  set prevRowDimensions(value: Array<Dimension>) {
    this._prevRowDimensions = value;
  }

  get prevColDimensions(): Array<Dimension> {
    return this._prevColDimensions;
  }

  set prevColDimensions(value: Array<Dimension>) {
    this._prevColDimensions = value;
  }

  get currentPage(): number {
    return this._currentPage;
  }

  set currentPage(value: number) {
    this._currentPage = value;
  }

  get isUsingHeaders(): boolean {
    return this.dataTable.isUsingHeaders;
  }

}

{'fraction_non_alphanumeric': 0.12385466034755134, 'fraction_numerical': 0.002317008952080042, 'mean_word_length': 3.0860585197934594, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 41, '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': '6181127', 'n_tokens_mistral': 2761, 'n_tokens_neox': 2745, 'n_words': 489}