Skip to content

Commit

Permalink
Issue #0000 fix: Lives mechanics changes for getset result
Browse files Browse the repository at this point in the history
  • Loading branch information
gouravmore committed Apr 5, 2024
1 parent ea4f3d8 commit 8836d5a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 15 deletions.
4 changes: 4 additions & 0 deletions src/components/DiscoverSentance/DiscoverSentance.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ const SpeakSentenceComponent = () => {
const [disableScreen, setDisableScreen] = useState(false);
const [play] = useSound(LevelCompleteAudio);
const [openMessageDialog, setOpenMessageDialog] = useState("");
const [totalSyllableCount, setTotalSyllableCount] = useState('');


const callConfettiAndPlay = () => {
play();
Expand Down Expand Up @@ -159,6 +161,7 @@ const SpeakSentenceComponent = () => {
session_id: localStorage.getItem("sessionId"),
user_id: localStorage.getItem("virtualId"),
collectionId: currentCollectionId,
totalSyllableCount: totalSyllableCount,
language: localStorage.getItem("lang"),
}
);
Expand Down Expand Up @@ -269,6 +272,7 @@ const SpeakSentenceComponent = () => {
`${process.env.REACT_APP_LEARNER_AI_APP_HOST}/${config.URLS.GET_PAGINATION}?page=1&limit=5&collectionId=${sentences?.content?.[0]?.collectionId}`
);
setCurrentContentType("Sentence");
setTotalSyllableCount(resPagination?.data?.totalSyllableCount)
setCurrentCollectionId(sentences?.content?.[0]?.collectionId);
setAssessmentResponse(resAssessment);
localStorage.setItem("storyTitle", sentences?.name);
Expand Down
23 changes: 11 additions & 12 deletions src/utils/VoiceAnalyser.js
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ function VoiceAnalyser(props) {
);
data = updateLearnerData;
responseText = data.responseText;
newThresholdPercentage = data?.targetsPercentage || 0;
newThresholdPercentage = data?.subsessionTargetsCount || 0;
handlePercentageForLife(newThresholdPercentage);
}

Expand Down Expand Up @@ -388,21 +388,12 @@ function VoiceAnalyser(props) {
};

const handlePercentageForLife = (percentage) => {
percentage = (percentage / livesData.totalTargets) * 100;
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 = {
Expand Down Expand Up @@ -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(
Expand Down
11 changes: 8 additions & 3 deletions src/views/Practice/Practice.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ const Practice = () => {
const [openMessageDialog, setOpenMessageDialog] = useState("");
const { state } = useLocation();
const lang = getLocalData("lang");
const [totalSyllableCount, setTotalSyllableCount] = useState('');

const gameOver = (data) => {
let userWon = livesData?.redLivesToShow > 0;
Expand Down Expand Up @@ -223,6 +224,7 @@ const Practice = () => {
sessionId: sessionId,
subSessionId: sub_session_id,
milestoneLevel: getSetData?.data?.currentLevel,
totalSyllableCount: totalSyllableCount,
language: localStorage.getItem("lang"),
}
);
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 8836d5a

Please sign in to comment.