Skip to content

Commit

Permalink
Move around functionality and delete unused code
Browse files Browse the repository at this point in the history
  • Loading branch information
ndittren committed Oct 11, 2024
1 parent 55967e3 commit 66a759c
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 66 deletions.
27 changes: 0 additions & 27 deletions media/js/src/simulations/simulation1/scatterPlot.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -219,12 +198,6 @@ export const ScatterPlot = ({ N, yCorrelation, seed, setAppRvalue,
'lasso2d', 'autoScale2d'],
}}
/>
{/* {isSuperUser && (
<div className="text-end me-5">
<button className="btn btn-sm btn-secondary"
onClick={exportCSV}>Export CSV</button>
</div>
)} */}
</>
);
};
Expand Down
2 changes: 0 additions & 2 deletions media/js/src/simulations/simulation1/simulationOne.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) : '';
Expand Down
37 changes: 0 additions & 37 deletions media/js/src/simulations/simulation2/components/scatterPlot2.jsx
Original file line number Diff line number Diff line change
@@ -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}) => {
Expand All @@ -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) {
Expand Down
57 changes: 57 additions & 0 deletions media/js/src/utils/devUtils.jsx
Original file line number Diff line number Diff line change
@@ -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');
};

0 comments on commit 66a759c

Please sign in to comment.