|
@@ -40,122 +40,6 @@ def last_data(date, location_id):
|
|
|
ratings[r.get('star_rating')-1] = r.get('total')
|
|
|
return ratings
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-def monthly_review_count(location_id):
|
|
|
- sql = f'''
|
|
|
- SELECT MONTHNAME(create_time) as month, star_rating, COALESCE(COUNT(*), 0) as total_review
|
|
|
- FROM review_review
|
|
|
- WHERE DATE_ADD(DATE_ADD(CURRENT_TIMESTAMP(),
|
|
|
- INTERVAL -1 YEAR), INTERVAL 15 DAY) <= create_time and location_id={location_id}
|
|
|
- GROUP BY MONTH(create_time), star_rating
|
|
|
- ORDER BY create_time;
|
|
|
- '''
|
|
|
- with connection.cursor() as cursor:
|
|
|
- cursor.execute(sql)
|
|
|
- rows = cursor.fetchall()
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- row_dict = {row[0] + '_' + str(row[1]): row[2] for row in rows}
|
|
|
-
|
|
|
- labels = []
|
|
|
- for row in rows:
|
|
|
- if row[0] not in labels:
|
|
|
- labels.append(row[0])
|
|
|
- row_lists = []
|
|
|
- for i in range(1, 6):
|
|
|
- row = [row_dict.get(m+'_'+str(i), 0) for m in labels]
|
|
|
- row_lists.append(row)
|
|
|
- return labels, row_lists
|
|
|
-
|
|
|
|
|
|
def get_review_count_by_week(location_id):
|
|
|
now = timezone.now()
|
|
@@ -173,10 +57,10 @@ def get_review_count_by_week(location_id):
|
|
|
with connection.cursor() as cursor:
|
|
|
cursor.execute(sql)
|
|
|
rows = cursor.fetchall()
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- row_dict = {str(row[0]) + '_' + str(row[1]): row[2] for row in rows}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ row_dict = {(row[0], row[1]): row[2] for row in rows}
|
|
|
|
|
|
labels = []
|
|
|
for row in rows:
|
|
@@ -184,7 +68,7 @@ def get_review_count_by_week(location_id):
|
|
|
labels.append(row[0])
|
|
|
star_ratings = []
|
|
|
for i in range(1, 6):
|
|
|
- row = [row_dict.get(str(w) + '_' + str(i), 0) for w in labels]
|
|
|
+ row = [row_dict.get((w, i), 0) for w in labels]
|
|
|
star_ratings.append(row)
|
|
|
total_review = list(np.sum(star_ratings, axis=0))
|
|
|
|
|
@@ -219,9 +103,9 @@ def get_review_count_by_month(location_id):
|
|
|
cursor.execute(sql)
|
|
|
rows = cursor.fetchall()
|
|
|
|
|
|
-
|
|
|
-
|
|
|
- row_dict = {str(row[0]) + '_' + str(row[1]): row[2] for row in rows}
|
|
|
+
|
|
|
+
|
|
|
+ row_dict = {(row[0], row[1]): row[2] for row in rows}
|
|
|
|
|
|
labels = []
|
|
|
for row in rows:
|
|
@@ -229,7 +113,7 @@ def get_review_count_by_month(location_id):
|
|
|
labels.append(row[0])
|
|
|
star_ratings = []
|
|
|
for i in range(1, 6):
|
|
|
- row = [row_dict.get(str(m) + '_' + str(i), 0) for m in labels]
|
|
|
+ row = [row_dict.get((m, i), 0) for m in labels]
|
|
|
star_ratings.append(row)
|
|
|
total_review = list(np.sum(star_ratings, axis=0))
|
|
|
|