Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge dev-server to dev #2023

Merged
merged 29 commits into from
Jun 7, 2024
Merged
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
9216fde
Merge pull request #1957 from gtech-mulearn/dev-server
Jenin82 May 15, 2024
410e04d
Merge pull request #1982 from gtech-mulearn/dev
jelanmathewjames May 30, 2024
0264597
Merge pull request #1983 from gtech-mulearn/dev
jelanmathewjames May 30, 2024
7251db9
Merge pull request #1985 from gtech-mulearn/dev
jelanmathewjames May 30, 2024
effdf3e
Merge pull request #1986 from gtech-mulearn/dev
jelanmathewjames May 30, 2024
8c20cf3
Merge pull request #1988 from gtech-mulearn/dev
jelanmathewjames Jun 1, 2024
5521f6f
Merge pull request #1990 from gtech-mulearn/dev
jelanmathewjames Jun 1, 2024
c6ebdeb
Merge pull request #1992 from gtech-mulearn/dev
jelanmathewjames Jun 1, 2024
97b1d20
Merge pull request #1994 from gtech-mulearn/dev
jelanmathewjames Jun 1, 2024
af071d8
Merge pull request #1996 from gtech-mulearn/dev
jelanmathewjames Jun 1, 2024
977fb85
Merge pull request #1998 from gtech-mulearn/dev
jelanmathewjames Jun 1, 2024
ac4fdd3
Merge pull request #1999 from gtech-mulearn/dev
jelanmathewjames Jun 1, 2024
dd1950e
Merge pull request #2001 from gtech-mulearn/dev
jelanmathewjames Jun 1, 2024
fbc010a
Merge pull request #2002 from gtech-mulearn/dev
jelanmathewjames Jun 1, 2024
bca169b
Merge pull request #2004 from gtech-mulearn/dev
jelanmathewjames Jun 1, 2024
7b1a323
Merge pull request #2005 from gtech-mulearn/dev
jelanmathewjames Jun 1, 2024
d85913b
Merge pull request #2007 from gtech-mulearn/dev
Kochouseph26John Jun 6, 2024
1df2e88
Merge pull request #2009 from gtech-mulearn/dev
Kochouseph26John Jun 6, 2024
8dc64ba
Merge pull request #2010 from gtech-mulearn/dev-server
Kochouseph26John Jun 6, 2024
2efe031
Revert "prod"
Kochouseph26John Jun 6, 2024
8346be0
Merge pull request #2011 from gtech-mulearn/revert-2010-dev-server
Kochouseph26John Jun 6, 2024
a1a08ef
Merge pull request #2013 from gtech-mulearn/dev
Kochouseph26John Jun 6, 2024
6da4934
Merge pull request #2015 from gtech-mulearn/dev
Kochouseph26John Jun 6, 2024
6b08add
Merge pull request #2017 from gtech-mulearn/dev
Kochouseph26John Jun 6, 2024
48e3d5e
Merge branch 'production' into dev-server
Kochouseph26John Jun 7, 2024
021d84e
Merge pull request #2018 from gtech-mulearn/dev-server
Kochouseph26John Jun 7, 2024
fe88b5b
Merge pull request #2020 from gtech-mulearn/dev
Kochouseph26John Jun 7, 2024
a96422b
Merge pull request #2021 from gtech-mulearn/dev
Kochouseph26John Jun 7, 2024
065c876
Merge pull request #2022 from gtech-mulearn/production
jelanmathewjames Jun 7, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
122 changes: 115 additions & 7 deletions api/launchpad/launchpad_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from db.task import KarmaActivityLog



class Leaderboard(APIView):
def get(self, request):
total_karma_subquery = KarmaActivityLog.objects.filter(
Expand All @@ -19,13 +20,6 @@ def get(self, request):
).values('user').annotate(
total_karma=Sum('karma')
).values('total_karma')

intro_task_completed_users = KarmaActivityLog.objects.filter(
task__event='launchpad',
appraiser_approved=True,
task__hashtag='#lp24-introduction',
).values('user')

allowed_org_types = ["College", "School", "Company"]

users = User.objects.filter(
Expand Down Expand Up @@ -61,3 +55,117 @@ def get(self, request):
return CustomResponse().paginated_response(
data=serializer.data, pagination=paginated_queryset.get("pagination")
)
# class Leaderboard(APIView):
# def get(self, request):
# total_karma_subquery = KarmaActivityLog.objects.filter(
# user=OuterRef('id'),
# task__event='launchpad',
# appraiser_approved=True,
# ).values('user').annotate(
# total_karma=Sum('karma')
# ).values('total_karma')


# users = (
# User.objects.filter(
# karma_activity_log_user__task__event="launchpad",
# karma_activity_log_user__appraiser_approved=True,
# karma_activity_log_user__task__hashtag="#lp24-introduction",
# ).prefetch_related(
# Prefetch(
# "user_organization_link_user",
# queryset=UserOrganizationLink.objects.filter(
# org__org_type__in=["College", "School", "Company", "Community"]
# ),
# )
# )
# .annotate(
# karma=Subquery(total_karma_subquery, output_field=IntegerField()),
# org=F("user_organization_link_user__org__title"),
# district_name=F("user_organization_link_user__org__district__name"),
# state=F("user_organization_link_user__org__district__zone__state__name"),
# time_=Max("karma_activity_log_user__created_at"),
# )
# )

# paginated_queryset = CommonUtils.get_paginated_queryset(
# users,
# request,
# ["karma", "org", "district_name", "state", "time_"],
# sort_fields={
# "-karma": "-karma",
# "time_": "time_",
# },
# )

# serializer = LaunchpadLeaderBoardSerializer(
# paginated_queryset.get("queryset"), many=True
# )
# return CustomResponse().paginated_response(
# data=serializer.data, pagination=paginated_queryset.get("pagination")
# )
class Leaderboard(APIView):
def get(self, request):
query = """
SELECT
u.full_name,
SUM(kal.karma) AS karma,
COALESCE(org.title, comm.title) AS org,
COALESCE(org.dis, d.name) AS district,
COALESCE(org.state, s.name) AS state,
MAX(kal.created_at) AS time_
FROM karma_activity_log AS kal
INNER JOIN user AS u ON kal.user_id = u.id
INNER JOIN task_list AS tl ON tl.id = kal.task_id
LEFT JOIN (
SELECT
uol.user_id,
org.id,
org.title AS title,
d.name dis,
s.name state
FROM user_organization_link AS uol
INNER JOIN organization AS org ON org.id = uol.org_id AND org.org_type IN
("College", "School", "Company")
LEFT JOIN district AS d ON d.id = org.district_id
LEFT JOIN zone AS z ON z.id = d.zone_id
LEFT JOIN state AS s ON s.id = z.state_id
GROUP BY uol.user_id
) AS org ON org.user_id = u.id
LEFT JOIN (
SELECT
uol.user_id,
org.id,
org.title AS title
FROM organization AS org
INNER JOIN user_organization_link AS uol ON org.id = uol.org_id AND org.org_type IN ("Community")
GROUP BY uol.user_id
) AS comm ON comm.user_id = u.id
LEFT JOIN district AS d ON d.id = u.district_id
LEFT JOIN zone AS z ON d.zone_id = z.id
LEFT JOIN state AS s ON z.state_id = s.id
WHERE
tl.event = "launchpad" AND
kal.appraiser_approved = TRUE AND
u.id IN (
SELECT karma_activity_log.user_id FROM karma_activity_log
INNER JOIN task_list ON karma_activity_log.task_id = task_list.id
WHERE
task_list.hashtag = "#lp24-introduction" AND
karma_activity_log.appraiser_approved = TRUE
)
GROUP BY u.id
ORDER BY karma DESC, time_
"""
with connection.cursor() as cursor:
cursor.execute(query)
results = cursor.fetchall()
column_names = [desc[0] for desc in cursor.description]
user_ids = set()
list_of_dicts = []
for row in results:
if row[0] not in user_ids:
user_ids.add(row[0])
list_of_dicts.append(dict(zip(column_names, row)))
return CustomResponse(response=list_of_dicts).get_success_response()

Loading