Average of Everyone's Max Times Played With Someone: {Math.round(result.averageMaxPlayedWithCount * 100) / 100}
- Average Number of Unique Tables Visited: {Math.round(result.averageUniqueTablesVisited * 100) / 100}
+ Average of everyone's max times seeing one person: {Math.round(result.averageMaxPlayedWithCount * 100) / 100}
+ Average unique tables visited: {Math.round(result.averageUniqueTablesVisited * 100) / 100}
{result.playerList.length > 0 &&
diff --git a/src/Components/Subcomponents/SingleInput.jsx b/src/Components/Subcomponents/SingleInput.jsx
index 20f7307..d2c2d3d 100644
--- a/src/Components/Subcomponents/SingleInput.jsx
+++ b/src/Components/Subcomponents/SingleInput.jsx
@@ -1,15 +1,16 @@
import React from 'react';
import PropTypes from 'prop-types';
-// Pure functional component defined as a const
+
const SingleInput = (props) => (
{props.title}
@@ -26,6 +27,9 @@ SingleInput.propTypes = {
PropTypes.number,
]).isRequired,
placeholder: PropTypes.string,
+ min: PropTypes.number,
+ max: PropTypes.number,
+ step: PropTypes.number,
};
export default SingleInput;
diff --git a/src/Components/Subcomponents/StatefulButton.jsx b/src/Components/Subcomponents/StatefulButton.jsx
index 5572984..d61193b 100644
--- a/src/Components/Subcomponents/StatefulButton.jsx
+++ b/src/Components/Subcomponents/StatefulButton.jsx
@@ -8,9 +8,6 @@ StatefulButton.propTypes = {
icon: PropTypes.string,
name: PropTypes.string,
onChange: PropTypes.func.isRequired,
- // TODO pull a simple selected/unselected toggle handler out into a util for reuse
- // but I don't think I should just put that logic here since I'll want the parent to be aware of changes? Could add context instead
- // TODO decide what the selected status does in terms of styling - fill in the background?
};
function StatefulButton({
diff --git a/src/worker.js b/src/worker.js
index a288b89..6be2246 100644
--- a/src/worker.js
+++ b/src/worker.js
@@ -66,14 +66,14 @@ function runAlgorithm() {
// Different Run Options
let result;
switch (algorithmChoice) {
- case 'runRandomXTimes':
- result = runRandomXTimes(algorithmDetails.numTimesToRun); // 500 is a good number
+ case 'runRandomNTimes':
+ result = runRandomNTimes(algorithmDetails.numTimesToRun); // 500 is a good number
break;
case 'runUntilConstraints':
- result = runRandomXTimes(algorithmDetails.maxRuns);
+ result = runRandomNTimes(algorithmDetails.maxRuns);
break;
default:
- result = runRandomXTimes(algorithmDetails.numTimesToRun); // 500 is a good number
+ result = runRandomNTimes(algorithmDetails.numTimesToRun); // 500 is a good number
break;
}
console.log('RESULT', result);
@@ -92,7 +92,7 @@ function runRandomAndChooseBest(currentBestRun) {
return compareResults({playerList: resultPlayerList, ...resultStats}, currentBestRun);
}
-function runRandomXTimes(numRuns) {
+function runRandomNTimes(numRuns) {
let bestRun = {
playerList: [],
maxPlayedWithCount: 100,
From fc75b02124231e91c5ceb64b935455e12995b621 Mon Sep 17 00:00:00 2001
From: Bridget Bailey <10903271+bbailey27@users.noreply.github.com>
Date: Mon, 2 Dec 2024 23:35:02 -0600
Subject: [PATCH 4/4] Remove manual input for total player count
---
src/Components/Constraints.jsx | 12 ++---
src/Components/DataEntry.jsx | 46 ++++++--------------
src/Components/Details.jsx | 15 ++-----
src/Components/Subcomponents/SingleInput.jsx | 4 +-
src/Components/Tables.jsx | 6 +--
5 files changed, 27 insertions(+), 56 deletions(-)
diff --git a/src/Components/Constraints.jsx b/src/Components/Constraints.jsx
index c6554a4..dd84180 100644
--- a/src/Components/Constraints.jsx
+++ b/src/Components/Constraints.jsx
@@ -41,7 +41,7 @@ class Constraints extends Component {
inputType='number'
title='Max number of plays with same person allowed: '
name='maxPlayedWithAllowed'
- controlFunc={(e) => handleNumberChange(e, 'maxPlayedWithAllowed')}
+ onChange={(e) => handleNumberChange(e, 'maxPlayedWithAllowed')}
content={maxPlayedWithAllowed}
max={totalRounds}
min={1}
@@ -57,7 +57,7 @@ class Constraints extends Component {
inputType='number'
title='Max allowed average number of plays with same person: '
name='maxAveragePlayedWithAllowed'
- controlFunc={(e) => handleDecimalChange(e, 'maxAveragePlayedWithAllowed')}
+ onChange={(e) => handleDecimalChange(e, 'maxAveragePlayedWithAllowed')}
content={maxAveragePlayedWithAllowed}
max={totalRounds}
min={1}
@@ -73,7 +73,7 @@ class Constraints extends Component {
inputType='number'
title='Minimum allowed number of unique tables visited: '
name='minUniqueTablesAllowed'
- controlFunc={(e) => handleNumberChange(e, 'minUniqueTablesAllowed')}
+ onChange={(e) => handleNumberChange(e, 'minUniqueTablesAllowed')}
content={minUniqueTablesAllowed}
max={totalRounds}
min={1}
@@ -89,7 +89,7 @@ class Constraints extends Component {
inputType='number'
title='Minimum allowed average number of unique tables visited: '
name='minAverageUniqueTablesAllowed'
- controlFunc={(e) => handleDecimalChange(e, 'minAverageUniqueTablesAllowed')}
+ onChange={(e) => handleDecimalChange(e, 'minAverageUniqueTablesAllowed')}
content={minAverageUniqueTablesAllowed}
max={totalRounds}
min={1}
@@ -105,7 +105,7 @@ class Constraints extends Component {
inputType='number'
title='Max times to run: '
name='maxRuns'
- controlFunc={(e) => handleNumberChange(e, 'maxRuns')}
+ onChange={(e) => handleNumberChange(e, 'maxRuns')}
content={maxRuns}
max={10000}
min={1}
@@ -120,7 +120,7 @@ class Constraints extends Component {
inputType='number'
title='Number of times to run: '
name='numTimesToRun'
- controlFunc={(e) => handleNumberChange(e, 'numTimesToRun')}
+ onChange={(e) => handleNumberChange(e, 'numTimesToRun')}
content={numTimesToRun}
max={10000}
min={1}
diff --git a/src/Components/DataEntry.jsx b/src/Components/DataEntry.jsx
index c61dc45..4131e15 100644
--- a/src/Components/DataEntry.jsx
+++ b/src/Components/DataEntry.jsx
@@ -11,7 +11,6 @@ const defaultData = {
changePeople: true,
changeTables: true,
},
- totalPlayers: 20,
totalRounds: 4,
algorithmChoice: 'runRandomNTimes',
numTimesToRun: 500,
@@ -59,8 +58,6 @@ class DataEntry extends Component {
constructor(props) {
super(props);
this.handleOptionsChange = this.handleOptionsChange.bind(this);
- this.handleNumPlayersChange = this.handleNumPlayersChange.bind(this);
- this.handleNumRoundsChange = this.handleNumRoundsChange.bind(this);
this.handleNumberChange = this.handleNumberChange.bind(this);
this.handleDecimalChange = this.handleDecimalChange.bind(this);
this.handleAlgorithmChange = this.handleAlgorithmChange.bind(this);
@@ -80,21 +77,10 @@ class DataEntry extends Component {
});
}
- handleNumPlayersChange = (e) => {
+ handleNumberChange = (e, property, value = null) => {
+ const newValue = value !== null ? value : parseInt(e.target.value) || 0;
this.setState({
- totalPlayers: parseInt(e.target.value) ? parseInt(e.target.value) : 0
- });
- }
-
- handleNumRoundsChange = (e) => {
- this.setState({
- totalRounds: parseInt(e.target.value) ? parseInt(e.target.value) : 0
- });
- }
-
- handleNumberChange = (e, property) => {
- this.setState({
- [property]: parseInt(e.target.value) ? parseInt(e.target.value) : 0
+ [property]: newValue
});
}
@@ -125,9 +111,13 @@ class DataEntry extends Component {
handleFormSubmit = (e) => {
e.preventDefault();
+ const totalPlayers = this.state.tables.reduce((accumulator, currentItem) => {
+ return accumulator + currentItem.size
+ }, 0)
+
const formPayload = {
options: this.state.options,
- totalPlayers: this.state.totalPlayers,
+ totalPlayers,
totalRounds: this.state.totalRounds,
algorithmChoice: this.state.algorithmChoice,
numTimesToRun: this.state.numTimesToRun,
@@ -141,23 +131,15 @@ class DataEntry extends Component {
};
console.log('Send this in a POST request:', formPayload);
- const totalTableSpots = formPayload.tables.reduce(function(a, b) {
- return a + b.size;
- }, 0);
- if (formPayload.totalPlayers !== totalTableSpots) {
- throw new Error('Number of players must match number of table spots');
- } else {
- let result = runOrganizer(formPayload);
- this.props.handleTablesReady(this.state.tables);
- this.props.handleResultReady(result);
- this.setState({firstRun: false});
- }
+ let result = runOrganizer(formPayload);
+ this.props.handleTablesReady(this.state.tables);
+ this.props.handleResultReady(result);
+ this.setState({firstRun: false});
}
// TODO change to across the top to have more room for table data entry
render() {
const {
options,
- totalPlayers,
totalRounds,
algorithmChoice,
numTimesToRun,
@@ -177,10 +159,8 @@ class DataEntry extends Component {
handleOptionsChange={this.handleOptionsChange} />
+ handleNumberChange={this.handleNumberChange} />
Details
-
handleNumberChange(e, 'totalRounds')}
content={totalRounds}
/>
diff --git a/src/Components/Subcomponents/SingleInput.jsx b/src/Components/Subcomponents/SingleInput.jsx
index d2c2d3d..eeaa253 100644
--- a/src/Components/Subcomponents/SingleInput.jsx
+++ b/src/Components/Subcomponents/SingleInput.jsx
@@ -12,7 +12,7 @@ const SingleInput = (props) => (
max={props.max}
step={props.step}
value={props.content}
- onChange={props.controlFunc}
+ onChange={props.onChange}
placeholder={props.placeholder} />
);
@@ -21,7 +21,7 @@ SingleInput.propTypes = {
inputType: PropTypes.oneOf(['text', 'number']).isRequired,
title: PropTypes.string.isRequired,
name: PropTypes.string.isRequired,
- controlFunc: PropTypes.func.isRequired,
+ onChange: PropTypes.func.isRequired,
content: PropTypes.oneOfType([
PropTypes.string,
PropTypes.number,
diff --git a/src/Components/Tables.jsx b/src/Components/Tables.jsx
index b0d5b31..a7c978e 100644
--- a/src/Components/Tables.jsx
+++ b/src/Components/Tables.jsx
@@ -92,14 +92,14 @@ class Tables extends Component {
inputType='text'
title='Name: '
name='tableName'
- controlFunc={this.handleTableNameChange}
+ onChange={this.handleTableNameChange}
content={table.name}
/>
X