diff --git a/src/pages/Story/Discover.jsx b/src/pages/Story/Discover.jsx index 32f770d..595f6ad 100644 --- a/src/pages/Story/Discover.jsx +++ b/src/pages/Story/Discover.jsx @@ -235,11 +235,11 @@ const handleSubmit = () => { navigate(`/discoverylist/discovery/${collectionId}`) } - async function saveIndb(base64Data) { - let lang = localStorage.getItem('apphomelang') || 'ta'; - showLoading(); - // .replace(/[.',|!|?-']/g, '') - let responseText = ""; +async function saveIndb(base64Data) { + let lang = localStorage.getItem('apphomelang') || 'ta'; + showLoading(); + // .replace(/[.',|!|?-']/g, '') + let responseText = ""; const utcDate = new Date().toISOString().split('T')[0]; const responseStartTime = new Date().getTime(); axios @@ -281,39 +281,74 @@ const handleSubmit = () => { tempteacherText = replaceAll(tempteacherText, '?', ''); const teacherTextArray = tempteacherText.split(' '); - let student_correct_words_result = []; - let student_incorrect_words_result = []; + let studentCorrectWordsResult = []; + let studentIncorrectWordsResult = []; + let incorrectWords = []; + let studentTextResult = []; let originalwords = teacherTextArray.length; let studentswords = studentTextArray.length; - let wrong_words = 0; - let correct_words = 0; - let result_per_words = 0; - let result_per_words1 = 0; - let occuracy_percentage = 0; + let wrongWords = 0; + let correctWords = 0; + let resultPerWords = 0; + let resultPerWords1 = 0; + let occuracyPercentage = 0; + let existingIncorrectWords = JSON.parse(localStorage.getItem('incorrectWords')) || []; + + for (let i = 0; i < studentTextArray?.length; i++) { + if (teacherTextArray[i] === studentTextArray[i]) { + correctWords++; + studentTextResult.push( + <> + {' '} + {studentTextArray[i]} + + ); + } else if (teacherTextArray.includes(studentTextArray[i])) { + studentTextResult.push( + <> + {' '} + {studentTextArray[i]} + + ); + } else { + wrongWords++; + if(teacherTextArray[i])incorrectWords.push(teacherTextArray[i]); + studentTextResult.push( + <> + {' '} + {studentTextArray[i]} + + ); + } + } + let mergedArray = existingIncorrectWords.concat(incorrectWords); + let uniqueWordsSet = new Set(mergedArray); + let uniqueWordsArray = Array.from(uniqueWordsSet); + localStorage.setItem('incorrectWords', JSON.stringify(uniqueWordsArray)); let word_result_array = compareArrays(teacherTextArray, studentTextArray); for (let i = 0; i < studentTextArray.length; i++) { if (teacherTextArray.includes(studentTextArray[i])) { - correct_words++; - student_correct_words_result.push( + correctWords++; + studentCorrectWordsResult.push( studentTextArray[i] ); } else { - wrong_words++; - student_incorrect_words_result.push( + wrongWords++; + studentIncorrectWordsResult.push( studentTextArray[i] ); } } //calculation method if (originalwords >= studentswords) { - result_per_words = Math.round( - Number((correct_words / originalwords) * 100) + resultPerWords = Math.round( + Number((correctWords / originalwords) * 100) ); } else { - result_per_words = Math.round( - Number((correct_words / studentswords) * 100) + resultPerWords = Math.round( + Number((correctWords / studentswords) * 100) ); } @@ -353,8 +388,8 @@ const handleSubmit = () => { "values": [ { "original_text": posts?.data[currentLine]?.contentSourceData[0]?.text }, { "response_text": responseText }, - { "response_correct_words_array": student_correct_words_result }, - { "response_incorrect_words_array": student_incorrect_words_result }, + { "response_correct_words_array": studentCorrectWordsResult }, + { "response_incorrect_words_array": studentIncorrectWordsResult }, { "response_word_array_result": word_result_array }, { "response_word_result": word_result }, { "accuracy_percentage": finalScore }, @@ -399,156 +434,209 @@ const handleSubmit = () => { //setPageNo(pageno + 1) } }, [currentLine]) - return ( <> -
- -
-
- - {loading ? ( -
- ) : isUserSpeak ? ( - <> - - - -
- {currentLine === 1 ?

Very Good

: currentLine === 2 ?

Nice Try

: currentLine === 3 ?

WoW

:

Well Done

} -
-
- -
- next-button -

Try Next

-
-
- retry-again -

Try Again

-
-
-
-
- - - ) : ( - <> - {posts?.data?.map((post, ind) => - currentLine === ind ? ( -
-
- {post?.name} -
-
- -
-

- {posts?.data[currentLine]?.contentSourceData[0].text} -

- {localStorage.setItem( - 'contentText', - posts?.data[currentLine]?.contentSourceData[0].text - )} -
-
+
+ +
+
+ {loading ? ( +
+ ) : isUserSpeak ? ( + <> + +
+ {currentLine === 1 ? ( +

+ Very Good +

+ ) : currentLine === 2 ? ( +

+ Nice Try +

+ ) : currentLine === 3 ? ( +

+ WoW +

+ ) : ( +

+ Well Done +

+ )} +
+
+
+
+ +
+ next-button +

Try Next

+
+
+ retry-again +

Try Again

+
+
+
+
+ + ) : ( + <> + {posts?.data?.map((post, ind) => + currentLine === ind ? ( +
+
+ {post?.name} +
+
+ +
+

{ - isUserSpeak ? <> :
- {currentLine === posts?.data?.length ? ( - '' - ) : ( - <> -
- - setIsAudioPlay(e) }} - flag={true} - setCurrentLine={setCurrentLine} - setStoryBase64Data={setStoryBase64Data} - saveIndb={saveIndb} - setUserSpeak={setUserSpeak} - /> - {isAudioPlay === 'recording' ? ( -

- Stop -

- ) : ( -

- Speak -

- )} -
-
- - )} -
+ posts?.data[currentLine]?.contentSourceData[0] + .text } -

-
-
-
+ + {localStorage.setItem( + 'contentText', + posts?.data[currentLine]?.contentSourceData[0].text + )} +
+
+ {isUserSpeak ? ( + <> + ) : ( +
+ {currentLine === posts?.data?.length ? ( + '' + ) : ( + <> +
+ + setIsAudioPlay(e), + }} + flag={true} + setCurrentLine={setCurrentLine} + setStoryBase64Data={setStoryBase64Data} + saveIndb={saveIndb} + setUserSpeak={setUserSpeak} + /> + {isAudioPlay === 'recording' ? ( +

Stop

+ ) : ( +

+ Speak +

+ )} +
+
+ + )} +
+ )} +
+ +
+
+ ) : ( + '' + ) + )} + + )} +
+
+ {currentLine === posts?.data?.length ? ( + + + + + + {sessionResult === 'pass' ? 'Well Done !' : 'Good Job !'} + + + {sessionResult === 'pass' + ? 'Discover More For Level Up' + : 'Keep trying to Improve Level'} + + + + + + + ) : ( + '' + )} - ) : ( - '' - ) - )} - - )} - - - - {currentLine === posts?.data?.length ? ( - - - - - - {sessionResult === 'pass' - ? 'Well Done !' - : 'Good Job !'} - - - {sessionResult === 'pass' - ? "Discover More For Level Up" - : "Keep trying to Improve Level"} - - - - - - -) : ( - '' -)} - {/* Session Id: {localStorage.getItem('virtualStorySessionID')} */} - ); }; diff --git a/src/pages/Story/Showcase.jsx b/src/pages/Story/Showcase.jsx index eec17fa..7a902e1 100644 --- a/src/pages/Story/Showcase.jsx +++ b/src/pages/Story/Showcase.jsx @@ -196,6 +196,18 @@ const Showcase = ({forceRerender, setForceRerender}) => { return cleanString; } + function handleSpeechRecognition(spokenSentence) { + const spokenWords = spokenSentence.split(' '); + let existingIncorrectWords = + JSON.parse(localStorage.getItem('incorrectWords')) || []; + let updatedIncorrectWords = existingIncorrectWords.filter( + word => !spokenWords.includes(word) + ); + localStorage.setItem( + 'incorrectWords', + JSON.stringify(updatedIncorrectWords) + ); + } async function saveIndb(base64Data) { @@ -219,6 +231,7 @@ const Showcase = ({forceRerender, setForceRerender}) => { }) .then(async res => { responseText = res.data.responseText + handleSpeechRecognition(responseText) const responseEndTime = new Date().getTime(); const responseDuration = Math.round( (responseEndTime - responseStartTime) / 1000 diff --git a/src/pages/Test-Rig-Two/Story/Story.jsx b/src/pages/Test-Rig-Two/Story/Story.jsx index 2ed7193..67937be 100644 --- a/src/pages/Test-Rig-Two/Story/Story.jsx +++ b/src/pages/Test-Rig-Two/Story/Story.jsx @@ -80,6 +80,26 @@ const Story = ({ forceRerender, setForceRerender }) => { // return 0; // } // }); + + function highlightWords(sentence) { + let storedIncorrectWords = + JSON.parse(localStorage.getItem('incorrectWords')) || []; + const words = sentence.split(' '); + + const highlightedSentence = words.map((word, index) => { + if (storedIncorrectWords.includes(word)) { + return ( + + {word} + + ); + } else { + return word + ' '; + } + }); + return highlightedSentence; + } + const [completionCriteriaIndex, setCompletionCriteriaIndex] = useState( parseInt(localStorage.getItem('userPracticeState') || 0) ); @@ -567,17 +587,21 @@ const Story = ({ forceRerender, setForceRerender }) => { }} > -

- {post?.contentSourceData[0]?.text} -

+

+ {highlightWords( + post?.contentSourceData[0]?.text + )} +

{localStorage.setItem( 'contentText',