Skip to content

Commit fd81bdc

Browse files
authored
Merge pull request #1650 from codalab/develop
Merge develop into master
2 parents 6eda3ca + e352bec commit fd81bdc

File tree

2 files changed

+57
-27
lines changed

2 files changed

+57
-27
lines changed

src/apps/competitions/utils.py

+38-16
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
'''
22
This file contains utilities for competitions
33
'''
4-
import random
5-
6-
from django.db.models import Count
4+
# import random
5+
# from django.db.models import Count
76

87
from competitions.models import Competition
98

@@ -16,14 +15,26 @@ def get_popular_competitions(limit=4):
1615
:rtype: list
1716
:return: Most popular competitions.
1817
'''
19-
competitions = Competition.objects.filter(published=True) \
20-
.annotate(participant_count=Count('participants')) \
21-
.order_by('-participant_count')
2218

23-
if len(competitions) <= limit:
24-
return competitions
19+
# TODO: Fix the fetching of the popular competitions
20+
# Uncomment and update the following code when a long term fix is implemented for participants count
21+
22+
# competitions = Competition.objects.filter(published=True) \
23+
# .annotate(participant_count=Count('participants')) \
24+
# .order_by('-participant_count')
25+
26+
# if len(competitions) <= limit:
27+
# return competitions
2528

26-
return competitions[:limit]
29+
# return competitions[:limit]
30+
31+
# Temporary solution to show specific popular competitions
32+
try:
33+
popular_competiion_ids = [1752, 1772, 2338, 3863]
34+
competitions = Competition.objects.filter(id__in=popular_competiion_ids)
35+
return competitions
36+
except Exception:
37+
return []
2738

2839

2940
def get_featured_competitions(limit=4, excluded_competitions=None):
@@ -36,13 +47,24 @@ def get_featured_competitions(limit=4, excluded_competitions=None):
3647
:return: list of featured competitions
3748
'''
3849

39-
competitions = Competition.objects.filter(published=True) \
40-
.annotate(participant_count=Count('participants'))
50+
# TODO: Fix the fetching of the featured competitions
51+
# Uncomment and update the following code when a long term fix is implemented for participants count
52+
53+
# competitions = Competition.objects.filter(published=True) \
54+
# .annotate(participant_count=Count('participants'))
55+
56+
# if excluded_competitions:
57+
# competitions = competitions.exclude(pk__in=[c.pk for c in excluded_competitions])
4158

42-
if excluded_competitions:
43-
competitions = competitions.exclude(pk__in=[c.pk for c in excluded_competitions])
59+
# if len(competitions) <= limit:
60+
# return competitions
61+
# else:
62+
# return random.sample(list(competitions), limit)
4463

45-
if len(competitions) <= limit:
64+
# Temporary solution to show specific featured competitions
65+
try:
66+
featured_competiion_ids = [3523, 2745, 3160, 1567]
67+
competitions = Competition.objects.filter(id__in=featured_competiion_ids)
4668
return competitions
47-
else:
48-
return random.sample(list(competitions), limit)
69+
except Exception:
70+
return []

src/apps/pages/views.py

+19-11
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
from django.core.paginator import Paginator, PageNotAnInteger, EmptyPage
22
from django.views.generic import TemplateView
3-
from django.db.models import Count, Q
3+
from django.db.models import Q
44

5-
from competitions.models import Competition, Submission
6-
from profiles.models import User
5+
from competitions.models import Submission
76
from announcements.models import Announcement, NewsPost
87

98
from django.shortcuts import render
@@ -15,15 +14,24 @@ class HomeView(TemplateView):
1514
def get_context_data(self, *args, **kwargs):
1615
context = super().get_context_data(*args, **kwargs)
1716

18-
data = Competition.objects.aggregate(
19-
count=Count('*'),
20-
published_comps=Count('pk', filter=Q(published=True)),
21-
unpublished_comps=Count('pk', filter=Q(published=False)),
22-
)
17+
# TODO: Optimize fetching the statistics
18+
# Possibly from a file where they are written by an automated script once a day
19+
# For now showing latest numbers from live codabench
20+
# The following commented code is slowing down the loading of the home page
2321

24-
public_competitions = data['published_comps']
25-
users = User.objects.all().count()
26-
submissions = Submission.objects.all().count()
22+
# data = Competition.objects.aggregate(
23+
# count=Count('*'),
24+
# published_comps=Count('pk', filter=Q(published=True)),
25+
# unpublished_comps=Count('pk', filter=Q(published=False)),
26+
# )
27+
28+
# public_competitions = data['published_comps']
29+
# users = User.objects.all().count()
30+
# submissions = Submission.objects.all().count()
31+
32+
public_competitions = 204
33+
users = 12216
34+
submissions = 70276
2735

2836
context['general_stats'] = [
2937
{'label': "Public Competitions", 'count': public_competitions},

0 commit comments

Comments
 (0)