Skip to content

Always zero value for the first day in traffic analytics. #7544

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

Closed
kuzmoyev opened this issue Oct 7, 2020 · 0 comments · Fixed by #7545
Closed

Always zero value for the first day in traffic analytics. #7544

kuzmoyev opened this issue Oct 7, 2020 · 0 comments · Fixed by #7545

Comments

@kuzmoyev
Copy link
Contributor

kuzmoyev commented Oct 7, 2020

if since is None:
since = timezone.now().date() - timezone.timedelta(days=30)
queryset = cls.objects.filter(
project__slug=project_slug,
date__gt=since,
).values('date').annotate(total_views=Sum('view_count')).order_by('date')
count_dict = dict(
queryset.order_by('date').values_list('date', 'total_views')
)
# This fills in any dates where there is no data
# to make sure we have a full 30 days of dates
count_data = [count_dict.get(date) or 0 for date in _last_30_days_iter()]

I think because the date__gt filter is used (instead of date__gte) the first value (a day exactly a month ago) doesn't get to the output dictionary count_dict. So count_dict.get(date) or 0 is evaluated to zero every time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant