From e1446427757192bd41646819bcac420ec1659c92 Mon Sep 17 00:00:00 2001 From: Ajinkya Pande Date: Tue, 7 Jan 2025 17:27:17 +0530 Subject: [PATCH 1/2] Issueid #232285 fix: Jumble the word - Invalid content displays.PFA --- src/components/Practice/Mechanics4.jsx | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/components/Practice/Mechanics4.jsx b/src/components/Practice/Mechanics4.jsx index 8b4fd785..a6cecb98 100644 --- a/src/components/Practice/Mechanics4.jsx +++ b/src/components/Practice/Mechanics4.jsx @@ -215,8 +215,9 @@ const Mechanics4 = ({ paddingX: type === "word" ? 0 : "20px", }} > - {selectedWords?.map((elem) => ( + {selectedWords?.map((elem, ind) => ( handleWords(elem, true)} className={ answer === "wrong" @@ -267,8 +268,8 @@ const Mechanics4 = ({ mb: 3, }} > - {words?.map((elem) => ( - + {words?.map((elem, ind) => ( + {type === "word" ? ( handleWords(elem)} From 4ad8b8e117952fdf04d76bee9fdf0d31102c26a3 Mon Sep 17 00:00:00 2001 From: Ajinkya Pande Date: Wed, 8 Jan 2025 15:56:43 +0530 Subject: [PATCH 2/2] issueid #232952 feat: passing virtual id to telemetry and mechanic id to updatelearnerprofile api --- src/services/telementryService.js | 369 ++++++++++++++++-------------- src/utils/VoiceAnalyser.js | 1 + src/views/Practice/Practice.jsx | 11 +- 3 files changed, 204 insertions(+), 177 deletions(-) diff --git a/src/services/telementryService.js b/src/services/telementryService.js index c946756a..8eccfd10 100644 --- a/src/services/telementryService.js +++ b/src/services/telementryService.js @@ -1,7 +1,7 @@ -import { CsTelemetryModule } from '@project-sunbird/client-services/telemetry'; +import { CsTelemetryModule } from "@project-sunbird/client-services/telemetry"; -import { uniqueId } from './utilService'; -import { jwtDecode } from '../../node_modules/jwt-decode/build/cjs/index'; +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; @@ -9,88 +9,91 @@ let playSessionId; let url; let isBuddyLogin = checkTokenInLocalStorage(); -if (localStorage.getItem('token') !== null) { - let jwtToken = localStorage.getItem('token'); - let userDetails = jwtDecode(jwtToken); +if (localStorage.getItem("token") !== null) { + let jwtToken = localStorage.getItem("token"); + let userDetails = jwtDecode(jwtToken); } function checkTokenInLocalStorage() { - const token = localStorage.getItem('buddyToken'); - return !!token; // Returns true if token is present, false if token is null or undefined + const token = localStorage.getItem("buddyToken"); + return !!token; // Returns true if token is present, false if token is null or undefined } -if (localStorage.getItem('contentSessionId') !== null) { - contentSessionId = localStorage.getItem('contentSessionId'); +if (localStorage.getItem("contentSessionId") !== null) { + contentSessionId = localStorage.getItem("contentSessionId"); } else { - contentSessionId = localStorage.getItem('virtualStorySessionID') || uniqueId(); - localStorage.setItem('allAppContentSessionId', contentSessionId); + contentSessionId = + localStorage.getItem("virtualStorySessionID") || uniqueId(); + localStorage.setItem("allAppContentSessionId", contentSessionId); } let getUrl = window.location.href; -url = getUrl && getUrl.includes('#') && getUrl.split('#')[1].split('/')[1]; +url = getUrl && getUrl.includes("#") && getUrl.split("#")[1].split("/")[1]; export const initialize = async ({ context, config, metadata }) => { - playSessionId = uniqueId(); - if (!CsTelemetryModule.instance.isInitialised) { - await CsTelemetryModule.instance.init({}); - const telemetryConfig = { - config: { - pdata: context.pdata, - env: '', - channel: context.channel, - did: context.did, - authtoken: context.authToken || '', - uid: 'anonymous', - sid: context.sid, - batchsize: process.env.REACT_APP_BATCHSIZE, - mode: context.mode, - host: context.host, - apislug: context.apislug, - endpoint: context.endpoint, - tags: context.tags, - cdata: [ - { id: contentSessionId, type: 'ContentSession' }, - { id: playSessionId, type: 'PlaySession' }, - ], - }, - userOrgDetails: {}, - }; - - try { - await CsTelemetryModule.instance.telemetryService.initTelemetry(telemetryConfig); - } catch (error) { - console.log(':e', error); - } - } -}; + playSessionId = uniqueId(); + if (!CsTelemetryModule.instance.isInitialised) { + await CsTelemetryModule.instance.init({}); + const telemetryConfig = { + config: { + pdata: context.pdata, + env: "", + channel: context.channel, + did: context.did, + authtoken: context.authToken || "", + uid: "anonymous", + sid: context.sid, + batchsize: process.env.REACT_APP_BATCHSIZE, + mode: context.mode, + host: context.host, + apislug: context.apislug, + endpoint: context.endpoint, + tags: context.tags, + cdata: [ + { id: contentSessionId, type: "ContentSession" }, + { id: playSessionId, type: "PlaySession" }, + ], + }, + userOrgDetails: {}, + }; -export const start = (duration) => { try { - startTime = Date.now(); // Record the start time - CsTelemetryModule.instance.telemetryService.raiseStartTelemetry({ - options: getEventOptions(), - edata: { - type: 'content', - mode: 'play', - stageid: url, - duration: Number((duration / 1e3).toFixed(2)), - dspec: window.navigator.userAgent - }, - }); + await CsTelemetryModule.instance.telemetryService.initTelemetry( + telemetryConfig + ); } catch (error) { - console.log('err', error); + console.log(":e", error); } + } +}; + +export const start = (duration) => { + try { + startTime = Date.now(); // Record the start time + CsTelemetryModule.instance.telemetryService.raiseStartTelemetry({ + options: getEventOptions(), + edata: { + type: "content", + mode: "play", + stageid: url, + duration: Number((duration / 1e3).toFixed(2)), + dspec: window.navigator.userAgent, + }, + }); + } catch (error) { + console.log("err", error); + } }; export const response = (context, telemetryMode) => { - if (checkTelemetryMode(telemetryMode)) { - CsTelemetryModule.instance.telemetryService.raiseResponseTelemetry( - { - ...context, - }, - getEventOptions(), - ); - } + if (checkTelemetryMode(telemetryMode)) { + CsTelemetryModule.instance.telemetryService.raiseResponseTelemetry( + { + ...context, + }, + getEventOptions() + ); + } }; export const Log = (context, pageid, telemetryMode) => { @@ -116,137 +119,153 @@ export const Log = (context, pageid, telemetryMode) => { }; export const end = (data) => { - 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); - } + 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) => { - if (checkTelemetryMode(telemetryMode)) { - CsTelemetryModule.instance.telemetryService.raiseInteractTelemetry({ - options: getEventOptions(), - edata: { type: 'TOUCH', subtype: '', pageid: url }, - }); - } + if (checkTelemetryMode(telemetryMode)) { + CsTelemetryModule.instance.telemetryService.raiseInteractTelemetry({ + options: getEventOptions(), + edata: { type: "TOUCH", subtype: "", pageid: url }, + }); + } }; export const search = (id) => { - CsTelemetryModule.instance.telemetryService.raiseSearchTelemetry({ - options: getEventOptions(), - edata: { - // Required - type: 'content', // Required. content, assessment, asset - query: id, // Required. Search query string - filters: {}, // Optional. Additional filters - sort: {}, // Optional. Additional sort parameters - correlationid: '', // Optional. Server generated correlation id (for mobile app's telemetry) - size: 0, // Required. Number of search results - topn: [{}], // Required. top N (configurable) results with their score - }, - }); + CsTelemetryModule.instance.telemetryService.raiseSearchTelemetry({ + options: getEventOptions(), + edata: { + // Required + type: "content", // Required. content, assessment, asset + query: id, // Required. Search query string + filters: {}, // Optional. Additional filters + sort: {}, // Optional. Additional sort parameters + correlationid: "", // Optional. Server generated correlation id (for mobile app's telemetry) + size: 0, // Required. Number of search results + topn: [{}], // Required. top N (configurable) results with their score + }, + }); }; export const impression = (currentPage, telemetryMode) => { - if (checkTelemetryMode(telemetryMode)) { - CsTelemetryModule.instance.telemetryService.raiseImpressionTelemetry({ - options: getEventOptions(), - edata: { type: 'workflow', subtype: '', pageid: currentPage + '', uri: '' }, - }); - } + if (checkTelemetryMode(telemetryMode)) { + CsTelemetryModule.instance.telemetryService.raiseImpressionTelemetry({ + options: getEventOptions(), + edata: { + type: "workflow", + subtype: "", + pageid: currentPage + "", + uri: "", + }, + }); + } }; export const error = (error, data, telemetryMode) => { - if (checkTelemetryMode(telemetryMode)) { - CsTelemetryModule.instance.telemetryService.raiseErrorTelemetry({ - options: getEventOptions(), - edata: { - pageid: url, - err: data.err, - errtype: data.errtype, - stacktrace: error.toString() || '', - }, - }); - } + if (checkTelemetryMode(telemetryMode)) { + CsTelemetryModule.instance.telemetryService.raiseErrorTelemetry({ + options: getEventOptions(), + edata: { + pageid: url, + err: data.err, + errtype: data.errtype, + stacktrace: error.toString() || "", + }, + }); + } }; export const feedback = (data, contentId, telemetryMode) => { - if (checkTelemetryMode(telemetryMode)) { - CsTelemetryModule.instance.telemetryService.raiseFeedBackTelemetry({ - options: getEventOptions(), - edata: { - contentId: contentId, - rating: data, - comments: '', - }, - }); - } + if (checkTelemetryMode(telemetryMode)) { + CsTelemetryModule.instance.telemetryService.raiseFeedBackTelemetry({ + options: getEventOptions(), + edata: { + contentId: contentId, + rating: data, + comments: "", + }, + }); + } }; function checkTelemetryMode(currentMode) { - return ( - (process.env.REACT_APP_TELEMETRY_MODE === 'ET' && currentMode === 'ET') || - (process.env.REACT_APP_TELEMETRY_MODE === 'NT' && (currentMode === 'ET' || currentMode === 'NT')) || - (process.env.REACT_APP_TELEMETRY_MODE === 'DT' && - (currentMode === 'ET' || currentMode === 'NT' || currentMode === 'DT')) - ); + return ( + (process.env.REACT_APP_TELEMETRY_MODE === "ET" && currentMode === "ET") || + (process.env.REACT_APP_TELEMETRY_MODE === "NT" && + (currentMode === "ET" || currentMode === "NT")) || + (process.env.REACT_APP_TELEMETRY_MODE === "DT" && + (currentMode === "ET" || currentMode === "NT" || currentMode === "DT")) + ); } export const getEventOptions = () => { - var emis_username = 'anonymous'; - var buddyUserId = ''; + var emis_username = "anonymous"; + var buddyUserId = ""; - if (localStorage.getItem('token') !== null) { - let jwtToken = localStorage.getItem('token'); - var userDetails = jwtDecode(jwtToken); - emis_username = userDetails.emis_username; - } + if (localStorage.getItem("token") !== null) { + let jwtToken = localStorage.getItem("token"); + var userDetails = jwtDecode(jwtToken); + emis_username = userDetails.emis_username; + } - if (isBuddyLogin) { - let jwtToken = localStorage.getItem('buddyToken'); - let buddyUserDetails = jwtDecode(jwtToken); - buddyUserId = buddyUserDetails.emis_username; - } + if (isBuddyLogin) { + let jwtToken = localStorage.getItem("buddyToken"); + let buddyUserDetails = jwtDecode(jwtToken); + buddyUserId = buddyUserDetails.emis_username; + } - const userType = isBuddyLogin ? 'Buddy User' : 'User'; - const userId = isBuddyLogin ? emis_username + '/' + buddyUserId : emis_username || 'anonymous'; - - return { - object: {}, - context: { - pdata: { - // optional - id: process.env.REACT_APP_ID, // Producer ID. For ex: For sunbird it would be "portal" or "genie" - ver: process.env.REACT_APP_VER, // Version of the App - pid: process.env.REACT_APP_PID, // Optional. In case the component is distributed, then which instance of that component - }, - env: process.env.REACT_APP_ENV, - uid: `${isBuddyLogin ? emis_username + '/' + buddyUserId : emis_username || 'anonymous'}`, - cdata: [ - { id: localStorage.getItem('virtualStorySessionID') || contentSessionId, type: 'ContentSession' }, - { id: playSessionId, type: 'PlaySession' }, - { id: userId, type: userType }, - { id: localStorage.getItem("lang") || 'ta', type: 'language' }, - { id: userDetails?.school_name, type: 'school_name' }, - { - id: userDetails?.class_studying_id, - type: 'class_studying_id', - }, - { id: userDetails?.udise_code, type: 'udise_code' }, - ], - rollup: {}, + const userType = isBuddyLogin ? "Buddy User" : "User"; + const userId = isBuddyLogin + ? emis_username + "/" + buddyUserId + : emis_username || "anonymous"; + + return { + object: {}, + context: { + pdata: { + // optional + id: process.env.REACT_APP_ID, // Producer ID. For ex: For sunbird it would be "portal" or "genie" + ver: process.env.REACT_APP_VER, // Version of the App + pid: process.env.REACT_APP_PID, // Optional. In case the component is distributed, then which instance of that component + }, + env: process.env.REACT_APP_ENV, + uid: `${ + isBuddyLogin + ? emis_username + "/" + buddyUserId + : emis_username || "anonymous" + }`, + cdata: [ + { + id: localStorage.getItem("virtualStorySessionID") || contentSessionId, + type: "ContentSession", }, - }; + { id: playSessionId, type: "PlaySession" }, + { id: userId, type: userType }, + { id: localStorage.getItem("lang") || "ta", type: "language" }, + { id: userDetails?.school_name, type: "school_name" }, + { + id: userDetails?.class_studying_id, + type: "class_studying_id", + }, + { id: userDetails?.udise_code, type: "udise_code" }, + { id: localStorage.getItem("virtualId") || null, type: "virtualId" }, + ], + rollup: {}, + }, + }; }; diff --git a/src/utils/VoiceAnalyser.js b/src/utils/VoiceAnalyser.js index 3639cec2..99f2163d 100644 --- a/src/utils/VoiceAnalyser.js +++ b/src/utils/VoiceAnalyser.js @@ -362,6 +362,7 @@ function VoiceAnalyser(props) { sub_session_id, contentId, contentType, + mechanics_id: localStorage.getItem("mechanism_id") || "", }; if (props.selectedOption) { diff --git a/src/views/Practice/Practice.jsx b/src/views/Practice/Practice.jsx index e78f2234..49c1c8e6 100644 --- a/src/views/Practice/Practice.jsx +++ b/src/views/Practice/Practice.jsx @@ -232,7 +232,7 @@ const Practice = () => { ); setPoints(pointsRes?.data?.result?.totalLanguagePoints || 0); } - + if (isShowCase || isGameOver) { // assesment @@ -455,7 +455,10 @@ const Practice = () => { // TODO: Handle Error for lessons - no lesson progress - starting point should be P1 - if (process.env.REACT_APP_IS_APP_IFRAME !== "true" && localStorage.getItem("contentSessionId") !== null) { + if ( + process.env.REACT_APP_IS_APP_IFRAME !== "true" && + 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}` ); @@ -560,6 +563,10 @@ const Practice = () => { // } // }, [state]); + useEffect(() => { + localStorage.setItem("mechanism_id", (mechanism && mechanism.id) || ""); + }, [mechanism]); + const handleBack = async () => { if (progressData.currentPracticeStep > 0) { const virtualId = getLocalData("virtualId");