Skip to content

Conversation

@umerp
Copy link
Contributor

@umerp umerp commented May 21, 2025

[Tournament] Add frontend for analytics page

####Please merge 1082 first, then this one, then 1286.

What does this PR do?

Builds a new frontend page to display tournament analytics, including:

  • Total matches
  • Completed matches
  • Fastest and slowest matches (with players and durations)
  • Average match duration
  • All matches with timestamps and player details

The page is accessible after a tournament concludes, providing users with a summary of how the tournament played out.

Why is this change necessary?

This feature provides players with insight into tournament performance and engagement. At the end of a tournament, users should be able to see key statistics that summarize the tournament experience.

What components/files are affected?

  • TournamentCreate
  • TournamentMatch
  • TournamentDetail
  • urls.py

How should this be tested?

  • Navigate to a completed tournament’s detail page and ensure there is a link to the analytics page
  • Verify that all the correct statistics are displayed, including fastest and slowest matches
  • Confirm that the page behaves properly when no matches exist
  • Confirm that the data is fetched from the backend analytics endpoint
from django.utils import timezone
from datetime import timedelta
from chigame.games.models import Tournament, Game, Match, Lobby, Player
from django.contrib.auth import get_user_model

User = get_user_model()

# Create a game
game = Game.objects.create(
    name="Test Game",
    description="Test Description",
    min_players=2,
    max_players=2,
    complexity=2.5
)

# Create two users
user1 = User.objects.create_user(username='user1', email='[email protected]', password='testpass123')
user2 = User.objects.create_user(username='user2', email='[email protected]', password='testpass123')

# Create a tournament that has ended
now = timezone.now()
tournament = Tournament.objects.create(
    name="Test Tournament",
    game=game,
    registration_start_date=now - timedelta(days=2),
    registration_end_date=now - timedelta(days=1),
    tournament_start_date=now - timedelta(days=1),
    tournament_end_date=now,  # Ended now
    max_players=2,
    description="Test tournament",
    rules="Standard rules",
    draw_rules="No draws allowed",
    num_winner=1
)

# Add players
tournament.players.add(user1, user2)

# Create a lobby
lobby = Lobby.objects.create(
    name="Test Lobby",
    game=game,
    created_by=user1,
    min_players=2,
    max_players=2,
    match_status=Lobby.Finished
)
lobby.members.add(user1, user2)

# Create a match with timing
match = Match.objects.create(
    game=game,
    lobby=lobby,
    date_played=now - timedelta(minutes=30),
    start_time=now - timedelta(minutes=30),
    end_time=now - timedelta(minutes=25),  # 5 minutes duration
    duration=timedelta(minutes=5)
)
match.players.add(user1, user2)
tournament.matches.add(match)

# Print the tournament ID so you can visit its stats page
print(f"Tournament ID: {tournament.id}")



After running these commands:
Note the tournament ID that gets printed
Visit /tournament/{tournament_id}/stats/ in your browser
You should see the match stats including:
The 5-minute duration match
The start and end times
The average duration

Related Issues

Closes #668

@umerp umerp added this to the 2025/Sprint 4 milestone May 21, 2025
@umerp umerp self-assigned this May 21, 2025
@umerp umerp added the enhancement New feature or request label May 21, 2025
@umerp umerp requested a review from johnruge May 21, 2025 03:21
@umerp
Copy link
Contributor Author

umerp commented May 21, 2025

I have added everything that we need for this. I think this is ready for review.

@umerp umerp changed the title Tournaments/frontend analytics Tournaments/Frontend for Analytics Page May 23, 2025
@johnruge
Copy link
Contributor

@umerp, how are we supposed to get a tournament with matches that were played and all the stats needed to test this pr? Do you have any fixtures we can load? I have resorted to loading fixtures that I used in the simulation, and it gives an indication that some of these features work, but I am not sure in a case where they were actual matches played.
Screenshot 2025-05-23 at 4 02 31 PM

@umerp
Copy link
Contributor Author

umerp commented May 23, 2025

Hi @johnruge you can refrence my testing file #1286 for more tests.

@johnruge
Copy link
Contributor

Hi @umerp, I do not think I can use changes in a later PR to test this one. It should be easy to make a small test fixture and push it here.

Copy link
Contributor

@johnruge johnruge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Good job!

@johnruge johnruge requested a review from MuyanXie May 25, 2025 20:03
Copy link
Contributor

@MuyanXie MuyanXie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! The analytics dashboard is going to be very helpful. Thanks!

@MuyanXie MuyanXie merged commit 933d9a6 into dev May 25, 2025
2 checks passed
@MuyanXie
Copy link
Contributor

Issue Score: satisfactory

Comments:
Nice work implementing this dashboard. It looks nice. However, please notice none of the commit messages above have the correct format (refer to the developers' guide; this is also calssified as a major issue on grading schema). Other than that, everything looks nice

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request x/tournaments

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

[Tournament] Frontend for analytics page

5 participants