<commit_before>import {DataTableCell, DataTableColumn, DataTableRow, Filter, GeneralDataTable} from 'org_xprof/frontend/app/common/interfaces/data_table';

class DataTableForTesting {
  constructor(
      public data: GeneralDataTable|null = {cols: [], rows: [], p: {}}) {}
  addColumn(type: string, label?: string, id?: string) {
    this.data?.cols?.push({type, label, id});
  }
  clone() {
    return new DataTableForTesting(this.data);
  }
  getColumnIndex(column: number|string): number {
    if (!this.data || !this.data.cols) {
      return -1;
    }

    for (let i = 0; i < this.data.cols.length; i++) {
      if (this.data.cols[i].id === column ||
          this.data.cols[i].label === column) {
        return i;
      }
    }

    return -1;
  }
  getColumnLabel(columnIndex: number): string {
    if (!this.data || !this.data.cols) {
      return '';
    }
    if (columnIndex >= this.data.cols.length) {
      return '';
    }
    return this.data.cols[columnIndex].label as string;
  }
  getColumnType(columnIdx: number) {
    if (!this.data || !this.data.cols || this.data.cols.length <= columnIdx) {
      return null;
    }
    return this.data.cols[columnIdx].type;
  }
  getColumnId(columnIdx: number) {
    if (!this.data || !this.data.cols || this.data.cols.length <= columnIdx) {
      return '';
    }
    return this.data.cols[columnIdx].id;
  }
  getColumnRange(columnIdx: number) {
    if (!this.data || !this.data.rows) {
      return [Infinity, -Infinity];
    }
    let min = Infinity;
    let max = -Infinity;
    this.data.rows.forEach(row => {
      const val = row.c![columnIdx].v as number;
      min = Math.min(val, min);
      max = Math.max(val, max);
    });
    return [min, max];
  }
  getDistinctValues() {
    return [];
  }
  getNumberOfColumns() {
    if (!this.data || !this.data.cols) {
      return -1;
    }
    return this.data.cols.length;
  }
  getNumberOfRows() {
    if (!this.data || !this.data.rows) {
      return -1;
    }
    return this.data.rows.length;
  }
  getValue() {
    return 0;
  }
  getTableProperty(propName: string): string {
    if (!this.data || !this.data.p) {
      return '';
    }
    return this.data.p[propName];
  }
  getFilteredRows(filters: Filter[]): number[] {
    if (!this.data || !this.data.rows) {
      return [];
    }
    if (filters === []) {
      return [
        ...Array.from<number>({length: this.data.rows.length}).fill(0).keys()
      ];
    }
    const rowsIdxArray: number[] = [];
    this.data.rows.forEach((row, index) => {
      const includeRow = filters.reduce((include, filter) => {
        if (!this.data!.cols || this.data!.cols.length <= filter.column) {
          return include;
        }
        return include && row.c![filter.column] === filter.value;
      }, true);
      if (includeRow) {
        rowsIdxArray.push(index);
      }
    });
    return rowsIdxArray;
  }
  insertColumn() {}<commit_msg>Project import generated by Copybara<commit_after>import {DataTableCell, DataTableColumn, DataTableRow, Filter, GeneralDataTable} from 'org_xprof/frontend/app/common/interfaces/data_table';

class DataTableForTesting {
  constructor(
      public data: GeneralDataTable|null = {cols: [], rows: [], p: {}}) {}
  addColumn(type: string, label?: string, id?: string) {
    this.data?.cols?.push({type, label, id});
  }
  clone() {
    return new DataTableForTesting(this.data);
  }
  getColumnIndex(column: number|string): number {
    if (!this.data || !this.data.cols) {
      return -1;
    }

    for (let i = 0; i < this.data.cols.length; i++) {
      if (this.data.cols[i].id === column ||
          this.data.cols[i].label === column) {
        return i;
      }
    }

    return -1;
  }
  getColumnLabel(columnIndex: number): string {
    if (!this.data || !this.data.cols) {
      return '';
    }
    if (columnIndex >= this.data.cols.length) {
      return '';
    }
    return this.data.cols[columnIndex].label as string;
  }
  getColumnType(columnIdx: number) {
    if (!this.data || !this.data.cols || this.data.cols.length <= columnIdx) {
      return null;
    }
    return this.data.cols[columnIdx].type;
  }
  getColumnId(columnIdx: number) {
    if (!this.data || !this.data.cols || this.data.cols.length <= columnIdx) {
      return '';
    }
    return this.data.cols[columnIdx].id;
  }
  getColumnRange(columnIdx: number) {
    if (!this.data || !this.data.rows) {
      return [Infinity, -Infinity];
    }
    let min = Infinity;
    let max = -Infinity;
    this.data.rows.forEach(row => {
      const val = row.c![columnIdx].v as number;
      min = Math.min(val, min);
      max = Math.max(val, max);
    });
    return [min, max];
  }
  getDistinctValues() {
    return [];
  }
  getNumberOfColumns() {
    if (!this.data || !this.data.cols) {
      return -1;
    }
    return this.data.cols.length;
  }
  getNumberOfRows() {
    if (!this.data || !this.data.rows) {
      return -1;
    }
    return this.data.rows.length;
  }
  getValue() {
    return 0;
  }
  getTableProperty(propName: string): string {
    if (!this.data || !this.data.p) {
      return '';
    }
    return this.data.p[propName];
  }
  getFilteredRows(filters: Filter[]): number[] {
    if (!this.data || !this.data.rows) {
      return [];
    }
    if (filters === ([] as AnyDuringTs48Migration)) {
      return [
        ...Array.from<number>({length: this.data.rows.length}).fill(0).keys()
      ];
    }
    const rowsIdxArray: number[] = [];
    this.data.rows.forEach((row, index) => {
      const includeRow = filters.reduce((include, filter) => {
        if (!this.data!.cols || this.data!.cols.length <= filter.column) {
          return include;
        }
        return include && row.c![filter.column] === filter.value;
      }, true);
      if (includeRow) {
        rowsIdxArray.push(index);
      }
    });
    return rowsIdxArray;
  }
  insertColumn() {}
{'fraction_non_alphanumeric': 0.16912888436067244, 'fraction_numerical': 0.00271692986924775, 'mean_word_length': 2.487270574304322, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, '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': '4115207', 'n_tokens_mistral': 1986, 'n_tokens_neox': 1969, 'n_words': 380}