Skip to content

Commit

Permalink
Merge pull request #168 from ajinkyapandetekdi/diff-test-rig-1.1
Browse files Browse the repository at this point in the history
#0000 update learner profile api calling in practice
  • Loading branch information
gouravmore authored Oct 9, 2024
2 parents c48fc3b + 582f35b commit 3ce8cb9
Showing 1 changed file with 68 additions and 63 deletions.
131 changes: 68 additions & 63 deletions src/utils/VoiceAnalyser.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,78 +262,83 @@ function VoiceAnalyser(props) {
let profanityWord = "";
let newThresholdPercentage = 0;
let data = {};
if (callUpdateLearner) {
try {
const durationData = localStorage.getItem("duration");

try {
const durationData = localStorage.getItem("duration");
// Check if the durationData exists
if (!durationData) {
throw new Error("Duration data not found in localStorage.");
}

// Check if the durationData exists
if (!durationData) {
throw new Error("Duration data not found in localStorage.");
}
const {
contentLoadStartTime,
micStartTime,
micStopTime,
retryCount,
} = JSON.parse(durationData);

// Check if any of the required values are missing or invalid
if (
!contentLoadStartTime ||
!micStartTime ||
!micStopTime ||
retryCount === undefined
) {
throw new Error("Incomplete or invalid duration data.");
}

const { contentLoadStartTime, micStartTime, micStopTime, retryCount } =
JSON.parse(durationData);

// Check if any of the required values are missing or invalid
if (
!contentLoadStartTime ||
!micStartTime ||
!micStopTime ||
retryCount === undefined
) {
throw new Error("Incomplete or invalid duration data.");
}
const loadStart = parseInt(contentLoadStartTime);
const micStart = parseInt(micStartTime);
const micStop = parseInt(micStopTime);

const loadToMicStartDuration = (micStart - loadStart) / 1000; // in seconds
const micDuration = (micStop - micStart) / 1000; // in seconds

const { data: updateLearnerData } = await axios.post(
`${process.env.REACT_APP_LEARNER_AI_APP_HOST}/${config.URLS.UPDATE_LEARNER_PROFILE}/${lang}`,
{
original_text: originalText,
audio: base64Data,
user_id: virtualId,
session_id: sessionId,
language: lang,
date: new Date(),
sub_session_id,
contentId,
contentType,
practice_duration: parseFloat(loadToMicStartDuration.toFixed(2)),
read_duration: parseFloat(micDuration.toFixed(2)),
retry_count: parseInt(retryCount),
}
);

const loadStart = parseInt(contentLoadStartTime);
const micStart = parseInt(micStartTime);
const micStop = parseInt(micStopTime);

const loadToMicStartDuration = (micStart - loadStart) / 1000; // in seconds
const micDuration = (micStop - micStart) / 1000; // in seconds

const { data: updateLearnerData } = await axios.post(
`${process.env.REACT_APP_LEARNER_AI_APP_HOST}/${config.URLS.UPDATE_LEARNER_PROFILE}/${lang}`,
{
original_text: originalText,
audio: base64Data,
user_id: virtualId,
session_id: sessionId,
language: lang,
date: new Date(),
sub_session_id,
contentId,
contentType,
practice_duration: parseFloat(loadToMicStartDuration.toFixed(2)),
read_duration: parseFloat(micDuration.toFixed(2)),
retry_count: parseInt(retryCount),
data = updateLearnerData;
responseText = data.responseText;
profanityWord = await filterBadWords(data.responseText, lang);
if (profanityWord !== data.responseText) {
props?.setOpenMessageDialog({
message: "Please avoid using inappropriate language.",
isError: true,
});
}
);

data = updateLearnerData;
responseText = data.responseText;
profanityWord = await filterBadWords(data.responseText, lang);
if (profanityWord !== data.responseText) {
props?.setOpenMessageDialog({
message: "Please avoid using inappropriate language.",
isError: true,
});
}

newThresholdPercentage = data?.subsessionTargetsCount || 0;
newThresholdPercentage = data?.subsessionTargetsCount || 0;

if (contentType.toLowerCase() !== "word") {
handlePercentageForLife(
newThresholdPercentage,
contentType,
data?.subsessionFluency,
lang
if (contentType.toLowerCase() !== "word") {
handlePercentageForLife(
newThresholdPercentage,
contentType,
data?.subsessionFluency,
lang
);
}
} catch (error) {
console.error(
"Error retrieving duration data or updating learner profile:",
error
);
}
} catch (error) {
console.error(
"Error retrieving duration data or updating learner profile:",
error
);
}

const responseEndTime = new Date().getTime();
Expand Down

0 comments on commit 3ce8cb9

Please sign in to comment.