Giter Site home page Giter Site logo

hydrometrics's Issues

Hallucianating Questionaire

The observed problems are:

  1. On the question Is your household using any water purification methods, such as filters or purifiers, The tf values seem to be spiking upon repetative clicking of the yes button

  2. Going back to older questions in the form seems to be causing the form to hallucinate and show wrong values for the tf.

Screenshot 2024-03-16 at 12 52 40 PM Screenshot 2024-03-16 at 12 56 13 PM

My understanding of the current code

Loc: HydroMetrics/client/src/Pages/q.js

States used:

/**
 * @param {list} answers - Selected answer object
 * @param {number} members - Count of members in family (numeric)
 * @param {number} tf - Total footprint (water footprint) (numeric)
 * @param {*} prev - Previous value (unknown type)
 */

Current code Deign/Setup

// Imports

// State Declarations
// You may place your state declarations here

/**
 * @description Handles form submission.
 * Most probably hitting the backend with the form data.
 */
function handleSubmit() {
  // Your implementation for handling form submission goes here
}

/**
 * @description Handles input change.
 * This function is called after every question.
 *
 * @param {object} value - The selected/answer
 * @param {string} q - The question number
 * @returns {number} - Returns 500, doesn't return much, the objective is to change the state variable
 */
function handleInputChange(value, q) {
  // Your implementation for handling input change goes here
}

return <>All questionaire elements and the visual effects</>;

Proposed Solution

  1. The answers list can be converted to a dictionary with the question number as the key and the answer as the value. This will make it easier to handle the state changes and also make the code more readable.
const [answers, setAnswers] = useState({
  members: 0,
  question0: false,
  question1: false,
  question2: false,
  question3: 0,
  question4: 0,
  question5: 0,
  question6: 0,
  question7: 0,
  question8: 0,
});
  1. A computeTf function can be used to calculate the tf value based on the answers dictionary. This function can be called after every state change to update the tf value.
/**
 * @description - This function is used to calculate the tf value based on the answers dictionary
 * @returns {number} - The tf value
 * @param {object} answers - The answers dictionary
 *
*/
  const computeTf = () => {
	let tf = 0;
	if (answers.question0) {
	 ...
	}
	if (answers.question1) {
	 ...
	}
	if (answers.question2) {
	 ...
	}
	...
	setTf(tf);
  };

If you find this makes sense ill go ahead and implement the changes. If I seem to be missing something, please let me know.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.