Skip to content

Commit

Permalink
Update: Add context referencing for chatbot (#196)
Browse files Browse the repository at this point in the history
  • Loading branch information
hoangsonww committed Jul 26, 2024
1 parent 4e62cce commit ff10b9b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 19 deletions.
1 change: 0 additions & 1 deletion MovieVerse-Frontend/html/analytics.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/html" xmlns="http://www.w3.org/1999/html">

<head>
<meta charset="UTF-8">
<title>Database Analytics - The MovieVerse</title>
Expand Down
2 changes: 2 additions & 0 deletions MovieVerse-Frontend/js/analytics.js
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,7 @@ async function loadHighlyRatedMoviesOverYearsChart() {
}

function loadAllCharts() {
showSpinner();
loadMoviesByYearChart();
loadGenrePopularityChart();
loadMoviesByCertificationChart();
Expand All @@ -423,6 +424,7 @@ function loadAllCharts() {
loadTopRatedMoviesPerYearChart();
loadTotalMovieVotesOverYearsChart();
loadHighlyRatedMoviesOverYearsChart();
hideSpinner();
}

document.addEventListener('DOMContentLoaded', loadAllCharts);
Expand Down
37 changes: 19 additions & 18 deletions MovieVerse-Frontend/js/user-profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,11 @@ const app = initializeApp(firebaseConfig);
const db = getFirestore(app);

document.addEventListener('DOMContentLoaded', function() {
showSpinner();
handleProfileDisplay();
setupEventListeners();
setupSearchListeners();
hideSpinner();
});

function updateProgressCircles(movieRating, triviaScore) {
Expand Down Expand Up @@ -127,6 +129,7 @@ function handleProfileDisplay() {

function setupSearchListeners() {
try {
showSpinner();
const searchUserInput = document.getElementById('searchUserInput');
const searchUserResults = document.getElementById('searchUserResults');

Expand All @@ -141,6 +144,7 @@ function setupSearchListeners() {
searchUserResults.style.display = 'none';
}
});
hideSpinner();
}
catch (error) {
console.error("Error fetching user list: ", error);
Expand Down Expand Up @@ -213,16 +217,11 @@ document.getElementById('container1').addEventListener('click', async () => {
}

try {
const rating = await getAverageMovieRating(userEmail);
const convertRatingToPercent = (rating / 5) * 100;
const averageRating = convertRatingToPercent.toFixed(1);
const rating = parseInt(localStorage.getItem('currentAverageRating'), 10);
const averageRating = rating.toFixed(1);

const triviaStats = await getTriviaStats(userEmail);

let averageTriviaScore = 0;
if (triviaStats.totalAttempted > 0) {
averageTriviaScore = (triviaStats.totalCorrect / triviaStats.totalAttempted) * 100;
}
const triviaStats = parseInt(localStorage.getItem('currentAverageTriviaScore'), 10);
const averageTriviaScore = triviaStats.toFixed(1);

updateProgressCircles(averageRating, averageTriviaScore, 'container1');
}
Expand All @@ -244,16 +243,11 @@ document.getElementById('container2').addEventListener('click', async () => {
}

try {
const rating = await getAverageMovieRating(userEmail);
const convertRatingToPercent = (rating / 5) * 100;
const averageRating = convertRatingToPercent.toFixed(1);
const rating = parseInt(localStorage.getItem('currentAverageRating'), 10);
const averageRating = rating.toFixed(1);

const triviaStats = await getTriviaStats(userEmail);

let averageTriviaScore = 0;
if (triviaStats.totalAttempted > 0) {
averageTriviaScore = (triviaStats.totalCorrect / triviaStats.totalAttempted) * 100;
}
const triviaStats = parseInt(localStorage.getItem('currentAverageTriviaScore'), 10);
const averageTriviaScore = triviaStats.toFixed(1);

updateProgressCircles(averageRating, averageTriviaScore, 'container2');
}
Expand Down Expand Up @@ -355,6 +349,9 @@ async function loadProfile(userEmail = localStorage.getItem('currentlySignedInMo

updateProgressCircles(averageRating, averageTriviaScore);

localStorage.setItem('currentAverageRating', averageRating);
localStorage.setItem('currentAverageTriviaScore', averageTriviaScore);

try {
const docSnap = await getDoc(docRef);
let profile = {
Expand Down Expand Up @@ -633,6 +630,8 @@ function resizeImageAndConvertToBase64(file, maxWidth, maxHeight) {
}

function setupEventListeners() {
showSpinner();

document.getElementById('saveChanges').addEventListener('click', async () => {
await saveProfileChanges();
});
Expand Down Expand Up @@ -704,4 +703,6 @@ function setupEventListeners() {
document.getElementById('removeProfileImage').addEventListener('click', async () => {
await removeProfileImage();
});

hideSpinner();
}

0 comments on commit ff10b9b

Please sign in to comment.