|
@@ -4,7 +4,8 @@ from django.db.models import Count
|
|
|
|
|
|
|
|
|
def last_data(date, location_id):
|
|
|
- res = Review.objects.filter(create_time__gte=date, location_id=location_id).values('star_rating').annotate(total=Count('star_rating')).order_by('star_rating')
|
|
|
+ res = Review.objects.filter(create_time__gte=date, location_id=location_id).values('star_rating')\
|
|
|
+ .annotate(total=Count('star_rating')).order_by('star_rating')
|
|
|
ratings = [0] * 5
|
|
|
for r in res:
|
|
|
ratings[r.get('star_rating')-1] = r.get('total')
|
|
@@ -58,7 +59,7 @@ def get_review_count_by_month(location_id):
|
|
|
def get_review_count_by_week(location_id):
|
|
|
now = timezone.now()
|
|
|
day = 6 - now.weekday()
|
|
|
- first_day_week = now - timezone.timedelta(days=now.weekday()+1)
|
|
|
+ first_day_week = now - timezone.timedelta(days=(now.weekday()+1))
|
|
|
this_week = last_data(first_day_week, location_id)
|
|
|
sql = f'''
|
|
|
SELECT review_id, WEEK(create_time) as week, COUNT(review_id) as total_review
|