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

Add the whole year to download graph and defaults to totals #50

Merged
merged 1 commit into from
Apr 5, 2024
Merged
Changes from all commits
Commits
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
22 changes: 12 additions & 10 deletions ckanext/matomo/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -492,20 +492,22 @@ def get_downloads_in_date_range_by_id(cls, resource_id: str, start_date: datetim
.group_by('weekly').order_by('weekly').all())


total_visits_and_downloads = model.Session.query(func.sum(cls.visits).label('visits'),
func.sum(cls.downloads).label('downloads')).filter(
cls.resource_id == resource_id).first()
total_visits_and_downloads = (model.Session.query(func.sum(cls.visits).label('visits'),
func.sum(cls.downloads).label('downloads'))
.filter(cls.resource_id == resource_id).first())

visits: Visits = []

for week_visits in weekly_visits:
visits.append({'year': week_visits.weekly.year, 'week': week_visits.weekly.isocalendar()[1],
'downloads': week_visits.weekly_downloads})
visits = [{'year': (start_date + timedelta(weeks=x)).year,
'week': (start_date + timedelta(weeks=x)).isocalendar()[1],
'downloads': 0} for x in range(0,52)]

for date in visits:
for week_visits in weekly_visits:
if date['year'] == week_visits.weekly.year and date['week'] == week_visits.weekly.isocalendar()[1]:
date['downloads'] = week_visits.weekly_downloads

results = {'visits': visits,
'total_visits': total_visits_and_downloads.visits,
'total_downloads': total_visits_and_downloads.downloads}
'total_visits': total_visits_and_downloads.visits if total_visits_and_downloads.visits else 0,
'total_downloads': total_visits_and_downloads.downloads if total_visits_and_downloads.downloads else 0}

return results

Expand Down
Loading