diff --git a/django/frontend/static/js/views/ProfilePageView.js b/django/frontend/static/js/views/ProfilePageView.js index 08a4bc6..aea532c 100644 --- a/django/frontend/static/js/views/ProfilePageView.js +++ b/django/frontend/static/js/views/ProfilePageView.js @@ -21,7 +21,7 @@ export default class extends AbstractView { await this.fillHistory(games); await this.fillStatistics(games); - if (this.profile.id === client.me.id) + if (!client.me || this.profile.id === client.me.id) return; const addFriendButton = document.getElementById('addFriendButton'), @@ -78,8 +78,8 @@ export default class extends AbstractView { */ async fillStatistics(games) { - let winrateDiv = document.getElementById("winrate"); - + const winrateDiv = document.getElementById("winrate"); + let win = 0; let lose = 0; @@ -87,13 +87,17 @@ export default class extends AbstractView { if (game.finished === false) return - if (client.me.id === game.winner.id) + if (this.profile.id === game.winner.id) win++; else lose++; }); - winrateDiv.innerText = `winrate: ${win + lose === 0 ? "🤓" : win / (win + lose)}` + if (games.length) { + winrateDiv.innerText = `Winrate: ${win / (win + lose) * 100}%`; + } else { + winrateDiv.innerText = `Winrate: 🤓` + } } async fillHistory(games) diff --git a/django/games/objects/pong/PongGame.py b/django/games/objects/pong/PongGame.py index 1aca573..bf073e1 100644 --- a/django/games/objects/pong/PongGame.py +++ b/django/games/objects/pong/PongGame.py @@ -50,9 +50,9 @@ class PongGame(AGame): for i in range(4): if i < nb_players: - self.players.append(PongPlayer(self, players[i], None, Segment(corners[i], corners[(i + 1) % 4]))) + self.players.append(PongPlayer(self, players[i], None, Segment(corners[(i + 1) % 4], corners[i]))) else: - self.walls.append(Segment(corners[i], corners[(i + 1) % 4])) + self.walls.append(Segment(corners[(i + 1) % 4], corners[i])) self.ball: Ball = Ball() diff --git a/django/games/routine.py b/django/games/routine.py index 59e0493..0c5c5d2 100644 --- a/django/games/routine.py +++ b/django/games/routine.py @@ -303,7 +303,7 @@ async def async_routine(game: PongGame): ball_routine.cancel() return - await asyncio.sleep(0.05) + await asyncio.sleep(1) def routine(game: PongGame): diff --git a/docker-compose.yml b/docker-compose.yml index bf3dd82..261d5b0 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,4 +1,4 @@ -name: ft_transcendence +version: '3.8' services: django: @@ -11,10 +11,13 @@ services: container_name: django restart: always env_file: .env + volumes: + - type: bind + source: ./django + target: /app depends_on: db: condition: service_healthy - restart: true db: image: postgres