diff --git a/media/js/src/simulations/simulation1/scatterPlot.jsx b/media/js/src/simulations/simulation1/scatterPlot.jsx index d054232..8b91890 100644 --- a/media/js/src/simulations/simulation1/scatterPlot.jsx +++ b/media/js/src/simulations/simulation1/scatterPlot.jsx @@ -3,9 +3,7 @@ import Plot from 'react-plotly.js'; import seedrandom from 'seedrandom'; import axios from 'axios'; import PropTypes from 'prop-types'; -// import { saveAs } from 'file-saver'; -// const isSuperUser = window.MetricsMentor.currentUser.is_superuser; export const ScatterPlot = ({ N, yCorrelation, seed, setAppRvalue, setSlope, setIntercept, setStderror, plotType, setSlopes, @@ -122,25 +120,6 @@ export const ScatterPlot = ({ N, yCorrelation, seed, setAppRvalue, } }; - // const exportCSV = () => { - // let headers = ['x', 'y']; - // if (plotType === '3d') { - // headers.push('z'); - // } - - // const dataRows = data.map(point => { - // let row = [point.x, point.y]; - // if (plotType === '3d') { - // row.push(point.z); - // } - // return row.join(','); - // }); - - // const csv = [headers.join(','), ...dataRows].join('\n'); - // const blob = new Blob([csv], { type: 'text/csv;charset=utf-8' }); - // saveAs(blob, 'scatterplot_data.csv'); - // }; - useEffect(() => { if (N) { setData(generateData()); @@ -219,12 +198,6 @@ export const ScatterPlot = ({ N, yCorrelation, seed, setAppRvalue, 'lasso2d', 'autoScale2d'], }} /> - {/* {isSuperUser && ( -
- -
- )} */} ); }; diff --git a/media/js/src/simulations/simulation1/simulationOne.jsx b/media/js/src/simulations/simulation1/simulationOne.jsx index 4249f36..704d8f9 100644 --- a/media/js/src/simulations/simulation1/simulationOne.jsx +++ b/media/js/src/simulations/simulation1/simulationOne.jsx @@ -11,8 +11,6 @@ import { CriticalValueModal } from './modalCV'; import { GlossaryModal } from './modalGlossary'; -// const CURRENT_USER = window.MetricsMentor.currentUser.id; -// const isSuperUser = window.MetricsMentor.currentUser.is_superuser; const simContainer = document.querySelector('#react-root'); const coursePk = simContainer ? Number(simContainer.dataset.course) : ''; diff --git a/media/js/src/simulations/simulation2/components/scatterPlot2.jsx b/media/js/src/simulations/simulation2/components/scatterPlot2.jsx index 8630170..89060f7 100644 --- a/media/js/src/simulations/simulation2/components/scatterPlot2.jsx +++ b/media/js/src/simulations/simulation2/components/scatterPlot2.jsx @@ -1,7 +1,6 @@ import React, { useState, useEffect } from 'react'; import Plot from 'react-plotly.js'; import PropTypes from 'prop-types'; -// import axios from 'axios'; export const ScatterPlot2 = ({controls, data, labelIndex, param}) => { @@ -15,42 +14,6 @@ export const ScatterPlot2 = ({controls, data, labelIndex, param}) => { const [selectedAltLines, setSelectedAltLines] = useState([]); - // /** - // * !!DEV CODE!!: Use to extract the regression data for new data sets - // */ - // const minMax = function(arr) { - // return arr.reduce(function(p, v) { - // return ([p[0] < v ? p[0] : v, v < p[1] ? p[1] : v]); - // }, [Infinity, -Infinity]); - // }; - - // useEffect(() => { - // axios.post('/calc_regression/', { - // x_values: x1_values, - // y_values: y_values, - // }).then((response) => { - // const d = response.data; - // const xRange = minMax(x1_values); - // console.log('xRange:', xRange); - // console.log(param.x_1, d, 'yRange:', - // [xRange[0] * d.slope + d.intercept, - // xRange[1] * d.slope + d.intercept]); - // }); - // for (let col of param.option) { - // axios.post('/calc_multi_regression/', { - // x1_values: x1_values, - // x2_values: data[col], - // y_values: y_values, - // }).then((response) => { - // const d = response.data; - // const xRange = minMax(x1_values); - // console.log(col, d, 'yRange:', - // [xRange[0] * d.slope_x1 + d.intercept, - // xRange[1] * d.slope_x1 + d.intercept]); - // }); - // } - // }, [data]); - useEffect(() => { const altLines = []; if (controls) { diff --git a/media/js/src/utils/devUtils.jsx b/media/js/src/utils/devUtils.jsx new file mode 100644 index 0000000..cdd4e80 --- /dev/null +++ b/media/js/src/utils/devUtils.jsx @@ -0,0 +1,57 @@ +// devUtils.js + +import axios from 'axios'; +import { saveAs } from 'file-saver'; + +export const minMax = function(arr) { + return arr.reduce(function(p, v) { + return ([p[0] < v ? p[0] : v, v < p[1] ? p[1] : v]); + }, [Infinity, -Infinity]); +}; + +export const extractRegressionData = (x1_values, y_values, param, data) => { + axios.post('/calc_regression/', { + x_values: x1_values, + y_values: y_values, + }).then((response) => { + const d = response.data; + const xRange = minMax(x1_values); + console.log('xRange:', xRange); + console.log(param.x_1, d, 'yRange:', + [xRange[0] * d.slope + d.intercept, + xRange[1] * d.slope + d.intercept]); + }); + + for (let col of param.option) { + axios.post('/calc_multi_regression/', { + x1_values: x1_values, + x2_values: data[col], + y_values: y_values, + }).then((response) => { + const d = response.data; + const xRange = minMax(x1_values); + console.log(col, d, 'yRange:', + [xRange[0] * d.slope_x1 + d.intercept, + xRange[1] * d.slope_x1 + d.intercept]); + }); + } +}; + +export const exportCSV = (data, plotType) => { + let headers = ['x', 'y']; + if (plotType === '3d') { + headers.push('z'); + } + + const dataRows = data.map(point => { + let row = [point.x, point.y]; + if (plotType === '3d') { + row.push(point.z); + } + return row.join(','); + }); + + const csv = [headers.join(','), ...dataRows].join('\n'); + const blob = new Blob([csv], { type: 'text/csv;charset=utf-8' }); + saveAs(blob, 'scatterplot_data.csv'); +}; \ No newline at end of file