Skip to content
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

Release 1.3 apicall optimisation #240

Merged
merged 7 commits into from
Jan 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/all-dev-tn-new.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: ALL new tn dev Deployment
on:
push:
branches:
- all-1.3-tn-dev-hotfix
- all-1.3-feedback-change

jobs:
deploy:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/all-dev-tn.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: ALL tn dev Deployment
on:
push:
branches:
- all-1.2-tn-dev
- release-1.3-apicall-optimisation

jobs:
deploy:
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ lerna-debug.log*
.env
#build
build

*.env*
# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

Expand Down
16 changes: 15 additions & 1 deletion src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import FingerprintJS from "@fingerprintjs/fingerprintjs";
import routes from "./routes";
import { AppContent } from "./views";
import theme from "./assets/styles/theme";
import { initialize } from "./services/telementryService";
import { initialize, end } from "./services/telementryService";
import { startEvent } from "./services/callTelemetryIntract";
import "@project-sunbird/telemetry-sdk/index.js";
import { getParameter } from "./utils/constants";
Expand Down Expand Up @@ -72,6 +72,20 @@ const App = () => {
setFp();
}, []);

useEffect(() => {
const handleBeforeUnload = (event) => {
window.telemetry && window.telemetry.syncEvents && window.telemetry.syncEvents();
};

// Add the event listener
window.addEventListener("beforeunload", handleBeforeUnload);

// Cleanup the event listener on component unmount
return () => {
window.removeEventListener("beforeunload", handleBeforeUnload);
};
}, []);

useEffect(() => {
let virtualId;

Expand Down
12 changes: 7 additions & 5 deletions src/components/Assesment/Assesment.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -598,10 +598,12 @@ const Assesment = ({ discoverStart }) => {
}

localStorage.setItem("lang", lang || "ta");
const getPointersDetails = await axios.get(
`${process.env.REACT_APP_LEARNER_AI_ORCHESTRATION_HOST}/${config.URLS.GET_POINTER}/${usernameDetails?.data?.result?.virtualID}/${session_id}?language=${lang}`
);
setPoints(getPointersDetails?.data?.result?.totalLanguagePoints || 0);
if (localStorage.getItem("contentSessionId") !== null) {
const getPointersDetails = await axios.get(
`${process.env.REACT_APP_LEARNER_AI_ORCHESTRATION_HOST}/${config.URLS.GET_POINTER}/${usernameDetails?.data?.result?.virtualID}/${session_id}?language=${lang}`
);
setPoints(getPointersDetails?.data?.result?.totalLanguagePoints || 0);
}

dispatch(setVirtualId(usernameDetails?.data?.result?.virtualID));
})();
Expand Down Expand Up @@ -635,7 +637,7 @@ const Assesment = ({ discoverStart }) => {
localStorage.setItem("sessionId", sessionId);
}

if (virtualId) {
if (virtualId && localStorage.getItem("contentSessionId") !== null) {
const getPointersDetails = await axios.get(
`${process.env.REACT_APP_LEARNER_AI_ORCHESTRATION_HOST}/${config.URLS.GET_POINTER}/${virtualId}/${sessionId}?language=${lang}`
);
Expand Down
11 changes: 7 additions & 4 deletions src/components/AssesmentEnd/AssesmentEnd.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,13 @@ const AssesmentEnd = () => {
sessionId = uniqueId();
localStorage.setItem("sessionId", sessionId)
}
const getPointersDetails = await axios.get(
`${process.env.REACT_APP_LEARNER_AI_ORCHESTRATION_HOST}/${config.URLS.GET_POINTER}/${virtualId}/${sessionId}?language=${lang}`
);
setPoints(getPointersDetails?.data?.result?.totalLanguagePoints || 0);

if (localStorage.getItem("contentSessionId") !== null) {
const getPointersDetails = await axios.get(
`${process.env.REACT_APP_LEARNER_AI_ORCHESTRATION_HOST}/${config.URLS.GET_POINTER}/${virtualId}/${sessionId}?language=${lang}`
);
setPoints(getPointersDetails?.data?.result?.totalLanguagePoints || 0);
}
})();
setTimeout(() => {
setShake(false);
Expand Down
59 changes: 30 additions & 29 deletions src/components/DiscoverSentance/DiscoverSentance.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -118,35 +118,18 @@ const SpeakSentenceComponent = () => {
try {
const lang = getLocalData("lang");

if (!(localStorage.getItem("contentSessionId") !== null)) {
const pointsRes = await axios.post(
`${process.env.REACT_APP_LEARNER_AI_ORCHESTRATION_HOST}/${config.URLS.ADD_POINTER}`,
{
userId: localStorage.getItem("virtualId"),
sessionId: localStorage.getItem("sessionId"),
points: 1,
language: lang,
milestone: "m0",
}
);
setPoints(pointsRes?.data?.result?.totalLanguagePoints || 0);
} else {
send(1);
// setPoints(localStorage.getItem("currentLessonScoreCount"));
}

await axios.post(
`${process.env.REACT_APP_LEARNER_AI_ORCHESTRATION_HOST}/${config.URLS.ADD_LESSON}`,
{
userId: localStorage.getItem("virtualId"),
sessionId: localStorage.getItem("sessionId"),
milestone: `discoveryList/discovery/${currentCollectionId}`,
lesson: localStorage.getItem("storyTitle"),
progress: ((currentQuestion + 1) * 100) / questions.length,
language: lang,
milestoneLevel: "m0",
}
);
// await axios.post(
// `${process.env.REACT_APP_LEARNER_AI_ORCHESTRATION_HOST}/${config.URLS.ADD_LESSON}`,
// {
// userId: localStorage.getItem("virtualId"),
// sessionId: localStorage.getItem("sessionId"),
// milestone: `discoveryList/discovery/${currentCollectionId}`,
// lesson: localStorage.getItem("storyTitle"),
// progress: ((currentQuestion + 1) * 100) / questions.length,
// language: lang,
// milestoneLevel: "m0",
// }
// );

if (currentQuestion < questions.length - 1) {
setCurrentQuestion(currentQuestion + 1);
Expand All @@ -164,6 +147,24 @@ const SpeakSentenceComponent = () => {
language: localStorage.getItem("lang"),
}
);

if (!(localStorage.getItem("contentSessionId") !== null)) {
const pointsRes = await axios.post(
`${process.env.REACT_APP_LEARNER_AI_ORCHESTRATION_HOST}/${config.URLS.ADD_POINTER}`,
{
userId: localStorage.getItem("virtualId"),
sessionId: localStorage.getItem("sessionId"),
points: 1,
language: lang,
milestone: "m0",
}
);
setPoints(pointsRes?.data?.result?.totalLanguagePoints || 0);
} else {
send(5);
// setPoints(localStorage.getItem("currentLessonScoreCount"));
}

setInitialAssesment(false);
const { data: getSetData } = getSetResultRes;
const data = JSON.stringify(getSetData?.data);
Expand Down
27 changes: 18 additions & 9 deletions src/services/telementryService.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { CsTelemetryModule } from '@project-sunbird/client-services/telemetry';
import { uniqueId } from './utilService';
import { jwtDecode } from '../../node_modules/jwt-decode/build/cjs/index';

let startTime; // Variable to store the timestamp when the start event is raised
let contentSessionId;
let playSessionId;
let url;
Expand Down Expand Up @@ -65,6 +66,7 @@ export const initialize = async ({ context, config, metadata }) => {

export const start = (duration) => {
try {
startTime = Date.now(); // Record the start time
CsTelemetryModule.instance.telemetryService.raiseStartTelemetry({
options: getEventOptions(),
edata: {
Expand Down Expand Up @@ -114,15 +116,22 @@ export const Log = (context, pageid, telemetryMode) => {
};

export const end = (data) => {
CsTelemetryModule.instance.telemetryService.raiseEndTelemetry({
edata: {
type: 'content',
mode: 'play',
pageid: url,
summary: data?.summary || {},
duration: data?.duration || '000',
},
});
try {
const endTime = Date.now(); // Record the end time
const duration = ((endTime - startTime) / 1000).toFixed(2); // Calculate duration in seconds

CsTelemetryModule.instance.telemetryService.raiseEndTelemetry({
edata: {
type: 'content',
mode: 'play',
pageid: url,
summary: data?.summary || {},
duration: duration, // Log the calculated duration
},
});
} catch (error) {
console.error("Error in end telemetry event:", error);
}
};

export const interact = (telemetryMode) => {
Expand Down
102 changes: 65 additions & 37 deletions src/views/Practice/Practice.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,32 @@ const Practice = () => {
}
}, [startShowCase]);

const [audioSrc, setAudioSrc] = useState(null);

useEffect(() => {
const preloadAudio = async () => {
try {
const response = await fetch(LevelCompleteAudio);
const audioBlob = await response.blob();
const audioUrl = URL.createObjectURL(audioBlob);
setAudioSrc(audioUrl);
} catch (error) {
console.error("Error loading audio:", error);
}
};
preloadAudio();
}, []);

const callConfettiAndPlay = () => {
let audio = new Audio(LevelCompleteAudio);
audio.play();
if (audioSrc) {
// Play preloaded audio if available
const audio = new Audio(audioSrc);
audio.play();
} else {
// Fallback to LevelCompleteAudio if preloaded audio is not available
const fallbackAudio = new Audio(LevelCompleteAudio);
fallbackAudio.play();
}
callConfetti();
};

Expand Down Expand Up @@ -154,24 +177,6 @@ const Practice = () => {

try {
const lang = getLocalData("lang");
if (localStorage.getItem("contentSessionId") !== null) {
setPoints(1);
if (isShowCase) {
send(1);
}
} else {
const pointsRes = await axios.post(
`${process.env.REACT_APP_LEARNER_AI_ORCHESTRATION_HOST}/${config.URLS.ADD_POINTER}`,
{
userId: localStorage.getItem("virtualId"),
sessionId: localStorage.getItem("sessionId"),
points: 1,
language: lang,
milestone: `m${level}`,
}
);
setPoints(pointsRes?.data?.result?.totalLanguagePoints || 0);
}

const virtualId = getLocalData("virtualId");
const sessionId = getLocalData("sessionId");
Expand All @@ -194,18 +199,18 @@ const Practice = () => {

let showcasePercentage = ((currentQuestion + 1) * 100) / questions.length;

await axios.post(
`${process.env.REACT_APP_LEARNER_AI_ORCHESTRATION_HOST}/${config.URLS.ADD_LESSON}`,
{
userId: virtualId,
sessionId: sessionId,
milestone: isShowCase ? "showcase" : `practice`,
lesson: currentPracticeStep,
progress: isShowCase ? showcasePercentage : currentPracticeProgress,
language: lang,
milestoneLevel: `m${level}`,
}
);
// await axios.post(
// `${process.env.REACT_APP_LEARNER_AI_ORCHESTRATION_HOST}/${config.URLS.ADD_LESSON}`,
// {
// userId: virtualId,
// sessionId: sessionId,
// milestone: isShowCase ? "showcase" : `practice`,
// lesson: currentPracticeStep,
// progress: isShowCase ? showcasePercentage : currentPracticeProgress,
// language: lang,
// milestoneLevel: `m${level}`,
// }
// );

let newPracticeStep =
currentQuestion === questions.length - 1 || isGameOver
Expand All @@ -226,6 +231,27 @@ const Practice = () => {
let currentPracticeStep =
practiceProgress[virtualId].currentPracticeStep;
let isShowCase = currentPracticeStep === 4 || currentPracticeStep === 9; // P4 or P8

// Set points
if (localStorage.getItem("contentSessionId") !== null) {
setPoints(1);
if (isShowCase) {
send(5);
}
} else {
const pointsRes = await axios.post(
`${process.env.REACT_APP_LEARNER_AI_ORCHESTRATION_HOST}/${config.URLS.ADD_POINTER}`,
{
userId: localStorage.getItem("virtualId"),
sessionId: localStorage.getItem("sessionId"),
points: 1,
language: lang,
milestone: `m${level}`,
}
);
setPoints(pointsRes?.data?.result?.totalLanguagePoints || 0);
}

if (isShowCase || isGameOver) {
// assesment

Expand Down Expand Up @@ -448,12 +474,14 @@ const Practice = () => {

// TODO: Handle Error for lessons - no lesson progress - starting point should be P1

const getPointersDetails = await axios.get(
`${process.env.REACT_APP_LEARNER_AI_ORCHESTRATION_HOST}/${config.URLS.GET_POINTER}/${virtualId}/${sessionId}?language=${lang}`
);
if (localStorage.getItem("contentSessionId") !== null) {
const getPointersDetails = await axios.get(
`${process.env.REACT_APP_LEARNER_AI_ORCHESTRATION_HOST}/${config.URLS.GET_POINTER}/${virtualId}/${sessionId}?language=${lang}`
);

// TODO: Just Opss icon - we are trying to fetch the score for you
setPoints(getPointersDetails?.data?.result?.totalLanguagePoints || 0);
// TODO: Just Opss icon - we are trying to fetch the score for you
setPoints(getPointersDetails?.data?.result?.totalLanguagePoints || 0);
}

let userState = Number.isInteger(
Number(resLessons.data?.result?.result?.lesson)
Expand Down
Loading