|
@@ -30,39 +30,21 @@ def get_google_review_report(location_id):
|
|
beginning_of_month = now.replace(day=1, hour=0, minute=0, second=0)
|
|
beginning_of_month = now.replace(day=1, hour=0, minute=0, second=0)
|
|
beginning_of_last_month = now - timezone.timedelta(days=now.day + 31)
|
|
beginning_of_last_month = now - timezone.timedelta(days=now.day + 31)
|
|
|
|
|
|
- pos = Review.objects.filter(
|
|
|
|
- location_id=location_id,
|
|
|
|
- create_time__range=(beginning_of_month, now),
|
|
|
|
- star_rating__gte=3
|
|
|
|
- ).count()
|
|
|
|
- neg = Review.objects.filter(
|
|
|
|
- location_id=location_id,
|
|
|
|
- create_time__range=(beginning_of_month, now),
|
|
|
|
- star_rating__lte=2
|
|
|
|
- ).count()
|
|
|
|
- pos_last_month = Review.objects.filter(
|
|
|
|
|
|
+ reviews = Review.objects.all()
|
|
|
|
+
|
|
|
|
+ this_month = reviews.filter(
|
|
location_id=location_id,
|
|
location_id=location_id,
|
|
- create_time__range=(beginning_of_last_month, beginning_of_month),
|
|
|
|
- star_rating__gte=3
|
|
|
|
|
|
+ create_time__range=(beginning_of_month, now)
|
|
).count()
|
|
).count()
|
|
- neg_last_month = Review.objects.filter(
|
|
|
|
|
|
+
|
|
|
|
+ last_month = reviews.filter(
|
|
location_id=location_id,
|
|
location_id=location_id,
|
|
- create_time__range=(beginning_of_last_month, beginning_of_month),
|
|
|
|
- star_rating__lte=2
|
|
|
|
|
|
+ create_time__range=(beginning_of_last_month, beginning_of_month)
|
|
).count()
|
|
).count()
|
|
- pos_growth = 'inf' if pos_last_month == 0 else round(((((pos / now.day) * 30) - pos_last_month) / pos_last_month) * 100, 2)
|
|
|
|
- neg_growth = 'inf' if neg_last_month == 0 else round(((((neg / now.day) * 30) - neg_last_month) / neg_last_month) * 100, 2)
|
|
|
|
- total = pos + neg
|
|
|
|
- last_month_total = pos_last_month + neg_last_month
|
|
|
|
- total_growth = 'inf' if last_month_total == 0 else round(((((total / now.day) * 30) - last_month_total) / last_month_total) * 100, 2)
|
|
|
|
|
|
|
|
return {
|
|
return {
|
|
- 'positive': pos,
|
|
|
|
- 'positive_growth': pos_growth,
|
|
|
|
- 'negative': neg,
|
|
|
|
- 'negative_growth': neg_growth,
|
|
|
|
- 'total': total,
|
|
|
|
- 'total_growth': total_growth
|
|
|
|
|
|
+ 'this_month': this_month,
|
|
|
|
+ 'last_month': last_month
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -71,39 +53,21 @@ def get_facebook_report(location_id):
|
|
beginning_of_month = now.replace(day=1, hour=0, minute=0, second=0)
|
|
beginning_of_month = now.replace(day=1, hour=0, minute=0, second=0)
|
|
beginning_of_last_month = now - timezone.timedelta(days=now.day + 31)
|
|
beginning_of_last_month = now - timezone.timedelta(days=now.day + 31)
|
|
|
|
|
|
- pos = FacebookReview.objects.filter(
|
|
|
|
- page__location_id=location_id,
|
|
|
|
- create_time__range=(beginning_of_month, now),
|
|
|
|
- recommendation_type=True
|
|
|
|
- ).count()
|
|
|
|
- neg = FacebookReview.objects.filter(
|
|
|
|
- page__location_id=location_id,
|
|
|
|
- create_time__range=(beginning_of_month, now),
|
|
|
|
- recommendation_type=False
|
|
|
|
- ).count()
|
|
|
|
- pos_last_month = FacebookReview.objects.filter(
|
|
|
|
|
|
+ reviews = FacebookReview.objects.all()
|
|
|
|
+
|
|
|
|
+ this_month = reviews.filter(
|
|
page__location_id=location_id,
|
|
page__location_id=location_id,
|
|
- create_time__range=(beginning_of_last_month, beginning_of_month),
|
|
|
|
- recommendation_type=True
|
|
|
|
|
|
+ create_time__range=(beginning_of_month, now)
|
|
).count()
|
|
).count()
|
|
- neg_last_month = FacebookReview.objects.filter(
|
|
|
|
|
|
+
|
|
|
|
+ last_month = reviews.filter(
|
|
page__location_id=location_id,
|
|
page__location_id=location_id,
|
|
- create_time__range=(beginning_of_last_month, beginning_of_month),
|
|
|
|
- recommendation_type=False
|
|
|
|
|
|
+ create_time__range=(beginning_of_last_month, beginning_of_month)
|
|
).count()
|
|
).count()
|
|
- pos_growth = 'inf' if pos_last_month == 0 else round(((((pos / now.day) * 30) - pos_last_month) / pos_last_month) * 100, 2)
|
|
|
|
- neg_growth = 'inf' if neg_last_month == 0 else round(((((neg / now.day) * 30) - neg_last_month) / neg_last_month) * 100, 2)
|
|
|
|
- total = pos + neg
|
|
|
|
- last_month_total = pos_last_month + neg_last_month
|
|
|
|
- total_growth = 'inf' if last_month_total == 0 else round(((((total / now.day) * 30) - last_month_total) / last_month_total) * 100, 2)
|
|
|
|
|
|
|
|
return {
|
|
return {
|
|
- 'positive': pos,
|
|
|
|
- 'positive_growth': pos_growth,
|
|
|
|
- 'negative': neg,
|
|
|
|
- 'negative_growth': neg_growth,
|
|
|
|
- 'total': total,
|
|
|
|
- 'total_growth': total_growth
|
|
|
|
|
|
+ 'this_month': this_month,
|
|
|
|
+ 'last_month': last_month
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -160,13 +124,13 @@ def get_this_month_analytics(location_id):
|
|
.annotate(total=Count('create_time__day'))
|
|
.annotate(total=Count('create_time__day'))
|
|
google_qs_dict = {q['create_time__day']: q['total'] for q in google_qs}
|
|
google_qs_dict = {q['create_time__day']: q['total'] for q in google_qs}
|
|
|
|
|
|
- yelp_qs = YelpReview.objects.filter(
|
|
|
|
- location__location_id=location_id,
|
|
|
|
- date_posted__range=(beginning_of_month, now),
|
|
|
|
- )\
|
|
|
|
- .values('date_posted__day')\
|
|
|
|
- .annotate(total=Count('date_posted__day'))
|
|
|
|
- yelp_qs_dict = {q['date_posted__day']: q['total'] for q in yelp_qs}
|
|
|
|
|
|
+ # yelp_qs = YelpReview.objects.filter(
|
|
|
|
+ # location__location_id=location_id,
|
|
|
|
+ # date_posted__range=(beginning_of_month, now),
|
|
|
|
+ # )\
|
|
|
|
+ # .values('date_posted__day')\
|
|
|
|
+ # .annotate(total=Count('date_posted__day'))
|
|
|
|
+ # yelp_qs_dict = {q['date_posted__day']: q['total'] for q in yelp_qs}
|
|
|
|
|
|
facebook_qs = FacebookReview.objects.filter(
|
|
facebook_qs = FacebookReview.objects.filter(
|
|
page__location_id=location_id,
|
|
page__location_id=location_id,
|
|
@@ -178,19 +142,17 @@ def get_this_month_analytics(location_id):
|
|
|
|
|
|
label = []
|
|
label = []
|
|
facebook = []
|
|
facebook = []
|
|
- yelp = []
|
|
|
|
google = []
|
|
google = []
|
|
for day in range(1, now.day+1):
|
|
for day in range(1, now.day+1):
|
|
label.append(day)
|
|
label.append(day)
|
|
facebook.append(facebook_qs_dict.get(day, 0))
|
|
facebook.append(facebook_qs_dict.get(day, 0))
|
|
- yelp.append(yelp_qs_dict.get(day, 0))
|
|
|
|
|
|
+ # yelp.append(yelp_qs_dict.get(day, 0))
|
|
google.append(google_qs_dict.get(day, 0))
|
|
google.append(google_qs_dict.get(day, 0))
|
|
|
|
|
|
return {
|
|
return {
|
|
'label': label,
|
|
'label': label,
|
|
'google': google,
|
|
'google': google,
|
|
'facebook': facebook,
|
|
'facebook': facebook,
|
|
- 'yelp': yelp
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|