hydrometrics's Issues
Hallucianating Questionaire
The observed problems are:
-
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 -
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](https://private-user-images.githubusercontent.com/111554368/313385175-15a6c890-ffcb-4258-b8d0-3f03f97a607b.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjE3NjIwODEsIm5iZiI6MTcyMTc2MTc4MSwicGF0aCI6Ii8xMTE1NTQzNjgvMzEzMzg1MTc1LTE1YTZjODkwLWZmY2ItNDI1OC1iOGQwLTNmMDNmOTdhNjA3Yi5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjQwNzIzJTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI0MDcyM1QxOTA5NDFaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT1lN2NjYTkwZTRjZWFjZGUwYjc1YzNkZjVlNWZkODkyZjBmYTZiYTFlNjBkMjA1YzZkMzBiZmRiOTY0OTgxNTQzJlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCZhY3Rvcl9pZD0wJmtleV9pZD0wJnJlcG9faWQ9MCJ9.XH-8X_6BHpv_ZlsaTHXHGmnQTW-me9ZBNo94HA2Hr_Y)
![Screenshot 2024-03-16 at 12 56 13 PM](https://private-user-images.githubusercontent.com/111554368/313385325-9af5c67a-5f1e-4365-9d70-3769d4065b8b.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjE3NjIwODEsIm5iZiI6MTcyMTc2MTc4MSwicGF0aCI6Ii8xMTE1NTQzNjgvMzEzMzg1MzI1LTlhZjVjNjdhLTVmMWUtNDM2NS05ZDcwLTM3NjlkNDA2NWI4Yi5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjQwNzIzJTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI0MDcyM1QxOTA5NDFaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT0wMjI2YjUwMTA2ODViZDY2NTI3ZGU3ZDNjMzJmYTZhYTkwNWQyOTk1Y2RlMWQ3NWM1ZTY1NTA4YTRiMTdmYWVmJlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCZhY3Rvcl9pZD0wJmtleV9pZD0wJnJlcG9faWQ9MCJ9.rYkC92mwt_NLnE14pGu_uC0oC097zB7aTN_1Ezup0cU)
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
- 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,
});
- 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
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.