From 94652e5db0ca3008e5d7c0817191ee783ed3118d Mon Sep 17 00:00:00 2001 From: J Date: Thu, 29 Sep 2022 15:46:41 -0700 Subject: [PATCH 01/13] add test question --- src/ProblemPool/agtesttbl1/agtesttbl1.json | 9 +++++++++ .../agtesttbl1/steps/agtesttbl1/agtesttbl1a.json | 12 ++++++++++++ .../tutoring/agtesttbl1aDefaultPathway.json | 10 ++++++++++ src/ProblemPool/stepfiles.txt | 1 + src/config/skillModel.js | 2 +- 5 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 src/ProblemPool/agtesttbl1/agtesttbl1.json create mode 100644 src/ProblemPool/agtesttbl1/steps/agtesttbl1/agtesttbl1a.json create mode 100644 src/ProblemPool/agtesttbl1/steps/agtesttbl1/tutoring/agtesttbl1aDefaultPathway.json diff --git a/src/ProblemPool/agtesttbl1/agtesttbl1.json b/src/ProblemPool/agtesttbl1/agtesttbl1.json new file mode 100644 index 00000000000..417bb16f431 --- /dev/null +++ b/src/ProblemPool/agtesttbl1/agtesttbl1.json @@ -0,0 +1,9 @@ +{ + "id": "agtesttbl1", + "title": "Multiplying the Matrix By a Scalar", + "body": "Given matrix B, find -3B.", + "variabilization": {}, + "oer": "https://openstax.org/", + "lesson": "7.5 Matrices and Matrix Operations", + "courseName": "Openstax: College Algebra" +} \ No newline at end of file diff --git a/src/ProblemPool/agtesttbl1/steps/agtesttbl1/agtesttbl1a.json b/src/ProblemPool/agtesttbl1/steps/agtesttbl1/agtesttbl1a.json new file mode 100644 index 00000000000..a7a1c79f09d --- /dev/null +++ b/src/ProblemPool/agtesttbl1/steps/agtesttbl1/agtesttbl1a.json @@ -0,0 +1,12 @@ +{ + "id": "agtesttbl1a", + "stepAnswer": [ + "$$\\begin{bmatrix} -8 & -2 \\\\ -6 & -4 \\end{bmatrix}$$" + ], + "problemType": "TextBox", + "stepTitle": "$$B=\\begin{bmatrix} 4 & 1 \\\\ 3 & 2 \\end{bmatrix}$$", + "stepBody": "", + "answerType": "arithmetic", + "variabilization": {}, + "answerLatex": "$$\\begin{bmatrix} -8 & -2 \\\\ -6 & -4 \\end{bmatrix}$$" +} \ No newline at end of file diff --git a/src/ProblemPool/agtesttbl1/steps/agtesttbl1/tutoring/agtesttbl1aDefaultPathway.json b/src/ProblemPool/agtesttbl1/steps/agtesttbl1/tutoring/agtesttbl1aDefaultPathway.json new file mode 100644 index 00000000000..fe102bd69a3 --- /dev/null +++ b/src/ProblemPool/agtesttbl1/steps/agtesttbl1/tutoring/agtesttbl1aDefaultPathway.json @@ -0,0 +1,10 @@ +[ + { + "id": "agtesttbl1a-h1", + "type": "hint", + "dependencies": [], + "title": "Multiplying a Matrix by a Scalar", + "text": "To multiply a matrix A by a scaler C, multiply each entry in A by C.", + "variabilization": {} + } +] \ No newline at end of file diff --git a/src/ProblemPool/stepfiles.txt b/src/ProblemPool/stepfiles.txt index a12abefa12b..644f5a96420 100644 --- a/src/ProblemPool/stepfiles.txt +++ b/src/ProblemPool/stepfiles.txt @@ -1,3 +1,4 @@ + agtesttbl1a: ["matrices_and_matrix_operations"], a6f9727real1a: ["realnumber"], a6f9727real1b: ["realnumber"], a6f9727real1c: ["realnumber"], diff --git a/src/config/skillModel.js b/src/config/skillModel.js index f553f2acca1..7deaf5b0e1e 100644 --- a/src/config/skillModel.js +++ b/src/config/skillModel.js @@ -1,5 +1,5 @@ const skillModel = { - + agtesttbl1a: [`matrices_and_matrix_operations`], a6f9727real1a: [`classifying_a_real_number`], a6f9727real1b: [`classifying_a_real_number`], a6f9727real1c: [`classifying_a_real_number`], From e6b579f43a2d4d58745191718affcc0cbfaceccc Mon Sep 17 00:00:00 2001 From: Ethan Zhang <36081769+e-zhang09@users.noreply.github.com> Date: Fri, 30 Sep 2022 15:07:29 -0700 Subject: [PATCH 02/13] feat: fix step naming --- .../agtesttbl1/steps/{agtesttbl1 => agtesttbl1a}/agtesttbl1a.json | 0 .../tutoring/agtesttbl1aDefaultPathway.json | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename src/ProblemPool/agtesttbl1/steps/{agtesttbl1 => agtesttbl1a}/agtesttbl1a.json (100%) rename src/ProblemPool/agtesttbl1/steps/{agtesttbl1 => agtesttbl1a}/tutoring/agtesttbl1aDefaultPathway.json (100%) diff --git a/src/ProblemPool/agtesttbl1/steps/agtesttbl1/agtesttbl1a.json b/src/ProblemPool/agtesttbl1/steps/agtesttbl1a/agtesttbl1a.json similarity index 100% rename from src/ProblemPool/agtesttbl1/steps/agtesttbl1/agtesttbl1a.json rename to src/ProblemPool/agtesttbl1/steps/agtesttbl1a/agtesttbl1a.json diff --git a/src/ProblemPool/agtesttbl1/steps/agtesttbl1/tutoring/agtesttbl1aDefaultPathway.json b/src/ProblemPool/agtesttbl1/steps/agtesttbl1a/tutoring/agtesttbl1aDefaultPathway.json similarity index 100% rename from src/ProblemPool/agtesttbl1/steps/agtesttbl1/tutoring/agtesttbl1aDefaultPathway.json rename to src/ProblemPool/agtesttbl1/steps/agtesttbl1a/tutoring/agtesttbl1aDefaultPathway.json From 1299399f43c0dea5beec29e2c10b5238774caebe Mon Sep 17 00:00:00 2001 From: Ethan Zhang <36081769+e-zhang09@users.noreply.github.com> Date: Fri, 30 Sep 2022 16:31:54 -0700 Subject: [PATCH 03/13] feat: ignore .DS_Store steps --- src/tools/preprocessProblemPool.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/tools/preprocessProblemPool.js b/src/tools/preprocessProblemPool.js index ac3b894dadc..67cb337d0bb 100644 --- a/src/tools/preprocessProblemPool.js +++ b/src/tools/preprocessProblemPool.js @@ -110,8 +110,9 @@ const staticFiguresPath = path.join(__dirname, '..', '..', 'public', 'static', ' } problem.steps = await Promise.all( - stepDirs.map( - async stepDir => { + stepDirs + .filter(s => !(s.toString().startsWith("_") || s.toString().startsWith("."))) // ignore directories that start with _ or . + .map(async stepDir => { const stepName = stepDir.toString() const stepPath = path.join(problemPath, 'steps', stepName) From 5c597e81f742ce084ca4c8e9d0f97646a0ce8c46 Mon Sep 17 00:00:00 2001 From: J Date: Mon, 3 Oct 2022 15:03:04 -0700 Subject: [PATCH 04/13] fixed table style --- .../ProblemInput/ProblemInput.js | 34 ++++ src/ProblemLayout/ProblemInput/TableInput.js | 155 ++++++++++++++++++ src/ProblemLayout/commonStyles.js | 21 +++ src/ProblemPool/agtesttbl1/agtesttbl1.json | 4 +- .../steps/agtesttbl1a/agtesttbl1a.json | 11 +- src/util/parseTableTex.js | 15 ++ 6 files changed, 234 insertions(+), 6 deletions(-) create mode 100644 src/ProblemLayout/ProblemInput/TableInput.js create mode 100644 src/util/parseTableTex.js diff --git a/src/ProblemLayout/ProblemInput/ProblemInput.js b/src/ProblemLayout/ProblemInput/ProblemInput.js index b1904247d77..7bd2a0bb814 100644 --- a/src/ProblemLayout/ProblemInput/ProblemInput.js +++ b/src/ProblemLayout/ProblemInput/ProblemInput.js @@ -5,6 +5,7 @@ import TextField from "@material-ui/core/TextField"; import MultipleChoice from "./MultipleChoice"; import GridInput from "./GridInput"; import MatrixInput from "./MatrixInput"; +import TableInput from "./TableInput"; import { renderText } from "../../ProblemLogic/renderText"; import clsx from "clsx"; import './ProblemInput.css' @@ -12,6 +13,7 @@ import { shuffleArray } from "../../util/shuffleArray"; import { EQUATION_EDITOR_AUTO_COMMANDS, EQUATION_EDITOR_AUTO_OPERATORS, ThemeContext } from "../../config/config"; import { stagingProp } from "../../util/addStagingProperty"; import { parseMatrixTex } from "../../util/parseMatrixTex"; +import { parseTableTex } from "../../util/parseTableTex"; class ProblemInput extends React.Component { static contextType = ThemeContext; @@ -52,6 +54,17 @@ class ProblemInput extends React.Component { } } + isTableInput() { + if (this.props.step?.stepAnswer) { + return this.props.step?.problemType !== "MultipleChoice" && + /\\begin{[a-zA-Z]?tabular}/.test(this.props.step.stepAnswer[0]) + } + if (this.props.step?.hintAnswer) { + return this.props.step?.problemType !== "MultipleChoice" && + /\\begin{[a-zA-Z]?tabular}/.test(this.props.step.hintAnswer[0]) + } + } + onEquationChange(eq) { const containerEl = this.equationRef?.current const eqContentEl = this.equationRef?.current?.querySelector(".mq-editable-field") @@ -87,8 +100,13 @@ class ProblemInput extends React.Component { problemType = "MatrixInput" } + if (this.isTableInput()) { + problemType = "TableInput" + } + return ( + {(problemType === "TextBox" && this.props.step.answerType !== "string") && ( @@ -171,6 +189,21 @@ class ProblemInput extends React.Component { } : {}} /> )} + {problemType === "TableInput" && ( + this.props.setInputValState(newVal)} + numRows={this.props.step.numRows} + numCols={this.props.step.numCols} + context={this.props.context} + classes={this.props.classes} + index={index} + {...(use_expanded_view && debug) ? { + defaultValue: parseTableTex(correctAnswer)[0] + } : {}} + /> + + + )}
@@ -178,6 +211,7 @@ class ProblemInput extends React.Component {
+ ) } diff --git a/src/ProblemLayout/ProblemInput/TableInput.js b/src/ProblemLayout/ProblemInput/TableInput.js new file mode 100644 index 00000000000..4bbb1a627c4 --- /dev/null +++ b/src/ProblemLayout/ProblemInput/TableInput.js @@ -0,0 +1,155 @@ +import React, { createRef } from "react"; +import './GridInput.css' +import Button from "@material-ui/core/Button"; +import clsx from 'clsx'; +import EquationEditor from "equation-editor-react"; +import { Box,TextField } from "@material-ui/core"; +import { EQUATION_EDITOR_AUTO_COMMANDS, EQUATION_EDITOR_AUTO_OPERATORS } from "../../config/config"; +import { stagingProp } from "../../util/addStagingProperty"; + +class TableInput extends React.Component { + + constructor(props) { + + super(props); + this.state = { + gridState: props.defaultValue || this.genEmptyGrid(2, 3), + }; + this.gridRef = createRef() + this.clearCells = this.clearCells.bind(this) + } + + + genEmptyGrid = (numRows, numCols) => new Array(numRows) + .fill(0) + .map(_ => new Array(numCols).fill("")) + + cellFieldChange(str, idx, jdx) { + const gridState = this.state.gridState + gridState[idx][jdx] = str; + + this.setState({ + gridState + }, () => { + this.props.onChange(JSON.stringify(this.state.gridState)) + }) + } + + clearCells(evt) { + if (evt != null && evt.type === 'submit') { + evt.preventDefault() + } + + this.setState({ + gridState: this.genEmptyGrid(2, 3) + }) + if (this.gridRef.current) { + this.gridRef.current + .querySelectorAll(".mq-editable-field > *[mathquill-command-id], .mq-root-block > *[mathquill-command-id]") + .forEach(node => { + node.remove() + }) + } + } + + + render() { + const { classes, index } = this.props; + + const { gridState } = this.state; + + const revealClearButton = gridState.reduce((acc, cur, _) => + acc + cur.reduce((_acc, _cur, __) => + _acc + _cur.length, 0 + ), 0 + ) > 0; // only reveal the clear button if there is at least something in a cell + + return ( +
+
+ + + { + gridState[0].map((row, col) => { + return ( + + ) + }) + } + + + + { + gridState.map((row, idx) => + row.map((val, jdx) => { + return ( +
+ this.cellFieldChange(str, idx, jdx)} + style={{ width: "100%" }} + autoCommands={EQUATION_EDITOR_AUTO_COMMANDS} + autoOperatorNames={EQUATION_EDITOR_AUTO_OPERATORS} + /> + +
+ + ) + }) + ) + } +
+
+ + + +
+ ) + } + +} + + +export default TableInput; diff --git a/src/ProblemLayout/commonStyles.js b/src/ProblemLayout/commonStyles.js index 2af2301ee2e..836dcce79a7 100644 --- a/src/ProblemLayout/commonStyles.js +++ b/src/ProblemLayout/commonStyles.js @@ -145,6 +145,27 @@ const styles = theme => ({ paddingBottom: 5 } }, + textTblLatex: { + borderRadius: "0px", + outline: "1px solid #c4c4c4", + '&:hover': { + border: "1px solid #000000", + }, + '&:focus-within': { + border: "2px solid #3f51b5", + }, + height: 50, + width: '100%', + '& > .mq-editable-field': { + display: 'table', + tableLayout: 'fixed' + }, + '& > * > *[mathquill-block-id]': { + height: 50, + display: 'table-cell', + paddingBottom: 5 + } + }, textBoxLatexIncorrect: { boxShadow: "0 0 0.75pt 0.75pt red", '&:focus-within': { diff --git a/src/ProblemPool/agtesttbl1/agtesttbl1.json b/src/ProblemPool/agtesttbl1/agtesttbl1.json index 417bb16f431..73d29c0a979 100644 --- a/src/ProblemPool/agtesttbl1/agtesttbl1.json +++ b/src/ProblemPool/agtesttbl1/agtesttbl1.json @@ -1,7 +1,7 @@ { "id": "agtesttbl1", - "title": "Multiplying the Matrix By a Scalar", - "body": "Given matrix B, find -3B.", + "title": "Find two way table", + "body": "Find two way table", "variabilization": {}, "oer": "https://openstax.org/", "lesson": "7.5 Matrices and Matrix Operations", diff --git a/src/ProblemPool/agtesttbl1/steps/agtesttbl1a/agtesttbl1a.json b/src/ProblemPool/agtesttbl1/steps/agtesttbl1a/agtesttbl1a.json index a7a1c79f09d..60d5f298c27 100644 --- a/src/ProblemPool/agtesttbl1/steps/agtesttbl1a/agtesttbl1a.json +++ b/src/ProblemPool/agtesttbl1/steps/agtesttbl1a/agtesttbl1a.json @@ -1,12 +1,15 @@ { "id": "agtesttbl1a", "stepAnswer": [ - "$$\\begin{bmatrix} -8 & -2 \\\\ -6 & -4 \\end{bmatrix}$$" + "$$\\begin{tabular} apple & sugar \\\\ -6 & -4 \\\\ 1 & 3 \\end{tabular}$$" ], "problemType": "TextBox", - "stepTitle": "$$B=\\begin{bmatrix} 4 & 1 \\\\ 3 & 2 \\end{bmatrix}$$", + "stepTitle": "$$B=\\begin{tabular} 4 & 1 \\\\ 3 & 2 \\end{tabular}$$", "stepBody": "", "answerType": "arithmetic", "variabilization": {}, - "answerLatex": "$$\\begin{bmatrix} -8 & -2 \\\\ -6 & -4 \\end{bmatrix}$$" -} \ No newline at end of file + "answerLatex": "$$\\begin{tabular} apple & sugar \\\\ -6 & -4 \\\\ 1 & 3 \\end{tabular}$$" +} + + + diff --git a/src/util/parseTableTex.js b/src/util/parseTableTex.js new file mode 100644 index 00000000000..fc2f4a7d785 --- /dev/null +++ b/src/util/parseTableTex.js @@ -0,0 +1,15 @@ +export function parseTableTex(solTex) { + const solutionTable = [] + + ;(Array.isArray(solTex) ? solTex : [solTex]).forEach(sol => { + const _start = sol.indexOf("tabular} ") + "tabular} ".length + const _end = sol.indexOf("\\end{") + let _solutionTable = sol + .substring(_start, _end) + .trim() + .split("\\\\") + .map(row => row.split("&").map(val => val.trim())) + solutionTable.push(_solutionTable) + }) + return solutionTable; +} From bf027ead5737cf66eaa10f9e34a4e231dfa8245a Mon Sep 17 00:00:00 2001 From: J Date: Wed, 5 Oct 2022 16:37:58 -0700 Subject: [PATCH 05/13] implemented adjustable table size given by question" --- .../ProblemInput/ProblemInput.js | 25 ++++++++++++++++--- src/ProblemLayout/ProblemInput/TableInput.js | 6 +++-- .../steps/agtesttbl1a/agtesttbl1a.json | 2 +- 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/src/ProblemLayout/ProblemInput/ProblemInput.js b/src/ProblemLayout/ProblemInput/ProblemInput.js index 7bd2a0bb814..bac34812d1d 100644 --- a/src/ProblemLayout/ProblemInput/ProblemInput.js +++ b/src/ProblemLayout/ProblemInput/ProblemInput.js @@ -88,6 +88,25 @@ class ProblemInput extends React.Component { } this.props.setInputValState(eq) } + + getNumRows(correctAnswer) { + const numRows = correctAnswer.split("\\\\").length; + + return numRows + + } + getNumCols(correctAnswer) { + const numRows = correctAnswer.split("\\\\").length; + const numCols = correctAnswer.split("\\\\").join("&").split("&").length / numRows; + return numCols + } + + // getHeader(props) { + // const cleanedAnswer = props.replace("$$\\begin{tabular}", "\\end{tabular}$$","").replace(/is/g, "or"); + // } + + + render() { const { classes, state, index } = this.props; @@ -104,9 +123,9 @@ class ProblemInput extends React.Component { problemType = "TableInput" } + return ( - {(problemType === "TextBox" && this.props.step.answerType !== "string") && ( @@ -192,8 +211,8 @@ class ProblemInput extends React.Component { {problemType === "TableInput" && ( this.props.setInputValState(newVal)} - numRows={this.props.step.numRows} - numCols={this.props.step.numCols} + numRows={this.getNumRows(correctAnswer)} + numCols={this.getNumCols(correctAnswer)} context={this.props.context} classes={this.props.classes} index={index} diff --git a/src/ProblemLayout/ProblemInput/TableInput.js b/src/ProblemLayout/ProblemInput/TableInput.js index 4bbb1a627c4..936d420128e 100644 --- a/src/ProblemLayout/ProblemInput/TableInput.js +++ b/src/ProblemLayout/ProblemInput/TableInput.js @@ -13,10 +13,12 @@ class TableInput extends React.Component { super(props); this.state = { - gridState: props.defaultValue || this.genEmptyGrid(2, 3), + gridState: props.defaultValue || this.genEmptyGrid(props.numRows, props.numCols), }; this.gridRef = createRef() this.clearCells = this.clearCells.bind(this) + this.numRows = props.numRows; + this.numCols = props.numCols; } @@ -41,7 +43,7 @@ class TableInput extends React.Component { } this.setState({ - gridState: this.genEmptyGrid(2, 3) + gridState: this.genEmptyGrid(this.numRows, this.numCols) }) if (this.gridRef.current) { this.gridRef.current diff --git a/src/ProblemPool/agtesttbl1/steps/agtesttbl1a/agtesttbl1a.json b/src/ProblemPool/agtesttbl1/steps/agtesttbl1a/agtesttbl1a.json index 60d5f298c27..3d1e8a9662c 100644 --- a/src/ProblemPool/agtesttbl1/steps/agtesttbl1a/agtesttbl1a.json +++ b/src/ProblemPool/agtesttbl1/steps/agtesttbl1a/agtesttbl1a.json @@ -4,7 +4,7 @@ "$$\\begin{tabular} apple & sugar \\\\ -6 & -4 \\\\ 1 & 3 \\end{tabular}$$" ], "problemType": "TextBox", - "stepTitle": "$$B=\\begin{tabular} 4 & 1 \\\\ 3 & 2 \\end{tabular}$$", + "stepTitle": "$$\\begin{tabular} apple & sugar \\\\ -6 & -4 \\\\ 1 & 3 \\end{tabular}$$", "stepBody": "", "answerType": "arithmetic", "variabilization": {}, From b8562567ba866fc6f1090556cff023b361e2eb9e Mon Sep 17 00:00:00 2001 From: J Date: Fri, 7 Oct 2022 14:54:33 -0700 Subject: [PATCH 06/13] add header --- .../ProblemInput/ProblemInput.js | 26 +++++++------------ src/ProblemLayout/ProblemInput/TableInput.js | 5 ++-- 2 files changed, 13 insertions(+), 18 deletions(-) diff --git a/src/ProblemLayout/ProblemInput/ProblemInput.js b/src/ProblemLayout/ProblemInput/ProblemInput.js index bac34812d1d..4570a3078a4 100644 --- a/src/ProblemLayout/ProblemInput/ProblemInput.js +++ b/src/ProblemLayout/ProblemInput/ProblemInput.js @@ -24,6 +24,8 @@ class ProblemInput extends React.Component { this.equationRef = createRef() this.onEquationChange = this.onEquationChange.bind(this) + + this.questionAnswer = this.props.stepAnswer } componentDidMount() { @@ -89,24 +91,15 @@ class ProblemInput extends React.Component { this.props.setInputValState(eq) } - getNumRows(correctAnswer) { - const numRows = correctAnswer.split("\\\\").length; - - return numRows - - } - getNumCols(correctAnswer) { + + getDimAndHeaders(correctAnswer) { + const temp = correctAnswer; const numRows = correctAnswer.split("\\\\").length; const numCols = correctAnswer.split("\\\\").join("&").split("&").length / numRows; - return numCols + const headers = temp.match(/([a-zA-z]+)/g).slice(2,2+numCols) + return {numRows, numCols, headers} } - // getHeader(props) { - // const cleanedAnswer = props.replace("$$\\begin{tabular}", "\\end{tabular}$$","").replace(/is/g, "or"); - // } - - - render() { const { classes, state, index } = this.props; @@ -211,8 +204,9 @@ class ProblemInput extends React.Component { {problemType === "TableInput" && ( this.props.setInputValState(newVal)} - numRows={this.getNumRows(correctAnswer)} - numCols={this.getNumCols(correctAnswer)} + numRows={this.getDimAndHeaders(correctAnswer).numRows} + numCols={this.getDimAndHeaders(correctAnswer).numCols} + headers= {this.getDimAndHeaders(correctAnswer).headers} context={this.props.context} classes={this.props.classes} index={index} diff --git a/src/ProblemLayout/ProblemInput/TableInput.js b/src/ProblemLayout/ProblemInput/TableInput.js index 936d420128e..e13d70b68b2 100644 --- a/src/ProblemLayout/ProblemInput/TableInput.js +++ b/src/ProblemLayout/ProblemInput/TableInput.js @@ -19,6 +19,7 @@ class TableInput extends React.Component { this.clearCells = this.clearCells.bind(this) this.numRows = props.numRows; this.numCols = props.numCols; + this.headers = props.headers; } @@ -86,6 +87,7 @@ class TableInput extends React.Component { borderBottom: '1px solid #c4c4c4', background: '#ececec'} }} > + { gridState[0].map((row, col) => { return ( @@ -93,9 +95,8 @@ class TableInput extends React.Component { disabled id="filled-disabled" label="Disabled" - defaultValue="Hello World" + defaultValue={this.props.headers[col]} key ={col} - className={'grid-cell'} /> ) From b15990b2106d7330645b94d885d27f20d5f1e10b Mon Sep 17 00:00:00 2001 From: juni0001 Date: Tue, 25 Oct 2022 22:08:17 -0700 Subject: [PATCH 07/13] changed parse text --- src/ProblemLayout/ProblemInput/ProblemInput.js | 6 ++++-- src/util/parseTableTex.js | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/ProblemLayout/ProblemInput/ProblemInput.js b/src/ProblemLayout/ProblemInput/ProblemInput.js index 4570a3078a4..045fcbd3d88 100644 --- a/src/ProblemLayout/ProblemInput/ProblemInput.js +++ b/src/ProblemLayout/ProblemInput/ProblemInput.js @@ -94,9 +94,10 @@ class ProblemInput extends React.Component { getDimAndHeaders(correctAnswer) { const temp = correctAnswer; - const numRows = correctAnswer.split("\\\\").length; - const numCols = correctAnswer.split("\\\\").join("&").split("&").length / numRows; + const TotalRows = correctAnswer.split("\\\\").length; + const numCols = correctAnswer.split("\\\\").join("&").split("&").length / TotalRows; const headers = temp.match(/([a-zA-z]+)/g).slice(2,2+numCols) + const numRows = TotalRows - 1; return {numRows, numCols, headers} } @@ -119,6 +120,7 @@ class ProblemInput extends React.Component { return ( + {console.log(parseTableTex(correctAnswer))} {(problemType === "TextBox" && this.props.step.answerType !== "string") && ( diff --git a/src/util/parseTableTex.js b/src/util/parseTableTex.js index fc2f4a7d785..d2aeb2c23f5 100644 --- a/src/util/parseTableTex.js +++ b/src/util/parseTableTex.js @@ -11,5 +11,5 @@ export function parseTableTex(solTex) { .map(row => row.split("&").map(val => val.trim())) solutionTable.push(_solutionTable) }) - return solutionTable; + return solutionTable[0].slice(1,4); } From af9f444001ecd962186613d51b0a66a320d34941 Mon Sep 17 00:00:00 2001 From: juni0001 Date: Wed, 26 Oct 2022 16:28:07 -0700 Subject: [PATCH 08/13] minor changes on style --- src/ProblemLayout/ProblemInput/TableInput.js | 110 +++++++++---------- src/util/parseTableTex.js | 2 +- 2 files changed, 55 insertions(+), 57 deletions(-) diff --git a/src/ProblemLayout/ProblemInput/TableInput.js b/src/ProblemLayout/ProblemInput/TableInput.js index e13d70b68b2..a91dc249520 100644 --- a/src/ProblemLayout/ProblemInput/TableInput.js +++ b/src/ProblemLayout/ProblemInput/TableInput.js @@ -69,8 +69,6 @@ class TableInput extends React.Component { return (
-
- - - { - gridState[0].map((row, col) => { - return ( - - ) - }) - } - - + { + gridState[0].map((row, col) => { + return ( + + ) + }) + } + + +
- { - gridState.map((row, idx) => - row.map((val, jdx) => { - return ( -
- this.cellFieldChange(str, idx, jdx)} - style={{ width: "100%" }} - autoCommands={EQUATION_EDITOR_AUTO_COMMANDS} - autoOperatorNames={EQUATION_EDITOR_AUTO_OPERATORS} - /> - -
- - ) - }) - ) - } + { + gridState.map((row, idx) => + row.map((val, jdx) => { + return ( +
+ this.cellFieldChange(str, idx, jdx)} + style={{ width: "100%" }} + autoCommands={EQUATION_EDITOR_AUTO_COMMANDS} + autoOperatorNames={EQUATION_EDITOR_AUTO_OPERATORS} + /> + +
+ + ) + }) + ) + }
diff --git a/src/util/parseTableTex.js b/src/util/parseTableTex.js index d2aeb2c23f5..bc064ff3f19 100644 --- a/src/util/parseTableTex.js +++ b/src/util/parseTableTex.js @@ -11,5 +11,5 @@ export function parseTableTex(solTex) { .map(row => row.split("&").map(val => val.trim())) solutionTable.push(_solutionTable) }) - return solutionTable[0].slice(1,4); + return Array(solutionTable[0].slice(1)); } From 1b5827b2ef45194ab9eca452d25283cf19788bc0 Mon Sep 17 00:00:00 2001 From: juni0001 Date: Thu, 27 Oct 2022 16:04:28 -0700 Subject: [PATCH 09/13] add checkanswer for table --- .../ProblemInput/ProblemInput.js | 8 ++++++- src/ProblemLayout/ProblemInput/TableInput.js | 18 +++++++-------- src/ProblemLogic/checkAnswer.js | 23 +++++++++++++++++++ 3 files changed, 38 insertions(+), 11 deletions(-) diff --git a/src/ProblemLayout/ProblemInput/ProblemInput.js b/src/ProblemLayout/ProblemInput/ProblemInput.js index 045fcbd3d88..078588bacf8 100644 --- a/src/ProblemLayout/ProblemInput/ProblemInput.js +++ b/src/ProblemLayout/ProblemInput/ProblemInput.js @@ -34,6 +34,11 @@ class ProblemInput extends React.Component { console.log('automatically determined matrix input to be the correct problem type') } + console.debug('problem', this.props.step, 'seed', this.props.seed) + if (this.isTableInput()) { + console.log('automatically determined table input to be the correct problem type') + } + const mqDisplayArea = this.equationRef?.current?.querySelector(".mq-editable-field > .mq-root-block") if (mqDisplayArea != null) { mqDisplayArea.ariaHidden = true @@ -120,7 +125,8 @@ class ProblemInput extends React.Component { return ( - {console.log(parseTableTex(correctAnswer))} + {/* {console.log("tbl",parseTableTex(correctAnswer))} */} + {/* {console.log("mx", parseMatrixTex(correctAnswer))} */} {(problemType === "TextBox" && this.props.step.answerType !== "string") && ( diff --git a/src/ProblemLayout/ProblemInput/TableInput.js b/src/ProblemLayout/ProblemInput/TableInput.js index a91dc249520..43a6114fc5c 100644 --- a/src/ProblemLayout/ProblemInput/TableInput.js +++ b/src/ProblemLayout/ProblemInput/TableInput.js @@ -14,6 +14,7 @@ class TableInput extends React.Component { super(props); this.state = { gridState: props.defaultValue || this.genEmptyGrid(props.numRows, props.numCols), + fer: Math.random() }; this.gridRef = createRef() this.clearCells = this.clearCells.bind(this) @@ -44,22 +45,19 @@ class TableInput extends React.Component { } this.setState({ - gridState: this.genEmptyGrid(this.numRows, this.numCols) + gridState: this.genEmptyGrid(this.numRows, this.numCols), + fer: Math.random() + }, () => { + this.props.onChange(JSON.stringify(this.state.gridState)) }) - if (this.gridRef.current) { - this.gridRef.current - .querySelectorAll(".mq-editable-field > *[mathquill-command-id], .mq-root-block > *[mathquill-command-id]") - .forEach(node => { - node.remove() - }) - } + } render() { const { classes, index } = this.props; - const { gridState } = this.state; + const { gridState, fer } = this.state; const revealClearButton = gridState.reduce((acc, cur, _) => acc + cur.reduce((_acc, _cur, __) => @@ -119,7 +117,7 @@ class TableInput extends React.Component { return (
variabilize(actualAns, variabilization)); } @@ -93,6 +96,26 @@ function checkAnswer(attempt, actual, answerType, precision, variabilization) { }) return [attempt, correctAnswer] + } else if (/\\begin{[a-zA-Z]?tabular}/.test(actual)){ + console.debug(`attempt: ${attempt} vs. actual:`, actual) + const studentMatrix = JSON.parse(attempt) + const solutionMatrices = parseTableTex(actual); + + console.debug('solutions: ', solutionMatrices) + correctAnswer = solutionMatrices.some(matrix => { + return matrix.reduce((acc, row, idx) => acc && row.reduce((_acc, cell, jdx) => { + const _studentRow = studentMatrix[idx] || [] + const _studentCell = _studentRow[jdx] || "" + const _studentExpr = parse(_studentCell).expr + + const _solExpr = parse(cell).expr + + return _acc && KAS.compare(_studentExpr, _solExpr).equal + }, true), true) + }) + + return [attempt, correctAnswer] + } else { if (IS_STAGING_OR_DEVELOPMENT) { console.debug("Using KAS to compare answer with solution", attempt, actual) From c1097f97190dfc9ac09127397337a3389d3f1d3a Mon Sep 17 00:00:00 2001 From: juni0001 Date: Thu, 10 Nov 2022 15:43:25 -0800 Subject: [PATCH 10/13] updated ui --- src/ProblemLayout/ProblemInput/TableInput.js | 17 +++++++++-------- .../steps/agtesttbl1a/agtesttbl1a.json | 4 ++-- src/ProblemPool/agtesttbl2/agtesttbl2.json | 9 +++++++++ .../steps/agtesttbl2a/agtesttbl2a.json | 15 +++++++++++++++ .../tutoring/agtesttbl2aDefaultPathway.json | 10 ++++++++++ src/ProblemPool/stepfiles.txt | 1 + src/config/skillModel.js | 1 + 7 files changed, 47 insertions(+), 10 deletions(-) create mode 100644 src/ProblemPool/agtesttbl2/agtesttbl2.json create mode 100644 src/ProblemPool/agtesttbl2/steps/agtesttbl2a/agtesttbl2a.json create mode 100644 src/ProblemPool/agtesttbl2/steps/agtesttbl2a/tutoring/agtesttbl2aDefaultPathway.json diff --git a/src/ProblemLayout/ProblemInput/TableInput.js b/src/ProblemLayout/ProblemInput/TableInput.js index 43a6114fc5c..3cc685a7dd0 100644 --- a/src/ProblemLayout/ProblemInput/TableInput.js +++ b/src/ProblemLayout/ProblemInput/TableInput.js @@ -69,17 +69,15 @@ class TableInput extends React.Component {
@@ -89,10 +87,13 @@ class TableInput extends React.Component { ) }) diff --git a/src/ProblemPool/agtesttbl1/steps/agtesttbl1a/agtesttbl1a.json b/src/ProblemPool/agtesttbl1/steps/agtesttbl1a/agtesttbl1a.json index 3d1e8a9662c..15c72fcc82f 100644 --- a/src/ProblemPool/agtesttbl1/steps/agtesttbl1a/agtesttbl1a.json +++ b/src/ProblemPool/agtesttbl1/steps/agtesttbl1a/agtesttbl1a.json @@ -4,11 +4,11 @@ "$$\\begin{tabular} apple & sugar \\\\ -6 & -4 \\\\ 1 & 3 \\end{tabular}$$" ], "problemType": "TextBox", - "stepTitle": "$$\\begin{tabular} apple & sugar \\\\ -6 & -4 \\\\ 1 & 3 \\end{tabular}$$", + "stepTitle": "enter table with -6, -4, 1, 3", "stepBody": "", "answerType": "arithmetic", "variabilization": {}, - "answerLatex": "$$\\begin{tabular} apple & sugar \\\\ -6 & -4 \\\\ 1 & 3 \\end{tabular}$$" + "answerLatex": "enter table with -6, -4, 1, 3" } diff --git a/src/ProblemPool/agtesttbl2/agtesttbl2.json b/src/ProblemPool/agtesttbl2/agtesttbl2.json new file mode 100644 index 00000000000..2869ea1b8e0 --- /dev/null +++ b/src/ProblemPool/agtesttbl2/agtesttbl2.json @@ -0,0 +1,9 @@ +{ + "id": "agtesttbl2", + "title": "Find two way table", + "body": "Find two way table", + "variabilization": {}, + "oer": "https://openstax.org/", + "lesson": "7.5 Matrices and Matrix Operations", + "courseName": "Openstax: College Algebra" +} \ No newline at end of file diff --git a/src/ProblemPool/agtesttbl2/steps/agtesttbl2a/agtesttbl2a.json b/src/ProblemPool/agtesttbl2/steps/agtesttbl2a/agtesttbl2a.json new file mode 100644 index 00000000000..7d316fadd0b --- /dev/null +++ b/src/ProblemPool/agtesttbl2/steps/agtesttbl2a/agtesttbl2a.json @@ -0,0 +1,15 @@ +{ + "id": "agtesttbl2a", + "stepAnswer": [ + "$$\\begin{tabular} apple & sugarandhoneyand & candy \\\\ -6 & -4 & 3\\\\ 1 & 3 & 2\\end{tabular}$$" + ], + "problemType": "TextBox", + "stepTitle": "enter table with -6, -4, 1, 3", + "stepBody": "", + "answerType": "arithmetic", + "variabilization": {}, + "answerLatex": "enter table with -6, -4, 1, 3" +} + + + diff --git a/src/ProblemPool/agtesttbl2/steps/agtesttbl2a/tutoring/agtesttbl2aDefaultPathway.json b/src/ProblemPool/agtesttbl2/steps/agtesttbl2a/tutoring/agtesttbl2aDefaultPathway.json new file mode 100644 index 00000000000..dfdf0ee8580 --- /dev/null +++ b/src/ProblemPool/agtesttbl2/steps/agtesttbl2a/tutoring/agtesttbl2aDefaultPathway.json @@ -0,0 +1,10 @@ +[ + { + "id": "agtesttbl2a-h1", + "type": "hint", + "dependencies": [], + "title": "Multiplying a Matrix by a Scalar", + "text": "To multiply a matrix A by a scaler C, multiply each entry in A by C.", + "variabilization": {} + } +] \ No newline at end of file diff --git a/src/ProblemPool/stepfiles.txt b/src/ProblemPool/stepfiles.txt index 644f5a96420..bf40bfe5dd3 100644 --- a/src/ProblemPool/stepfiles.txt +++ b/src/ProblemPool/stepfiles.txt @@ -1,4 +1,5 @@ agtesttbl1a: ["matrices_and_matrix_operations"], + agtesttbl2a: ["matrices_and_matrix_operations"], a6f9727real1a: ["realnumber"], a6f9727real1b: ["realnumber"], a6f9727real1c: ["realnumber"], diff --git a/src/config/skillModel.js b/src/config/skillModel.js index 7deaf5b0e1e..3875ba7189e 100644 --- a/src/config/skillModel.js +++ b/src/config/skillModel.js @@ -1,5 +1,6 @@ const skillModel = { agtesttbl1a: [`matrices_and_matrix_operations`], + agtesttbl2a: [`matrices_and_matrix_operations`], a6f9727real1a: [`classifying_a_real_number`], a6f9727real1b: [`classifying_a_real_number`], a6f9727real1c: [`classifying_a_real_number`], From fe4cb0d5a121bec047bd44f54de4f0a56a91191e Mon Sep 17 00:00:00 2001 From: juni0001 Date: Thu, 10 Nov 2022 16:29:23 -0800 Subject: [PATCH 11/13] change overflow --- src/ProblemLayout/ProblemInput/TableInput.js | 32 ++++++-------------- 1 file changed, 10 insertions(+), 22 deletions(-) diff --git a/src/ProblemLayout/ProblemInput/TableInput.js b/src/ProblemLayout/ProblemInput/TableInput.js index 3cc685a7dd0..ca5c2ad90c4 100644 --- a/src/ProblemLayout/ProblemInput/TableInput.js +++ b/src/ProblemLayout/ProblemInput/TableInput.js @@ -72,23 +72,25 @@ class TableInput extends React.Component { gridTemplateColumns={`repeat(${gridState[0].length}, 0fr)`} overflow={'auto'} pt={0} - pb={0} + pb={1} gridColumnGap={1} + gridGap={1} justifyContent={'center'} sx={{ - '& .MuiTextField-root': {width: 'min(120px, 19vw)', borderRadius: 0, + '& .MuiTextField-root': {borderRadius: 0, outline: "1px solid #c4c4c4", borderTop: '1px solid #c4c4c4', height:'40px', - borderBottom: '1px solid #c4c4c4', background: '#ececec'} + background: '#ececec'} + }} > { - gridState[0].map((row, col) => { + gridState[0].map((row, idx) => { return ( -
- { gridState.map((row, idx) => row.map((val, jdx) => { @@ -138,8 +126,8 @@ class TableInput extends React.Component { }) ) } - -
+ +