setIdleOption()

in frontend/app/components/tensorflow_stats/tensorflow_stats.ts [101:179]


  setIdleOption(option: IdleOption = IdleOption.NO) {
    this.idleMenuButtonLabel = option;
    if ((!this.data || this.data.length === 0) ||
        (this.hasDiff && (!this.diffData || this.diffData.length === 0))) {
      this.selectedData = null;
      this.selectedDiffData = null;
      return;
    }

    if (option === IdleOption.YES) {
      this.selectedData = this.data[0] || null;
      if (this.hasDiff && this.diffData) {
        this.selectedDiffData = this.diffData[0] || null;
      }
    } else {
      this.selectedData = this.data[1] || null;
      if (this.hasDiff && this.diffData) {
        this.selectedDiffData = this.diffData[1] || null;
      }
    }

    // Four charts share one DataProvider. In order to prevent DataTable from
    // being created 4 times, it calls DataProvider function directly.
    this.dataProvider.parseData(this.selectedData);

    const dataTable = this.dataProvider.getDataTable();
    let opTypeIndex = -1;
    let opNameIndex = -1;
    let selfTimeIndex = -1;
    let opExecutorIndex = -1;
    if (dataTable && dataTable.getColumnIndex) {
      this.flopRateChartXColumn = dataTable.getColumnIndex(OP_NAME_ID);
      this.flopRateChartYColumn =
          dataTable.getColumnIndex(MEASURED_FLOP_RATE_ID);
      opTypeIndex = dataTable.getColumnIndex(OP_TYPE_ID);
      opNameIndex = dataTable.getColumnIndex(OP_NAME_ID);
      selfTimeIndex = dataTable.getColumnIndex(SELF_TIME_ID);
      opExecutorIndex = dataTable.getColumnIndex(OP_EXECUTOR_ID);
    }

    const filtersForDevice =
        [{column: opExecutorIndex, value: OpExecutor.DEVICE}];
    const filtersForHost = [{column: opExecutorIndex, value: OpExecutor.HOST}];

    this.dataInfoDeviceByType.customChartDataProcessor = this.selectedDiffData ?
        new CategoryDiffTableDataProcessor(
            this.selectedDiffData, filtersForDevice, opTypeIndex,
            selfTimeIndex) :
        new CategoryTableDataProcessor(
            filtersForDevice, opTypeIndex, selfTimeIndex);
    this.dataInfoDeviceByName.customChartDataProcessor =
        new CategoryTableDataProcessor(
            filtersForDevice, opNameIndex, selfTimeIndex);
    this.dataInfoHostByType.customChartDataProcessor = this.selectedDiffData ?
        new CategoryDiffTableDataProcessor(
            this.selectedDiffData, filtersForHost, opTypeIndex, selfTimeIndex) :
        new CategoryTableDataProcessor(
            filtersForHost, opTypeIndex, selfTimeIndex);
    this.dataInfoHostByName.customChartDataProcessor =
        new CategoryTableDataProcessor(
            filtersForHost, opNameIndex, selfTimeIndex);

    // Since the DataInfo has not been updated, the notifyCharts function is
    // called to redraw the graph.
    this.dataProvider.notifyCharts();

    if (this.selectedData && this.selectedData.p) {
      this.architecture = this.selectedData.p.architecture_type || '';
      this.task = this.selectedData.p.task_type || '';
      this.devicePprofLink = this.selectedData.p.device_tf_pprof_link || '';
      this.hostPprofLink = this.selectedData.p.host_tf_pprof_link || '';
    }
    this.hasDeviceData = false;
    if (this.selectedData && this.selectedData.rows) {
      this.hasDeviceData = !!this.selectedData.rows.find(row => {
        return row && row.c && row.c[1] && row.c[1].v === OpExecutor.DEVICE;
      });
    }
  }