Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup #564

Merged
merged 2 commits into from
Oct 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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');
};