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

Feature request: Show hits from yesterday, lastweek ... #60

Open
sowinski opened this issue Jun 27, 2017 · 4 comments
Open

Feature request: Show hits from yesterday, lastweek ... #60

sowinski opened this issue Jun 27, 2017 · 4 comments

Comments

@sowinski
Copy link

Hi,

how can I check hits for a specific time period? Right now, it is only possible to count the hits from now back to a certain time period.

Get total hits for an object over a certain time period:

{% get_hit_count for [object] within ["days=1"] %}

Regards

@thornomad
Copy link
Owner

Good idea! Would need to be able to do it on a specific date or a range of dates or some basic querying. I like it!

Would be happy to consider a PR for such a feature. I am not actively developing this project these days; just trying to keep it up and running.

@sowinski
Copy link
Author

I use this peace of code for general statistics per Day with some filter for a specific kind of objects.

from hitcount.models import Hit
from django.contrib.contenttypes.models import ContentType
content_type = ContentType.objects.get(app_label="searchroom", model="buildingcontactdetails")

Hit.objects.filter(hitcount__content_type=content_type).annotate(created_date=TruncDate('created')).values('created_date').annotate(sum=Count('created_date')).values('created_date', 'sum').order_by('created_date')

This show the hits per day

@sowinski
Copy link
Author

I ended up with this code. But it is super slow.

Building.objects.filter(user=self.request.user)
            .annotate(get_hits_lastmonth=Coalesce(Subquery(hitcount_30.values('myhits')[:1], output_field=IntegerField()), 0)) \
            .annotate(get_hits_lastweek=Coalesce(Subquery(hitcount_7.values('myhits')[:1], output_field=IntegerField()), 0)) \
            .annotate(get_hits_yesterday=Coalesce(Subquery(hitcount_1.values('myhits')[:1], output_field=IntegerField()), 0)) 

I am using this request to show in my users dashboard some activities in the last day, week and month.

Any Idea how to optimize this?

@Ione03
Copy link

Ione03 commented Mar 23, 2022

I use this peace of code:
today = datetime.datetime.now()
hit_today = Hit.objects.filter(created__year=today.year, created__month=today.month, \
created__day=today.day).count()

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

No branches or pull requests

3 participants