change drawing game star implemantetion
parent
cbe6255540
commit
c4131434ef
|
@ -116,82 +116,7 @@ function submitUserData(drawingZone) {
|
|||
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(){
|
||||
let progress = 0;
|
||||
let starValue;
|
||||
let maxStarValue = 5;
|
||||
|
||||
function progressIncrement() {
|
||||
const interval = setInterval(() => {
|
||||
|
@ -283,32 +207,33 @@ function submitUserData(drawingZone) {
|
|||
calculationText.style.fontWeight = '600';
|
||||
calculationText.style.color = 'rgba(0, 0, 0, 0.38)';
|
||||
containerDiv.appendChild(calculationText);
|
||||
let userData = {
|
||||
let userDataForStar = {
|
||||
gameName: gameVersion,
|
||||
childId: childId,
|
||||
gameID: gameId,
|
||||
gameTime: timeDifferenceInSeconds,
|
||||
screenShot: imageCode
|
||||
};
|
||||
// console.log(userData);
|
||||
|
||||
// First API call
|
||||
fetch(`https://api.teachertrainingkolkata.in/api/aiEvaluateImageToStar`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify(userData)
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify(userDataForStar)
|
||||
})
|
||||
.then(response => {
|
||||
if(!response.ok){
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP error! status: ${response.status}`);
|
||||
}
|
||||
return response.json()
|
||||
return response.json();
|
||||
})
|
||||
.then(data => {
|
||||
// console.log('data', data.data.score);
|
||||
setTimeout(() => {
|
||||
if (data && data.message === "Game data saved successfully") {
|
||||
starValue = data.data.score;
|
||||
let starValue = data.data.gameStar; // Ensure starValue is available
|
||||
|
||||
let feedbackMessage = '';
|
||||
if (starValue >= 1 && starValue <= 3) {
|
||||
feedbackMessage = "You're making progress! Let's keep going!";
|
||||
|
@ -321,6 +246,7 @@ function submitUserData(drawingZone) {
|
|||
} else {
|
||||
feedbackMessage = "Invalid star value.";
|
||||
}
|
||||
|
||||
loadingMainContainer.style.display = 'none';
|
||||
loadingDiv.style.display = 'none';
|
||||
starContainer.style.display = 'flex';
|
||||
|
@ -328,22 +254,92 @@ function submitUserData(drawingZone) {
|
|||
document.getElementById('get-star-value').innerHTML = starValue;
|
||||
document.getElementById('starFeedbackMessage').innerHTML = feedbackMessage;
|
||||
scoreBoard.style.display = 'flex';
|
||||
|
||||
if (scoreBoard.style.display === 'flex') {
|
||||
const bottomAnimateClipart = document.getElementById('bottomAnimateClipart');
|
||||
bottomAnimateClipart.classList.remove('hidden');
|
||||
bottomAnimateClipart.classList.add('-translate-x-full');
|
||||
bottomAnimateClipart.classList.add('transition-transform', 'duration-700');
|
||||
bottomAnimateClipart.classList.add('-translate-x-full', 'transition-transform', 'duration-700');
|
||||
setTimeout(() => {
|
||||
bottomAnimateClipart.classList.add('hidden');
|
||||
bottomAnimateClipart.classList.remove('translate-x-full');
|
||||
}, 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 => {
|
||||
console.error('An error occurred', error);
|
||||
});
|
||||
console.error('An error occurred', error);
|
||||
});
|
||||
}
|
Loading…
Reference in New Issue