Merge pull request 'change drawing game star implemantetion' (#42) from newb2 into master
Reviewed-on: #42master
commit
65aa08bfb6
|
@ -116,82 +116,7 @@ function submitUserData(drawingZone) {
|
||||||
imageCode = image.src;
|
imageCode = image.src;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
let userData = {
|
|
||||||
'gameName': gameVersion,
|
|
||||||
'gameID': gameId,
|
|
||||||
'screenShot': imageCode,
|
|
||||||
'childId' : childId,
|
|
||||||
'gameTime' : timeDifferenceInSeconds
|
|
||||||
|
|
||||||
};
|
|
||||||
// console.log('userData', userData)
|
|
||||||
fetch(`https://api.teachertrainingkolkata.in/api/saveGalleryImage`, {
|
|
||||||
method: 'POST',
|
|
||||||
headers: {
|
|
||||||
'Content-Type' : 'application/json'
|
|
||||||
},
|
|
||||||
body: JSON.stringify(userData)
|
|
||||||
|
|
||||||
})
|
|
||||||
.then(response => response.json())
|
|
||||||
.then(data => {
|
|
||||||
// console.log('data from save gallery', data);
|
|
||||||
|
|
||||||
if(data.screenshotUrl){
|
|
||||||
fetch(`https://api.teachertrainingkolkata.in/api/saveGameScore2`, {
|
|
||||||
method: 'POST',
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/json'
|
|
||||||
},
|
|
||||||
body: JSON.stringify(userData)
|
|
||||||
})
|
|
||||||
.then(response => {
|
|
||||||
setTimeout(() => {
|
|
||||||
if (response.ok) {
|
|
||||||
if (response.status == 200) {
|
|
||||||
document.getElementById('saved-toast').classList.remove('hidden');
|
|
||||||
setTimeout(() => {
|
|
||||||
document.getElementById('saved-toast').classList.add('hidden');
|
|
||||||
}, 2000);
|
|
||||||
|
|
||||||
// console.log(response.status, " Data Saved Succesfully");
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// console.log('Something went wrong', response);
|
|
||||||
}
|
|
||||||
}, 100);
|
|
||||||
})
|
|
||||||
.catch(error => {
|
|
||||||
console.error('An error occurred', error);
|
|
||||||
});
|
|
||||||
const userAnotherData = {
|
|
||||||
assignmentId: assignmentId,
|
|
||||||
worksheetId: worksheetId,
|
|
||||||
studentId: childId,
|
|
||||||
submissionFile: data.screenshotUrl.split('/')[4].split('?')[0],
|
|
||||||
};
|
|
||||||
const authToken = 'Bearer eyJhbGciOiJSUzUxMiIsInR5cCI6IkpXVCJ9.eyJ1c2VyIjp7ImlkZW50aXR5SWQiOiI2NjNjNGMzNjRiNmYzZjU0YmExZjcxMTUiLCJfaWQiOiI2NjNjNGMzNjBiOWYyZDk5MGQyNWYwYjMiLCJ0eXBlIjoiQUtBREVNWSIsImRldmljZUlkIjoiMDBqNXJtODl5b3BvNjh1a2Yyb2c5cTdoIn0sImlhdCI6MTczNjM5ODkwNCwiZXhwIjoxNzM3MDAzNzA0LCJpc3MiOiJidXp6T25lIn0.vhH0zTkVisnbK6n5aPgV3RrtmpP095Gtz6ayUc29XerEV-XPVhYwg06JQnm2FWGPtadEJ2Ea5z6_YNp5Kz9DENL9LxpYYuXRUOGvMEaVM5YZOYQ88viqxM7SIvxElIsc8cQeJr5v-4ov4MyOuXws7R5MDDO2PuzYdwaA52GXbQ0LO3aFGOQL7nWPKVYqFWCQe_T-1JphbsGStHivcmUy8_DAdjs0VpXFJKiQm6jcWQO3j3uOUJSi14af4ZvrUPkjIT92OOHiZTL7CUbbFt4yktnw3Gm2Fv6lS5pamSJpVJnGJQ6ebjd70IXnE49Mn9IK9AssnjTBh2DaNeVc0C1z9Q'; // Your token
|
|
||||||
fetch(`https://preschool-curriculum.in/api/one/v1/akademy/worksheet/submissions`, {
|
|
||||||
method: 'POST',
|
|
||||||
headers: {
|
|
||||||
'Content-Type' : 'application/json',
|
|
||||||
'Authorization' : authToken
|
|
||||||
},
|
|
||||||
body: JSON.stringify(userAnotherData)
|
|
||||||
})
|
|
||||||
.then(response => response.json())
|
|
||||||
.then(data => {
|
|
||||||
// console.log('submissions api response', data)
|
|
||||||
})
|
|
||||||
.catch(error => {
|
|
||||||
console.error('An error occured', error)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch(error => {
|
|
||||||
console.error('An error occured', error);
|
|
||||||
})
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
@ -200,7 +125,6 @@ function submitUserData(drawingZone) {
|
||||||
function calculateFromAI(){
|
function calculateFromAI(){
|
||||||
let progress = 0;
|
let progress = 0;
|
||||||
let starValue;
|
let starValue;
|
||||||
let maxStarValue = 5;
|
|
||||||
|
|
||||||
function progressIncrement() {
|
function progressIncrement() {
|
||||||
const interval = setInterval(() => {
|
const interval = setInterval(() => {
|
||||||
|
@ -283,32 +207,33 @@ function submitUserData(drawingZone) {
|
||||||
calculationText.style.fontWeight = '600';
|
calculationText.style.fontWeight = '600';
|
||||||
calculationText.style.color = 'rgba(0, 0, 0, 0.38)';
|
calculationText.style.color = 'rgba(0, 0, 0, 0.38)';
|
||||||
containerDiv.appendChild(calculationText);
|
containerDiv.appendChild(calculationText);
|
||||||
let userData = {
|
let userDataForStar = {
|
||||||
gameName: gameVersion,
|
gameName: gameVersion,
|
||||||
childId: childId,
|
childId: childId,
|
||||||
gameID: gameId,
|
gameID: gameId,
|
||||||
gameTime: timeDifferenceInSeconds,
|
gameTime: timeDifferenceInSeconds,
|
||||||
screenShot: imageCode
|
screenShot: imageCode
|
||||||
};
|
};
|
||||||
// console.log(userData);
|
|
||||||
|
// First API call
|
||||||
fetch(`https://api.teachertrainingkolkata.in/api/aiEvaluateImageToStar`, {
|
fetch(`https://api.teachertrainingkolkata.in/api/aiEvaluateImageToStar`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json'
|
'Content-Type': 'application/json'
|
||||||
},
|
},
|
||||||
body: JSON.stringify(userData)
|
body: JSON.stringify(userDataForStar)
|
||||||
})
|
})
|
||||||
.then(response => {
|
.then(response => {
|
||||||
if(!response.ok){
|
if (!response.ok) {
|
||||||
throw new Error(`HTTP error! status: ${response.status}`);
|
throw new Error(`HTTP error! status: ${response.status}`);
|
||||||
}
|
}
|
||||||
return response.json()
|
return response.json();
|
||||||
})
|
})
|
||||||
.then(data => {
|
.then(data => {
|
||||||
// console.log('data', data.data.score);
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
if (data && data.message === "Game data saved successfully") {
|
if (data && data.message === "Game data saved successfully") {
|
||||||
starValue = data.data.score;
|
let starValue = data.data.gameStar; // Ensure starValue is available
|
||||||
|
|
||||||
let feedbackMessage = '';
|
let feedbackMessage = '';
|
||||||
if (starValue >= 1 && starValue <= 3) {
|
if (starValue >= 1 && starValue <= 3) {
|
||||||
feedbackMessage = "You're making progress! Let's keep going!";
|
feedbackMessage = "You're making progress! Let's keep going!";
|
||||||
|
@ -321,6 +246,7 @@ function submitUserData(drawingZone) {
|
||||||
} else {
|
} else {
|
||||||
feedbackMessage = "Invalid star value.";
|
feedbackMessage = "Invalid star value.";
|
||||||
}
|
}
|
||||||
|
|
||||||
loadingMainContainer.style.display = 'none';
|
loadingMainContainer.style.display = 'none';
|
||||||
loadingDiv.style.display = 'none';
|
loadingDiv.style.display = 'none';
|
||||||
starContainer.style.display = 'flex';
|
starContainer.style.display = 'flex';
|
||||||
|
@ -328,22 +254,92 @@ function submitUserData(drawingZone) {
|
||||||
document.getElementById('get-star-value').innerHTML = starValue;
|
document.getElementById('get-star-value').innerHTML = starValue;
|
||||||
document.getElementById('starFeedbackMessage').innerHTML = feedbackMessage;
|
document.getElementById('starFeedbackMessage').innerHTML = feedbackMessage;
|
||||||
scoreBoard.style.display = 'flex';
|
scoreBoard.style.display = 'flex';
|
||||||
|
|
||||||
if (scoreBoard.style.display === 'flex') {
|
if (scoreBoard.style.display === 'flex') {
|
||||||
const bottomAnimateClipart = document.getElementById('bottomAnimateClipart');
|
const bottomAnimateClipart = document.getElementById('bottomAnimateClipart');
|
||||||
bottomAnimateClipart.classList.remove('hidden');
|
bottomAnimateClipart.classList.remove('hidden');
|
||||||
bottomAnimateClipart.classList.add('-translate-x-full');
|
bottomAnimateClipart.classList.add('-translate-x-full', 'transition-transform', 'duration-700');
|
||||||
bottomAnimateClipart.classList.add('transition-transform', 'duration-700');
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
bottomAnimateClipart.classList.add('hidden');
|
bottomAnimateClipart.classList.add('hidden');
|
||||||
bottomAnimateClipart.classList.remove('translate-x-full');
|
bottomAnimateClipart.classList.remove('translate-x-full');
|
||||||
}, 100);
|
}, 100);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ✅ Now create `userData` inside the correct scope where starValue exists
|
||||||
|
let userData = {
|
||||||
|
gameName: gameVersion,
|
||||||
|
gameID: gameId,
|
||||||
|
screenShot: imageCode,
|
||||||
|
childId: childId,
|
||||||
|
gameTime: timeDifferenceInSeconds,
|
||||||
|
gameStar: starValue // ✅ Now correctly assigned
|
||||||
|
};
|
||||||
|
|
||||||
|
// ✅ Now perform the second fetch request
|
||||||
|
fetch(`https://api.teachertrainingkolkata.in/api/saveGalleryImage`, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
},
|
||||||
|
body: JSON.stringify(userData)
|
||||||
|
})
|
||||||
|
.then(response => response.json())
|
||||||
|
.then(data => {
|
||||||
|
if (data.screenshotUrl) {
|
||||||
|
fetch(`https://api.teachertrainingkolkata.in/api/saveGameScore2`, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
},
|
||||||
|
body: JSON.stringify(userData)
|
||||||
|
})
|
||||||
|
.then(response => {
|
||||||
|
setTimeout(() => {
|
||||||
|
if (response.ok && response.status == 200) {
|
||||||
|
document.getElementById('saved-toast').classList.remove('hidden');
|
||||||
|
setTimeout(() => {
|
||||||
|
document.getElementById('saved-toast').classList.add('hidden');
|
||||||
|
}, 2000);
|
||||||
|
}
|
||||||
|
}, 100);
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
console.error('An error occurred', error);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Final API Call
|
||||||
|
const userAnotherData = {
|
||||||
|
assignmentId: assignmentId,
|
||||||
|
worksheetId: worksheetId,
|
||||||
|
studentId: childId,
|
||||||
|
submissionFile: data.screenshotUrl.split('/')[4].split('?')[0],
|
||||||
|
};
|
||||||
|
const authToken = 'Bearer eyJhbGciOiJSUzUxMiIsInR5cCI6IkpXVCJ9.eyJ1c2VyIjp7ImlkZW50aXR5SWQiOiI2NjNjNGMzNjRiNmYzZjU0YmExZjcxMTUiLCJfaWQiOiI2NjNjNGMzNjBiOWYyZDk5MGQyNWYwYjMiLCJ0eXBlIjoiQUtBREVNWSIsImRldmljZUlkIjoiMDBqNXJtODl5b3BvNjh1a2Yyb2c5cTdoIn0sImlhdCI6MTczNjM5ODkwNCwiZXhwIjoxNzM3MDAzNzA0LCJpc3MiOiJidXp6T25lIn0.vhH0zTkVisnbK6n5aPgV3RrtmpP095Gtz6ayUc29XerEV-XPVhYwg06JQnm2FWGPtadEJ2Ea5z6_YNp5Kz9DENL9LxpYYuXRUOGvMEaVM5YZOYQ88viqxM7SIvxElIsc8cQeJr5v-4ov4MyOuXws7R5MDDO2PuzYdwaA52GXbQ0LO3aFGOQL7nWPKVYqFWCQe_T-1JphbsGStHivcmUy8_DAdjs0VpXFJKiQm6jcWQO3j3uOUJSi14af4ZvrUPkjIT92OOHiZTL7CUbbFt4yktnw3Gm2Fv6lS5pamSJpVJnGJQ6ebjd70IXnE49Mn9IK9AssnjTBh2DaNeVc0C1z9Q';
|
||||||
|
|
||||||
|
fetch(`https://preschool-curriculum.in/api/one/v1/akademy/worksheet/submissions`, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
'Authorization': authToken
|
||||||
|
},
|
||||||
|
body: JSON.stringify(userAnotherData)
|
||||||
|
})
|
||||||
|
.then(response => response.json())
|
||||||
|
.then(data => {
|
||||||
|
console.log('Submission API response', data);
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
console.error('An error occurred', error);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
console.error('An error occurred', error);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}, 100);
|
}, 150);
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
console.error('An error occurred', error);
|
console.error('An error occurred', error);
|
||||||
});
|
});
|
||||||
}
|
}
|
Loading…
Reference in New Issue