From 55967e3a22052412b0644fffc456443b24d0fca6 Mon Sep 17 00:00:00 2001
From: ndittren <36773036+ndittren@users.noreply.github.com>
Date: Fri, 11 Oct 2024 13:10:09 -0400
Subject: [PATCH 1/2] Restructure folders
---
media/js/src/app.jsx | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/media/js/src/app.jsx b/media/js/src/app.jsx
index 990779c..e3b1286 100644
--- a/media/js/src/app.jsx
+++ b/media/js/src/app.jsx
@@ -2,8 +2,8 @@ import React, { useState, useEffect } from 'react';
import { BrowserRouter as Router, Route, Routes } from 'react-router-dom';
import { Dashboard } from './containers/dashboard';
import { SimulationOne} from './simulations/simulation1/simulationOne';
-import {
- SimulationTwo
+import {
+ SimulationTwo
} from './simulations/simulation2/components/simulationTwo';
const isSuperUser = window.MetricsMentor.currentUser.is_superuser;
From 4cb7b30d6ac0d5f59bb380b12bf3e9343a32cb48 Mon Sep 17 00:00:00 2001
From: ndittren <36773036+ndittren@users.noreply.github.com>
Date: Fri, 11 Oct 2024 14:09:22 -0400
Subject: [PATCH 2/2] Move around functionality and delete unused code
---
media/js/src/app.jsx | 4 +-
.../simulations/simulation1/scatterPlot.jsx | 27 ---------
.../simulations/simulation1/simulationOne.jsx | 2 -
.../simulation2/components/scatterPlot2.jsx | 37 ------------
media/js/src/utils/devUtils.jsx | 57 +++++++++++++++++++
5 files changed, 59 insertions(+), 68 deletions(-)
create mode 100644 media/js/src/utils/devUtils.jsx
diff --git a/media/js/src/app.jsx b/media/js/src/app.jsx
index e3b1286..990779c 100644
--- a/media/js/src/app.jsx
+++ b/media/js/src/app.jsx
@@ -2,8 +2,8 @@ import React, { useState, useEffect } from 'react';
import { BrowserRouter as Router, Route, Routes } from 'react-router-dom';
import { Dashboard } from './containers/dashboard';
import { SimulationOne} from './simulations/simulation1/simulationOne';
-import {
- SimulationTwo
+import {
+ SimulationTwo
} from './simulations/simulation2/components/simulationTwo';
const isSuperUser = window.MetricsMentor.currentUser.is_superuser;
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