|
@@ -1,4 +1,3 @@
|
|
-from django.db.models import Count
|
|
|
|
from review.models import Review
|
|
from review.models import Review
|
|
|
|
|
|
|
|
|
|
@@ -8,7 +7,7 @@ def get_review_count_by_month(location_id):
|
|
FROM review_review
|
|
FROM review_review
|
|
WHERE DATE_ADD(CURRENT_TIMESTAMP(),INTERVAL -1 YEAR) <= create_time and location_id={location_id}
|
|
WHERE DATE_ADD(CURRENT_TIMESTAMP(),INTERVAL -1 YEAR) <= create_time and location_id={location_id}
|
|
GROUP BY MONTH(create_time)
|
|
GROUP BY MONTH(create_time)
|
|
- ORDER BY DATE(create_time) DESC
|
|
|
|
|
|
+ ORDER BY DATE(create_time)
|
|
'''
|
|
'''
|
|
qs = Review.objects.raw(sql)
|
|
qs = Review.objects.raw(sql)
|
|
label = [q.month for q in qs]
|
|
label = [q.month for q in qs]
|
|
@@ -21,7 +20,7 @@ def get_review_count_by_month(location_id):
|
|
WHERE DATE_ADD(CURRENT_TIMESTAMP(),INTERVAL -1 YEAR) <= create_time
|
|
WHERE DATE_ADD(CURRENT_TIMESTAMP(),INTERVAL -1 YEAR) <= create_time
|
|
and location_id={location_id} and star_rating={i}
|
|
and location_id={location_id} and star_rating={i}
|
|
GROUP BY MONTH(create_time)
|
|
GROUP BY MONTH(create_time)
|
|
- ORDER BY DATE(create_time) DESC
|
|
|
|
|
|
+ ORDER BY DATE(create_time)
|
|
'''
|
|
'''
|
|
qs = Review.objects.raw(sql)
|
|
qs = Review.objects.raw(sql)
|
|
ratings = [0]*len(label)
|
|
ratings = [0]*len(label)
|
|
@@ -29,7 +28,7 @@ def get_review_count_by_month(location_id):
|
|
ratings[label.index(q.month)] = q.total_ratings
|
|
ratings[label.index(q.month)] = q.total_ratings
|
|
star_ratings.append(ratings)
|
|
star_ratings.append(ratings)
|
|
response = {
|
|
response = {
|
|
- 'month': label,
|
|
|
|
|
|
+ 'label': label,
|
|
'total_reviews': total_review,
|
|
'total_reviews': total_review,
|
|
'one_star': star_ratings[0],
|
|
'one_star': star_ratings[0],
|
|
'two_star': star_ratings[1],
|
|
'two_star': star_ratings[1],
|
|
@@ -40,32 +39,34 @@ def get_review_count_by_month(location_id):
|
|
return response
|
|
return response
|
|
|
|
|
|
|
|
|
|
-def get_review_count_by_month_all():
|
|
|
|
|
|
+def get_review_count_by_week(location_id):
|
|
sql = f'''
|
|
sql = f'''
|
|
- SELECT review_id, MONTHNAME(create_time) as month, COUNT(review_id) as total_review
|
|
|
|
|
|
+ SELECT review_id, WEEK(create_time) as week, COUNT(review_id) as total_review
|
|
FROM review_review
|
|
FROM review_review
|
|
- GROUP BY MONTH(create_time)
|
|
|
|
- ORDER BY DATE(create_time) DESC
|
|
|
|
|
|
+ WHERE DATE_ADD(CURRENT_TIMESTAMP(),INTERVAL -1 YEAR) <= create_time and location_id={location_id}
|
|
|
|
+ GROUP BY WEEK(create_time)
|
|
|
|
+ ORDER BY DATE(create_time)
|
|
'''
|
|
'''
|
|
qs = Review.objects.raw(sql)
|
|
qs = Review.objects.raw(sql)
|
|
- label = [q.month for q in qs]
|
|
|
|
|
|
+ label = [q.week for q in qs]
|
|
total_review = [q.total_review for q in qs]
|
|
total_review = [q.total_review for q in qs]
|
|
star_ratings = []
|
|
star_ratings = []
|
|
for i in range(1, 6):
|
|
for i in range(1, 6):
|
|
sql = f'''
|
|
sql = f'''
|
|
- SELECT review_id, MONTHNAME(create_time) as month, COUNT(review_id) as total_ratings
|
|
|
|
|
|
+ SELECT review_id, WEEK(create_time) as week, COUNT(review_id) as total_ratings
|
|
FROM review_review
|
|
FROM review_review
|
|
- WHERE star_rating={i}
|
|
|
|
- GROUP BY MONTH(create_time)
|
|
|
|
- ORDER BY DATE(create_time) DESC
|
|
|
|
|
|
+ WHERE DATE_ADD(CURRENT_TIMESTAMP(),INTERVAL -1 YEAR) <= create_time
|
|
|
|
+ and location_id={location_id} and star_rating={i}
|
|
|
|
+ GROUP BY WEEK(create_time)
|
|
|
|
+ ORDER BY DATE(create_time)
|
|
'''
|
|
'''
|
|
qs = Review.objects.raw(sql)
|
|
qs = Review.objects.raw(sql)
|
|
ratings = [0]*len(label)
|
|
ratings = [0]*len(label)
|
|
for q in qs:
|
|
for q in qs:
|
|
- ratings[label.index(q.month)] = q.total_ratings
|
|
|
|
|
|
+ ratings[label.index(q.week)] = q.total_ratings
|
|
star_ratings.append(ratings)
|
|
star_ratings.append(ratings)
|
|
response = {
|
|
response = {
|
|
- 'month': label,
|
|
|
|
|
|
+ 'label': label,
|
|
'total_reviews': total_review,
|
|
'total_reviews': total_review,
|
|
'one_star': star_ratings[0],
|
|
'one_star': star_ratings[0],
|
|
'two_star': star_ratings[1],
|
|
'two_star': star_ratings[1],
|