Skip to content

Commit

Permalink
Merge pull request #33 from ajinkyapandetekdi/Sentence-Sequence-score
Browse files Browse the repository at this point in the history
Sentence Sequence and Score of Result
  • Loading branch information
gouravmore authored Jul 18, 2023
2 parents a2c53d1 + 0bfa2b1 commit 4df5e1a
Show file tree
Hide file tree
Showing 4 changed files with 214 additions and 126 deletions.
81 changes: 50 additions & 31 deletions src/views/Score/Score.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,27 +117,47 @@ function Score() {
const [ocurracy_percentage, setOcurracy_percentage] = useState('');
const [newtextresult, setnewtextresult] = useState('');
const [fluencyresult, setfluencyresult] = useState('');
const [percentages, setpercentages] = useState(0)
const [percentages, setpercentages] = useState(0);

useEffect(() => {
if (voiceText && voiceText !== '') {
checkVoice(voiceText);
}
}, [voiceText]);

function handleScore() {
let tempVoiceText = voiceText.toLowerCase().split(' ');
let tempVoiceTeacher = teacherText.toLowerCase().split(' ');

let rightWords = 0;
let myLength = 0;
if (tempVoiceTeacher.length > tempVoiceText.length) {
myLength = tempVoiceTeacher.length;
} else {
myLength = tempVoiceText.length;
}
for (let i = 0; i < myLength; i++) {
if (tempVoiceText[i] === tempVoiceTeacher[i]) {
rightWords++;
}
}
let myPercentages = Math.round((rightWords / myLength) * 100);
return myPercentages;
}

function checkVoice(voiceText) {
let tempvoiceText = voiceText?.toLowerCase();
tempvoiceText = replaceAll(tempvoiceText, '.', '');
tempvoiceText = replaceAll(tempvoiceText, "'", '');
tempvoiceText = replaceAll(tempvoiceText, "’", '');
tempvoiceText = replaceAll(tempvoiceText, ',', '');
tempvoiceText = replaceAll(tempvoiceText, '!', '');
tempvoiceText = replaceAll(tempvoiceText, '|', '');
tempvoiceText = replaceAll(tempvoiceText, '?', '');
tempvoiceText = replaceAll(tempvoiceText, '.', '');
tempvoiceText = replaceAll(tempvoiceText, "'", '');
tempvoiceText = replaceAll(tempvoiceText, '’', '');
tempvoiceText = replaceAll(tempvoiceText, ',', '');
tempvoiceText = replaceAll(tempvoiceText, '!', '');
tempvoiceText = replaceAll(tempvoiceText, '|', '');
tempvoiceText = replaceAll(tempvoiceText, '?', '');
let tempteacherText = teacherText?.toLowerCase();
tempteacherText = replaceAll(tempteacherText, '.', '');
tempteacherText = replaceAll(tempteacherText, "'", '');
tempteacherText = replaceAll(tempteacherText, "’", '');
tempteacherText = replaceAll(tempteacherText, '’', '');
tempteacherText = replaceAll(tempteacherText, ',', '');
tempteacherText = replaceAll(tempteacherText, '!', '');
tempteacherText = replaceAll(tempteacherText, '|', '');
Expand Down Expand Up @@ -167,21 +187,22 @@ function Score() {
let texttemp = voiceText.toLowerCase();
texttemp = replaceAll(texttemp, '.', '');
texttemp = replaceAll(texttemp, "'", '');
texttemp = replaceAll(texttemp, "’", '');
texttemp = replaceAll(texttemp, ',', '');
texttemp = replaceAll(texttemp, '!', '');
texttemp = replaceAll(texttemp, '|', '');
texttemp = replaceAll(texttemp, '?', '');
const studentTextArray = texttemp.split(' ');
texttemp = replaceAll(texttemp, '’', '');
texttemp = replaceAll(texttemp, ',', '');
texttemp = replaceAll(texttemp, '!', '');
texttemp = replaceAll(texttemp, '|', '');
texttemp = replaceAll(texttemp, '?', '');
const studentTextArray = texttemp.split(' ');
const teacherTextArray = tempteacherText.split(' ');
let student_text_result = [];
let originalwords = teacherTextArray.length;
let studentswords = studentTextArray.length;
let wrong_words = 0;
let correct_words = 0;
let result_per_words = 0;
for (let i = 0; i < studentTextArray.length; i++) {
if (teacherTextArray.includes(studentTextArray[i])) {

for (let i = 0; i < studentTextArray?.length; i++) {
if (teacherTextArray[i] === studentTextArray[i]) {
correct_words++;
student_text_result.push(
<>
Expand All @@ -199,6 +220,7 @@ function Score() {
);
}
}

setOcurracy_percentage(
<>
{' '}
Expand All @@ -213,12 +235,12 @@ function Score() {
result_per_words = Math.round(
Number((correct_words / originalwords) * 100)
);
setpercentages(result_per_words)
setpercentages(result_per_words);
} else {
result_per_words = Math.round(
Number((correct_words / studentswords) * 100)
);
setpercentages(result_per_words)
setpercentages(result_per_words);
}
set_numberOfPieces(result_per_words);
set_isStart(true);
Expand Down Expand Up @@ -247,7 +269,7 @@ function Score() {
setTestResult(
<>
<div className="res_txt">
<>{result_per_words}/100</>
<>{handleScore()}/100</>
</div>
<br />
</>
Expand Down Expand Up @@ -278,8 +300,8 @@ function Score() {
<br />
<br />
<div className="content_text_div_see">
{percentages===100? voiceText:voiceTextHighlight}
</div>
{handleScore() === 100 ? voiceText : voiceTextHighlight}
</div>
<br />
{flag ? (
<>
Expand Down Expand Up @@ -466,15 +488,12 @@ function Score() {
onClick={() => {
//localStorage.setItem("apphomelang", resultnextlang);
const next_apphomelevel =
apphomelevel === 'Word'
? 'Sentence'
: apphomelevel === 'Sentence'
? 'Paragraph'
: 'Word';
localStorage.setItem(
'apphomelevel',
next_apphomelevel
);
apphomelevel === 'Word'
? 'Sentence'
: apphomelevel === 'Sentence'
? 'Paragraph'
: 'Word';
localStorage.setItem('apphomelevel', next_apphomelevel);
navigate(
isfromresult === 'learn'
? '/startlearn'
Expand Down
35 changes: 28 additions & 7 deletions src/viewsProto2/Score/Score.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,34 @@ function Score() {
function replaceAll(string, search, replace) {
return string.split(search).join(replace);
}
function handleScore() {
let tempVoiceText = voiceText.toLowerCase().split(' ');
let tempVoiceTeacher = teacherText.toLowerCase().split(' ');

let rightWords = 0;
let myLength = 0;
if (tempVoiceTeacher.length > tempVoiceText.length) {
myLength = tempVoiceTeacher.length;
} else {
myLength = tempVoiceText.length;
}
for (let i = 0; i < myLength; i++) {
if (tempVoiceText[i] === tempVoiceTeacher[i]) {
rightWords++;
}
}
let myPercentages = Math.round((rightWords / myLength) * 100);
return myPercentages;
}

function checkVoice(voiceText) {
let tempvoiceText = voiceText?.toLowerCase();
tempvoiceText = replaceAll(tempvoiceText, '.', '');
tempvoiceText = replaceAll(tempvoiceText, "'", '');
tempvoiceText = replaceAll(tempvoiceText, ',', '');
tempvoiceText = replaceAll(tempvoiceText, '!', '');
tempvoiceText = replaceAll(tempvoiceText, '|', '');
tempvoiceText = replaceAll(tempvoiceText, '?', '');
tempvoiceText = replaceAll(tempvoiceText, ',', '');
tempvoiceText = replaceAll(tempvoiceText, '!', '');
tempvoiceText = replaceAll(tempvoiceText, '|', '');
tempvoiceText = replaceAll(tempvoiceText, '?', '');
let tempteacherText = teacherText?.toLowerCase();
tempteacherText = replaceAll(tempteacherText, '.', '');
tempteacherText = replaceAll(tempteacherText, "'", '');
Expand Down Expand Up @@ -172,8 +192,9 @@ function Score() {
let wrong_words = 0;
let correct_words = 0;
let result_per_words = 0;

for (let i = 0; i < studentTextArray?.length; i++) {
if (teacherTextArray.includes(studentTextArray[i])) {
if (teacherTextArray[i] === studentTextArray[i]) {
correct_words++;
student_text_result.push(
<>
Expand Down Expand Up @@ -239,7 +260,7 @@ function Score() {
{originalwords < studentswords ? (
<font style={{ color: 'red' }}>You have recorded extra word</font>
) : (
<>{result_per_words}/100</>
<>{handleScore()}/100</>
)}
</div>
<br />
Expand Down Expand Up @@ -288,7 +309,7 @@ function Score() {
<hr />
{testResult}
<hr />*/}
{contenttype != 'Word' && numberOfPieces > 50 ? (
{contenttype !== 'Word' && numberOfPieces > 50 ? (
<>
<br />
<br />
Expand Down
49 changes: 35 additions & 14 deletions src/viewsProto3/Score/Score.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,28 +118,48 @@ function Score() {
const [ocurracy_percentage, setOcurracy_percentage] = useState('');
const [newtextresult, setnewtextresult] = useState('');
const [fluencyresult, setfluencyresult] = useState('');
const [percentages, setpercentages] = useState(0)
const [percentages, setpercentages] = useState(0);

useEffect(() => {
if (voiceText && voiceText !== '') {
checkVoice(voiceText);
}
}, [voiceText]);

function handleScore() {
let tempVoiceText = voiceText.toLowerCase().split(' ');
let tempVoiceTeacher = teacherText.toLowerCase().split(' ');

let rightWords = 0;
let myLength = 0;
if (tempVoiceTeacher.length > tempVoiceText.length) {
myLength = tempVoiceTeacher.length;
} else {
myLength = tempVoiceText.length;
}
for (let i = 0; i < myLength; i++) {
if (tempVoiceText[i] === tempVoiceTeacher[i]) {
rightWords++;
}
}
let myPercentages = Math.round((rightWords / myLength) * 100);
return myPercentages;
}

function checkVoice(voiceText) {
let tempvoiceText = voiceText?.toLowerCase();
tempvoiceText = replaceAll(tempvoiceText, '.', '');
tempvoiceText = replaceAll(tempvoiceText, "'", '');
tempvoiceText = replaceAll(tempvoiceText, "’", '');
tempvoiceText = replaceAll(tempvoiceText, ',', '');
tempvoiceText = replaceAll(tempvoiceText, '!', '');
tempvoiceText = replaceAll(tempvoiceText, '|', '');
tempvoiceText = replaceAll(tempvoiceText, '?', '');
tempvoiceText = replaceAll(tempvoiceText, '’', '');
tempvoiceText = replaceAll(tempvoiceText, ',', '');
tempvoiceText = replaceAll(tempvoiceText, '!', '');
tempvoiceText = replaceAll(tempvoiceText, '|', '');
tempvoiceText = replaceAll(tempvoiceText, '?', '');

let tempteacherText = teacherText?.toLowerCase();
tempteacherText = replaceAll(tempteacherText, '.', '');
tempteacherText = replaceAll(tempteacherText, "'", '');
tempteacherText = replaceAll(tempteacherText, "’", '');
tempteacherText = replaceAll(tempteacherText, '’', '');
tempteacherText = replaceAll(tempteacherText, ',', '');
tempteacherText = replaceAll(tempteacherText, '!', '');
tempteacherText = replaceAll(tempteacherText, '|', '');
Expand Down Expand Up @@ -175,8 +195,9 @@ function Score() {
let wrong_words = 0;
let correct_words = 0;
let result_per_words = 0;
for (let i = 0; i < studentTextArray.length; i++) {
if (teacherTextArray.includes(studentTextArray[i])) {

for (let i = 0; i < studentTextArray?.length; i++) {
if (teacherTextArray[i] === studentTextArray[i]) {
correct_words++;
student_text_result.push(
<>
Expand Down Expand Up @@ -207,12 +228,12 @@ function Score() {
result_per_words = Math.round(
Number((correct_words / originalwords) * 100)
);
setpercentages(result_per_words)
setpercentages(result_per_words);
} else {
result_per_words = Math.round(
Number((correct_words / studentswords) * 100)
);
setpercentages(result_per_words)
setpercentages(result_per_words);
}
set_numberOfPieces(result_per_words);
set_isStart(true);
Expand Down Expand Up @@ -241,7 +262,7 @@ function Score() {
setTestResult(
<>
<div className="res_txt">
<>{result_per_words}/100</>
<>{handleScore()}/100</>
</div>
<br />
</>
Expand Down Expand Up @@ -275,8 +296,8 @@ function Score() {
<br />
<br />
<div className="content_text_div_see">
{percentages===100? teacherText:voiceTextHighlight}
</div>
{handleScore() === 100 ? teacherText : voiceTextHighlight}
</div>
<br />
{flag ? (
<div style={{ marginBottom: '-30px' }}>
Expand Down
Loading

0 comments on commit 4df5e1a

Please sign in to comment.