|
@@ -1,11 +1,13 @@
|
|
|
|
+from django.utils import timezone
|
|
from review.models import Review
|
|
from review.models import Review
|
|
|
|
|
|
|
|
|
|
def get_review_count_by_month(location_id):
|
|
def get_review_count_by_month(location_id):
|
|
|
|
+ day = timezone.now().day
|
|
sql = f'''
|
|
sql = f'''
|
|
SELECT review_id, MONTHNAME(create_time) as month, COUNT(review_id) as total_review
|
|
SELECT review_id, MONTHNAME(create_time) as month, COUNT(review_id) as total_review
|
|
FROM review_review
|
|
FROM review_review
|
|
- WHERE DATE_ADD(CURRENT_TIMESTAMP(),INTERVAL -1 YEAR) <= create_time and location_id={location_id}
|
|
|
|
|
|
+ WHERE DATE_ADD(DATE_ADD(CURRENT_TIMESTAMP(),INTERVAL -1 YEAR), INTERVAL {day} DAY) <= create_time and location_id={location_id}
|
|
GROUP BY MONTH(create_time)
|
|
GROUP BY MONTH(create_time)
|
|
ORDER BY DATE(create_time)
|
|
ORDER BY DATE(create_time)
|
|
'''
|
|
'''
|
|
@@ -17,7 +19,7 @@ def get_review_count_by_month(location_id):
|
|
sql = f'''
|
|
sql = f'''
|
|
SELECT review_id, MONTHNAME(create_time) as month, COUNT(review_id) as total_ratings
|
|
SELECT review_id, MONTHNAME(create_time) as month, COUNT(review_id) as total_ratings
|
|
FROM review_review
|
|
FROM review_review
|
|
- WHERE DATE_ADD(CURRENT_TIMESTAMP(),INTERVAL -1 YEAR) <= create_time
|
|
|
|
|
|
+ WHERE DATE_ADD(DATE_ADD(CURRENT_TIMESTAMP(),INTERVAL -1 YEAR), INTERVAL {day} DAY) <= 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)
|
|
ORDER BY DATE(create_time)
|
|
@@ -40,10 +42,11 @@ def get_review_count_by_month(location_id):
|
|
|
|
|
|
|
|
|
|
def get_review_count_by_week(location_id):
|
|
def get_review_count_by_week(location_id):
|
|
|
|
+ day = timezone.now().weekday()
|
|
sql = f'''
|
|
sql = f'''
|
|
SELECT review_id, WEEK(create_time) as week, 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
|
|
- WHERE DATE_ADD(CURRENT_TIMESTAMP(),INTERVAL -1 YEAR) <= create_time and location_id={location_id}
|
|
|
|
|
|
+ WHERE DATE_ADD(DATE_ADD(CURRENT_TIMESTAMP(),INTERVAL -1 YEAR), INTERVAL {day} DAY) <= create_time and location_id={location_id}
|
|
GROUP BY WEEK(create_time)
|
|
GROUP BY WEEK(create_time)
|
|
ORDER BY DATE(create_time)
|
|
ORDER BY DATE(create_time)
|
|
'''
|
|
'''
|
|
@@ -55,7 +58,7 @@ def get_review_count_by_week(location_id):
|
|
sql = f'''
|
|
sql = f'''
|
|
SELECT review_id, WEEK(create_time) as week, 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 DATE_ADD(CURRENT_TIMESTAMP(),INTERVAL -1 YEAR) <= create_time
|
|
|
|
|
|
+ WHERE DATE_ADD(DATE_ADD(CURRENT_TIMESTAMP(),INTERVAL -1 YEAR), INTERVAL {day} DAY) <= create_time
|
|
and location_id={location_id} and star_rating={i}
|
|
and location_id={location_id} and star_rating={i}
|
|
GROUP BY WEEK(create_time)
|
|
GROUP BY WEEK(create_time)
|
|
ORDER BY DATE(create_time)
|
|
ORDER BY DATE(create_time)
|