diff --git a/Dockerfile b/Dockerfile index 957b964..f4bd023 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,7 +4,7 @@ FROM nginx:alpine COPY app/ /usr/share/nginx/html -COPY nginx.conf /etc/nginx/nginx.conf +#COPY nginx.conf /etc/nginx/nginx.conf EXPOSE 80 diff --git a/app/js/end_game.js b/app/js/end_game.js index e70adc4..1cd19ca 100644 --- a/app/js/end_game.js +++ b/app/js/end_game.js @@ -1,5 +1,6 @@ document.addEventListener('DOMContentLoaded', () => { + // Get game infos const params = new URLSearchParams(window.location.search); const score = params.get('score'); const meanTime = params.get('mean_time'); @@ -8,14 +9,17 @@ document.addEventListener('DOMContentLoaded', () => { const difficulty = params.get('difficulty').toLowerCase(); const mode = params.get('mode').toLowerCase(); + // Ensure the time is displayed in a user-friendly format (seconds with two decimal places) const formattedTime = parseFloat(meanTime).toFixed(2); + // Display the score and mean time document.getElementById('scoreValue').textContent = `${score}`; document.getElementById('timeValue').textContent = `${formattedTime} seconds`; document.getElementById('playerNameValue').textContent = `${player_name}`; document.getElementById('difficultyValue').textContent = `${difficulty}`; document.getElementById('totalRoundsValue').textContent = `${totalRounds}`; + // Send the score to the server const postData = { user: player_name, score: parseInt(score), @@ -24,36 +28,47 @@ document.addEventListener('DOMContentLoaded', () => { difficulty: difficulty }; - console.log('data to be sent:'); - console.log(JSON.stringify(postData)); - - fetch('http://localhost:8000/add_score', { - method: 'POST', - headers: { - 'Content-Type': 'application/json' - }, - body: JSON.stringify(postData) - }) - .then(response => response.json()) - .then(data => { - console.log('Success:', data); - }) - .catch((error) => { - console.error('Error:', error); - }); - - fetch(`http://localhost:8000/scores?mode=${mode}&difficulty=${difficulty}`) + // console.log('data to be sent:'); + // console.log(JSON.stringify(postData)); + + // fetch('http://127.0.0.1:8000/add_score', { + // method: 'POST', + // headers: { + // 'Content-Type': 'application/json' + // }, + // body: JSON.stringify(postData) + // }) + // .then(response => response.json()) + // .then(data => { + // console.log('Success:', data); + // }) + // .catch((error) => { + // console.error('Error:', error); + // }); + + // Get the podium from the server + fetch('http://localhost:8000/scores') .then(response => response.json()) .then(data => { - console.log('Podium data:', data); - displayPodium(data); + console.log('All scores data:', data); + // Sort the data by score (descending) and mean_time (ascending) + const sortedData = data.sort((a, b) => { + if (b.score === a.score) { + return a.mean_time - b.mean_time; + } + return b.score - a.score; + }); + // Take the top 3 scores + const top3 = sortedData.slice(0, 3); + displayPodium(top3); }) .catch((error) => { - console.error('Error fetching podium data:', error); + console.error('Error fetching scores data:', error); }); function displayPodium(scores) { const podiumContainer = document.getElementById('podium-container'); + podiumContainer.innerHTML = ''; // Clear previous podium data scores.forEach((score, index) => { const podiumBlock = document.createElement('div'); @@ -87,4 +102,4 @@ document.addEventListener('DOMContentLoaded', () => { podiumContainer.appendChild(podiumBlock); }); } -}); +}); \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index f60daea..f02fd09 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -8,7 +8,7 @@ services: - "8000:8000" networks: - quickdraw-network - command: ["/app/endpoints/entrypoint.sh", "--device", "cpu"] + command: ["/app/endpoints/entrypoint.sh", "--device", "mps"] quickdraw: image: ghcr.io/mlengineershub/quickdraw:latest diff --git a/endpoints/predict_cpu.py b/endpoints/predict_cpu.py index 7d39aad..e2972fd 100644 --- a/endpoints/predict_cpu.py +++ b/endpoints/predict_cpu.py @@ -171,10 +171,9 @@ async def get_labels(): @app.get("/scores") -async def get_scores(mode: str, difficulty: str): +async def get_scores(): """ - Function to return the top 3 scores from the database - filtered by the given mode and difficulty. + Function to return all scores from the database without any filters. It returns a dictionary with the scores. score1: { user: user1, @@ -205,14 +204,9 @@ async def get_scores(mode: str, difficulty: str): data = _data[1] df = pd.DataFrame(data) - df_filtered = df[(df['mode'] == mode) & (df['difficulty'] == difficulty)] - df_filtered = df_filtered.sort_values(by=['score', 'mean_time'], - ascending=[False, True]) - - df_top3 = df_filtered.head(3) - - scores = df_top3.to_dict(orient='records') + # Return the DataFrame as a dictionary without any filtering + scores = df.to_dict(orient='records') return scores diff --git a/nginx.conf b/nginx.conf index fd31c05..e69de29 100644 --- a/nginx.conf +++ b/nginx.conf @@ -1,27 +0,0 @@ -upstream api { - server localhost:8000; -} - -server { - listen 80; - server_name localhost; - - location / { - - if ($request_method = 'OPTIONS') { - add_header 'Access-Control-Max-Age' 1728000; - add_header 'Access-Control-Allow-Origin' '*'; - add_header 'Access-Control-Allow-Headers' 'Authorization,Accept,Origin,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range'; - add_header 'Access-Control-Allow-Methods' 'GET,POST,OPTIONS,PUT,DELETE,PATCH'; - add_header 'Content-Type' 'application/json'; - add_header 'Content-Length' 0; - return 204; - } - - add_header 'Access-Control-Allow-Origin' '*'; - add_header 'Access-Control-Allow-Headers' 'Authorization,Accept,Origin,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range'; - add_header 'Access-Control-Allow-Methods' 'GET,POST,OPTIONS,PUT,DELETE,PATCH'; - - proxy_pass http://api/; - } -}