-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issue #0000 fix: Lives mechanics changes for getset result #29
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -265,7 +265,7 @@ function VoiceAnalyser(props) { | |||||||
); | ||||||||
data = updateLearnerData; | ||||||||
responseText = data.responseText; | ||||||||
newThresholdPercentage = data?.targetsPercentage || 0; | ||||||||
newThresholdPercentage = data?.subsessionTargetsCount || 0; | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ensure that - newThresholdPercentage = data?.subsessionTargetsCount || 0;
+ newThresholdPercentage = data?.subsessionTargetsCount || 1; // Consider using a default value that prevents division by zero. This change helps to ensure that the application behaves predictably even when Committable suggestion
Suggested change
|
||||||||
handlePercentageForLife(newThresholdPercentage); | ||||||||
} | ||||||||
|
||||||||
|
@@ -388,21 +388,12 @@ function VoiceAnalyser(props) { | |||||||
}; | ||||||||
|
||||||||
const handlePercentageForLife = (percentage) => { | ||||||||
percentage = (percentage / livesData.totalTargets) * 100; | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider adding a check to ensure + if (livesData.totalTargets === 0) return; // Prevent division by zero
percentage = (percentage / livesData.totalTargets) * 100; This precaution prevents potential runtime errors due to division by zero. Committable suggestion
Suggested change
|
||||||||
try { | ||||||||
const THRESHOLD_PERCENTAGE = 30; | ||||||||
let newLivesData = {}; | ||||||||
|
||||||||
if (livesData) { | ||||||||
if (percentage > THRESHOLD_PERCENTAGE) { | ||||||||
let redLivesToShow = 0; | ||||||||
let blackLivesToShow = 5; | ||||||||
newLivesData = { | ||||||||
...livesData, | ||||||||
blackLivesToShow, | ||||||||
redLivesToShow, | ||||||||
}; | ||||||||
// 5 black , 0 red | ||||||||
} else if (percentage >= 0 && percentage <= 5) { | ||||||||
if (percentage >= 0 && percentage <= 5) { | ||||||||
let redLivesToShow = 5; | ||||||||
let blackLivesToShow = 0; | ||||||||
newLivesData = { | ||||||||
|
@@ -447,6 +438,14 @@ function VoiceAnalyser(props) { | |||||||
redLivesToShow, | ||||||||
}; | ||||||||
// 1 red , 4 black | ||||||||
}else{ | ||||||||
let redLivesToShow = 0; | ||||||||
let blackLivesToShow = 5; | ||||||||
newLivesData = { | ||||||||
...livesData, | ||||||||
blackLivesToShow, | ||||||||
redLivesToShow, | ||||||||
}; | ||||||||
} | ||||||||
|
||||||||
var audio = new Audio( | ||||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -60,6 +60,7 @@ const Practice = () => { | |||||
const [openMessageDialog, setOpenMessageDialog] = useState(""); | ||||||
const { state } = useLocation(); | ||||||
const lang = getLocalData("lang"); | ||||||
const [totalSyllableCount, setTotalSyllableCount] = useState(''); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Initialize - const [totalSyllableCount, setTotalSyllableCount] = useState('');
+ const [totalSyllableCount, setTotalSyllableCount] = useState(0); This ensures that Committable suggestion
Suggested change
|
||||||
|
||||||
const gameOver = (data) => { | ||||||
let userWon = livesData?.redLivesToShow > 0; | ||||||
|
@@ -223,6 +224,7 @@ const Practice = () => { | |||||
sessionId: sessionId, | ||||||
subSessionId: sub_session_id, | ||||||
milestoneLevel: getSetData?.data?.currentLevel, | ||||||
totalSyllableCount: totalSyllableCount, | ||||||
language: localStorage.getItem("lang"), | ||||||
} | ||||||
); | ||||||
|
@@ -280,9 +282,10 @@ const Practice = () => { | |||||
`${process.env.REACT_APP_LEARNER_AI_APP_HOST}/${config.URLS.GET_CONTENT}/${currentGetContent.criteria}/${virtualId}?language=${lang}&contentlimit=${limit}&gettargetlimit=${limit}` | ||||||
); | ||||||
|
||||||
setTotalSyllableCount(resGetContent?.data?.totalSyllableCount) | ||||||
setLivesData({ | ||||||
...livesData, | ||||||
totalTargets: resGetContent?.data?.totalTargets, | ||||||
totalTargets: resGetContent?.data?.totalSyllableCount, | ||||||
targetsForLives: | ||||||
resGetContent?.data?.totalTargets * TARGETS_PERCENTAGE, | ||||||
targetPerLive: | ||||||
|
@@ -413,9 +416,10 @@ const Practice = () => { | |||||
const resWord = await axios.get( | ||||||
`${process.env.REACT_APP_LEARNER_AI_APP_HOST}/${config.URLS.GET_CONTENT}/${currentGetContent.criteria}/${virtualId}?language=${lang}&contentlimit=${limit}&gettargetlimit=${limit}` | ||||||
); | ||||||
setTotalSyllableCount(resGetContent?.data?.totalSyllableCount) | ||||||
setLivesData({ | ||||||
...livesData, | ||||||
totalTargets: resWord?.data?.totalTargets, | ||||||
totalTargets: resWord?.data?.totalSyllableCount, | ||||||
targetsForLives: resWord?.data?.totalTargets * TARGETS_PERCENTAGE, | ||||||
targetPerLive: | ||||||
(resWord?.data?.totalTargets * TARGETS_PERCENTAGE) / LIVES, | ||||||
|
@@ -502,9 +506,10 @@ const Practice = () => { | |||||
const resWord = await axios.get( | ||||||
`${process.env.REACT_APP_LEARNER_AI_APP_HOST}/${config.URLS.GET_CONTENT}/${currentGetContent.criteria}/${virtualId}?language=${lang}&contentlimit=${limit}&gettargetlimit=${limit}` | ||||||
); | ||||||
setTotalSyllableCount(resGetContent?.data?.totalSyllableCount) | ||||||
setLivesData({ | ||||||
...livesData, | ||||||
totalTargets: resWord?.data?.totalTargets, | ||||||
totalTargets: resWord?.data?.totalSyllableCount, | ||||||
targetsForLives: resWord?.data?.totalTargets * TARGETS_PERCENTAGE, | ||||||
targetPerLive: | ||||||
(resWord?.data?.totalTargets * TARGETS_PERCENTAGE) / LIVES, | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider initializing
totalSyllableCount
with a numerical value (e.g., 0) instead of an empty string if it's meant to store a count.This change ensures type consistency and prevents potential type coercion issues when performing arithmetic operations or comparisons.
Committable suggestion