Skip to content

Commit

Permalink
Merge pull request #40 from ajinkyapandetekdi/telemetry-feedback
Browse files Browse the repository at this point in the history
Telemetry feedback
  • Loading branch information
gouravmore authored Jul 20, 2023
2 parents c32a83f + 3461028 commit c00be03
Show file tree
Hide file tree
Showing 7 changed files with 182 additions and 66 deletions.
4 changes: 4 additions & 0 deletions src/assests/Images/Thumbs_Down.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions src/assests/Images/Thumbs_up.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
70 changes: 41 additions & 29 deletions src/services/telementryService.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import React from 'react';
import { generateUUID, uniqueId } from './utilService';
import { CsTelemetryModule } from '@project-sunbird/client-services/telemetry';
import jwt from 'jwt-decode'

import jwt from 'jwt-decode';

var contentSessionId;
let playSessionId;
let url
let url;
let config;
if (localStorage.getItem('token') !== null) {
let jwtToken = localStorage.getItem('token');
Expand All @@ -21,7 +20,7 @@ if (localStorage.getItem('contentSessionId') !== null) {
}

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 = ({ context, config, metadata }) => {
context = context;
Expand All @@ -32,20 +31,22 @@ export const initialize = ({ context, config, metadata }) => {
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' }]
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: {},
};
Expand All @@ -54,8 +55,7 @@ export const initialize = ({ context, config, metadata }) => {
}
};

export const start = (duration) => {

export const start = duration => {
CsTelemetryModule.instance.telemetryService.raiseStartTelemetry({
options: getEventOptions(),
edata: {
Expand All @@ -68,10 +68,11 @@ export const start = (duration) => {
};

export const response = (context, options) => {
CsTelemetryModule.instance.telemetryService.raiseResponseTelemetry({
...context,
},
getEventOptions()
CsTelemetryModule.instance.telemetryService.raiseResponseTelemetry(
{
...context,
},
getEventOptions()
);
};

Expand All @@ -87,10 +88,10 @@ export const end = () => {
});
};

export const interact = (id) => {
export const interact = id => {
CsTelemetryModule.instance.telemetryService.raiseInteractTelemetry({
options: getEventOptions(),
edata: { type: 'TOUCH', subtype: '', id, pageid:url },
edata: { type: 'TOUCH', subtype: '', id, pageid: url },
});
console.log('working');
};
Expand Down Expand Up @@ -129,8 +130,19 @@ export const error = (error, data) => {
});
};

export const feedback = (data, contentId) => {
CsTelemetryModule.instance.telemetryService.raiseFeedBackTelemetry({
options: getEventOptions(),
edata: {
contentId: contentId,
rating: data,
comments: '',
},
});
};

export const getEventOptions = () => {
var emis_username = 'anonymous'
var emis_username = 'anonymous';
if (localStorage.getItem('token') !== null) {
let jwtToken = localStorage.getItem('token');
var userDetails = jwt(jwtToken);
Expand All @@ -139,14 +151,14 @@ export const getEventOptions = () => {
return {
object: {},
context: {
pdata:{
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: emis_username || "anonymous",
uid: emis_username || 'anonymous',
cdata: [
{ id: contentSessionId, type: 'ContentSession' },
{ id: playSessionId, type: 'PlaySession' },
Expand Down
59 changes: 41 additions & 18 deletions src/views/Score/Score.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import React, { useState, useEffect, createRef } from 'react';
import { useParams, useNavigate, Link } from 'react-router-dom';
import ReactAudioPlayer from 'react-audio-player';
import AudioPlayer from 'react-h5-audio-player';

import Thumbs_up from '../../assests/Images/Thumbs_up.svg';
import Thumbs_Down from '../../assests/Images/Thumbs_Down.svg';
import AppNavbar from '../../components/AppNavbar/AppNavbar';
import NewTopHomeNextBar from '../../components/NewTopHomeNextBar/NewTopHomeNextBar';
import NewBottomHomeNextBar from '../../components/NewBottomHomeNextBar/NewBottomHomeNextBar';
Expand All @@ -21,7 +22,7 @@ import { scroll_to_top } from '../../utils/Helper/JSHelper';
import play from '../../assests/Images/play-img.png';

import pause from '../../assests/Images/pause-img.png';

import { feedback } from '../../services/telementryService';
import next from '../../assests/Images/next.png';

import { replaceAll } from '../../utils/helper';
Expand Down Expand Up @@ -126,7 +127,6 @@ function Score() {
}, [voiceText]);

function handleScore() {

let voiceTextNoSymbol = replaceAll(voiceText, '?', '');
voiceTextNoSymbol = replaceAll(voiceTextNoSymbol, "'", '');
voiceTextNoSymbol = replaceAll(voiceTextNoSymbol, '.', '');
Expand All @@ -136,14 +136,13 @@ function Score() {
voiceTextNoSymbol = replaceAll(voiceTextNoSymbol, '!', '');
let tempVoiceText = voiceTextNoSymbol.toLowerCase().split(' ');


let teacherTextNoSymbol = replaceAll(teacherText, '?', '');
teacherTextNoSymbol = replaceAll(teacherTextNoSymbol, "'", '');
teacherTextNoSymbol = replaceAll(teacherTextNoSymbol, '.', '');
teacherTextNoSymbol = replaceAll(teacherTextNoSymbol, '’', '');
teacherTextNoSymbol = replaceAll(teacherTextNoSymbol, '|', '');
teacherTextNoSymbol = replaceAll(teacherTextNoSymbol, ',', '');
teacherTextNoSymbol = replaceAll(teacherTextNoSymbol, '!', '');
let teacherTextNoSymbol = replaceAll(teacherText, '?', '');
teacherTextNoSymbol = replaceAll(teacherTextNoSymbol, "'", '');
teacherTextNoSymbol = replaceAll(teacherTextNoSymbol, '.', '');
teacherTextNoSymbol = replaceAll(teacherTextNoSymbol, '’', '');
teacherTextNoSymbol = replaceAll(teacherTextNoSymbol, '|', '');
teacherTextNoSymbol = replaceAll(teacherTextNoSymbol, ',', '');
teacherTextNoSymbol = replaceAll(teacherTextNoSymbol, '!', '');
let tempVoiceTeacher = teacherTextNoSymbol.toLowerCase().split(' ');

let rightWords = 0;
Expand All @@ -154,9 +153,7 @@ function Score() {
myLength = tempVoiceText.length;
}
for (let i = 0; i < myLength; i++) {
// console.log(i);
if (tempVoiceText[i] === tempVoiceTeacher[i]) {
// console.log(i);
rightWords++;
}
}
Expand Down Expand Up @@ -230,6 +227,7 @@ function Score() {
</>
);
}

else if(teacherTextArray.includes(studentTextArray[i])){
student_text_result.push(
<>
Expand All @@ -239,6 +237,7 @@ function Score() {
</>
);
}

else {
wrong_words++;
student_text_result.push(
Expand Down Expand Up @@ -312,11 +311,35 @@ function Score() {
<div className="col s12 m8 l6 main_layout">
{/*<AppNavbar navtitle="Result" />*/}
<br />
<div style={{ display: 'flex' }}>
<NewTopHomeNextBar
nextlink={resultnext}
resultnextlang={resultnextlang}
ishomeback={true}
/>
nextlink={resultnext}
resultnextlang={resultnextlang}
ishomeback={true}
/>
<div
style={{
position: 'absolute',
right: '30%',
marginTop: '10px',
padding: '5px',
cursor:'pointer'
}}
>
<img
style={{ marginRight: '15px' }}
onClick={() => feedback(1, teacherText)}
src={Thumbs_up}
alt="thumbs-up"
/>
<img
onClick={() => feedback(-1, teacherText)}
src={Thumbs_Down}
alt="thumbs-down"
/>
</div>
</div>

<div>
<center>
{testResult}
Expand Down Expand Up @@ -588,4 +611,4 @@ function Score() {
);
}

export default Score;
export default Score;
41 changes: 32 additions & 9 deletions src/viewsProto2/Score/Score.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import React, { useState, useEffect, createRef } from 'react';
import { useParams, useNavigate, Link } from 'react-router-dom';
import ReactAudioPlayer from 'react-audio-player';
import AudioPlayer from 'react-h5-audio-player';

import Thumbs_up from '../../assests/Images/Thumbs_up.svg';
import Thumbs_Down from '../../assests/Images/Thumbs_Down.svg';
import AppNavbar from '../../components/AppNavbar/AppNavbar';
import NewTopHomeNextBar from '../../components2/NewTopHomeNextBar/NewTopHomeNextBar';
import NewBottomHomeNextBar from '../../components2/NewBottomHomeNextBar/NewBottomHomeNextBar';
Expand All @@ -15,17 +16,15 @@ import 'react-h5-audio-player/lib/styles.css';
import VoiceCompair from '../../components/VoiceCompair/VoiceCompair';
import refresh from '../../assests/Images/refresh.png';
import Animation from '../../components/Animation/Animation';

import { scroll_to_top } from '../../utils/Helper/JSHelper';

import play from '../../assests/Images/play-img.png';

import pause from '../../assests/Images/pause-img.png';

import next from '../../assests/Images/next.png';

/*chakra*/
import AppFooter from '../../components2/AppFooter/AppFooter';
import { feedback } from '../../services/telementryService';

function Score() {
const navigate = useNavigate();
Expand Down Expand Up @@ -324,11 +323,35 @@ function Score() {
<div className="col s12 m8 l6 main_layout">
{/*<AppNavbar navtitle="Result" />*/}
<br />
<NewTopHomeNextBar
nextlink={resultnext}
resultnextlang={resultnextlang}
ishomeback={true}
/>
<div style={{ display: 'flex' }}>
<NewTopHomeNextBar
nextlink={resultnext}
resultnextlang={resultnextlang}
ishomeback={true}
/>
<div
style={{
position: 'absolute',
right: '30%',
marginTop: '10px',
padding: '5px',
cursor:'pointer'
}}
>
<img
style={{ marginRight: '15px' }}
onClick={() => feedback(1, teacherText)}
src={Thumbs_up}
alt="thumbs-up"
/>
<img
onClick={() => feedback(-1, teacherText)}
src={Thumbs_Down}
alt="thumbs-down"
/>
</div>
</div>

<div>
<center>
{/*<h5 className="home_title">Result</h5>
Expand Down
37 changes: 31 additions & 6 deletions src/viewsProto3/Score/Score.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import React, { useState, useEffect, createRef } from 'react';
import { useParams, useNavigate, Link } from 'react-router-dom';
import ReactAudioPlayer from 'react-audio-player';
import AudioPlayer from 'react-h5-audio-player';

import Thumbs_up from '../../assests/Images/Thumbs_up.svg';
import Thumbs_Down from '../../assests/Images/Thumbs_Down.svg';
import AppNavbar from '../../components/AppNavbar/AppNavbar';
// import NewTopHomeNextBar from '../../components/NewTopHomeNextBar/NewTopHomeNextBar';
import NewBottomHomeNextBar from '../../components/NewBottomHomeNextBar/NewBottomHomeNextBar';
Expand All @@ -26,6 +27,7 @@ import next from '../../assests/Images/next.png';

import { replaceAll } from '../../utils/helper';
import NewTopHomeNextBar from '../../components2/NewTopHomeNextBar/NewTopHomeNextBar';
import { feedback } from '../../services/telementryService';

function Score() {
const navigate = useNavigate();
Expand Down Expand Up @@ -304,11 +306,34 @@ function Score() {
<div className="col s12 m8 l6 main_layout">
{/*<AppNavbar navtitle="Result" />*/}
<br />
<NewTopHomeNextBar
nextlink={''}
ishomeback={false}
isHideNavigation={true}
/>
<div style={{ display: 'flex' }}>
<NewTopHomeNextBar
nextlink={''}
ishomeback={false}
isHideNavigation={true}
/>
<div
style={{
position: 'absolute',
right: '30%',
marginTop: '10px',
padding: '5px',
cursor:'pointer'
}}
>
<img
style={{ marginRight: '15px' }}
onClick={() => feedback(1, teacherText)}
src={Thumbs_up}
alt="thumbs-up"
/>
<img
onClick={() => feedback(-1, teacherText)}
src={Thumbs_Down}
alt="thumbs-down"
/>
</div>
</div>
<div>
<center>
{testResult}
Expand Down
Loading

0 comments on commit c00be03

Please sign in to comment.