{"size": 2582, "ext": "js", "max_stars_repo_path": "assets/js/app/mads-cmv/components/Views/RFFeature.js", "max_stars_repo_name": "truemrwalker/mads-app", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "assets/js/app/mads-cmv/components/Views/RFFeature.js", "max_issues_repo_name": "truemrwalker/mads-app", "max_issues_repo_issues_event_min_datetime": "2021-04-22T06:57:27.000Z", "max_issues_repo_issues_event_max_datetime": "2021-08-06T03:19:42.000Z", "max_forks_repo_path": "assets/js/app/mads-cmv/components/Views/RFFeature.js", "max_forks_repo_name": "truemrwalker/mads-app", "max_forks_repo_forks_event_min_datetime": "2021-02-12T01:19:44.000Z", "max_forks_repo_forks_event_max_datetime": "2021-05-14T06:54:34.000Z"}
{"max_stars_count": null, "max_issues_count": 2, "max_forks_count": 2, "avg_line_length": 25.067961165, "max_line_length": 75, "alphanum_fraction": 0.6285824942}
// import { connect } from 'react-redux';

import { DataFrame } from 'pandas-js';

import withCommandInterface from './ViewWrapper';
// import QuadBarChart from '../VisComponents/QuadBarChart';
import BarChart from '../VisComponents/BarChart';
import RFFeatureForm from './RFFeatureForm';

import convertExtentValues from './FormUtils';

const settings = {
  options: {
    title: 'Feature Importance (RF)',
    legendLocation: 'top_left',
    extent: { width: 600, height: 400 },
    xaxis_orientation: 'vertical',
  },
};

class RFFeatureView extends withCommandInterface(
  BarChart,
  RFFeatureForm,
  settings
) {
  handleSelectionChange = (indices) => {
    // const { dataset, updateSelection, } = this.props;
    // const data = this.mapData(dataset);
    // console.log(data);
    // let selections = [];
    // indices.forEach((i) => {
    //   const idx = data.indices[i];
    //   selections = [...selections, ...idx];
    // });
    // console.log(selections);
    // updateSelection(selections);
  };

  getSelection = (selection) => {
    // do nothing
  };

  handleSubmit = (values) => {
    console.log(values);

    const { id, view, colorTags, actions, dataset } = this.props;

    let newValues = { ...values };

    // filter out non-existing columns & colorTags
    if (values.filter) {
      const colorTagIds = colorTags.map((c) => c.id);
      const filteredFilters = values.filter.filter((f) =>
        colorTagIds.includes(f)
      );
      newValues.filter = filteredFilters;
    }

    // filter out featureColumns
    const columns = this.getColumnOptionArray();
    console.log(columns);
    if (values.featureColumns) {
      const filteredColumns = values.featureColumns.filter((f) =>
        columns.includes(f)
      );
      newValues.featureColumns = filteredColumns;
    }

    if (newValues.featureColumns.length === 0 || !newValues.targetColumn) {
      return;
    }

    // extract data
    const data = {};
    const df = new DataFrame(dataset.main.data);
    const tc = df.get(newValues.targetColumn);
    data[newValues.targetColumn] = tc.values.toArray();
    newValues.featureColumns.forEach((c) => {
      const fc = df.get(c);
      data[c] = fc.values.toArray();
    });

    console.log(data);
    newValues = convertExtentValues(newValues);

    actions.sendRequestViewUpdate(view, newValues, data);
    // updateView(id, newValues);
  };

  mapData = (dataset) => {
    const { id } = this.props;
    let data = {};

    if (dataset[id]) {
      data = dataset[id];
    }

    return data;
  };
}

export default RFFeatureView;
