Skip to content

Commit

Permalink
Merge pull request #1757 from Jovit-Mathew236/dev
Browse files Browse the repository at this point in the history
[FIX] Fix counting issue in UrlAnalyticsAPI
  • Loading branch information
adnankattekaden authored Dec 6, 2023
2 parents 3495c4b + faed6e9 commit 28268d8
Showing 1 changed file with 29 additions and 24 deletions.
53 changes: 29 additions & 24 deletions api/url_shortener/url_shortener_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,32 +139,37 @@ def get(self, request, url_id):
devices = {}
referrer = {}

for query in queryset:
# Counting browsers
if browsers.get(query.browser):
browsers[query.browser] += 1
else:
browsers[query.browser] = 1

# Counting operating systems
if operating_systems.get(query.operating_system):
operating_systems[query.operating_system] += 1
else:
operating_systems[query.operating_system] = 1

# Counting devices
if devices.get(query.device_type):
devices[query.device_type] += 1
else:
devices[query.device_type] = 1

if referrer.get(query.referrer):
referrer[query.referrer] += 1
else:
referrer[query.referrer] = 1
if queryset.exists(): # Check if the queryset is not empty
for query in queryset:
# Counting browsers
if browsers.get(query.browser):
browsers[query.browser] += 1
else:
browsers[query.browser] = 1

# Counting operating systems
if operating_systems.get(query.operating_system):
operating_systems[query.operating_system] += 1
else:
operating_systems[query.operating_system] = 1

# Counting devices
if devices.get(query.device_type):
devices[query.device_type] += 1
else:
devices[query.device_type] = 1

if referrer.get(query.referrer):
referrer[query.referrer] += 1
else:
referrer[query.referrer] = 1

total_clicks = queryset.first().url_shortener.count
else:
total_clicks = 0

result = {
'total_clicks': query.url_shortener.count,
'total_clicks': total_clicks,
'browsers': browsers,
'platforms': operating_systems,
'devices': devices,
Expand Down

0 comments on commit 28268d8

Please sign in to comment.