|
@@ -106,39 +106,35 @@ def get_yelp_review_report(location_id):
|
|
|
beginning_of_month = now.replace(day=1, hour=0, minute=0, second=0)
|
|
|
beginning_of_last_month = now - timezone.timedelta(days=now.day + 31)
|
|
|
|
|
|
- pos = YelpReview.objects.filter(
|
|
|
+ reviews = YelpReview.objects.all()
|
|
|
+
|
|
|
+ this_month_pos = reviews.filter(
|
|
|
location__location_id=location_id,
|
|
|
date_posted__range=(beginning_of_month, now),
|
|
|
- rating__gte=3
|
|
|
+ rating__gte=4
|
|
|
).count()
|
|
|
- neg = YelpReview.objects.filter(
|
|
|
+ this_month_neg = reviews.filter(
|
|
|
location__location_id=location_id,
|
|
|
date_posted__range=(beginning_of_month, now),
|
|
|
- rating__lte=2
|
|
|
+ rating__lte=3
|
|
|
).count()
|
|
|
- pos_last_month = YelpReview.objects.filter(
|
|
|
+
|
|
|
+ last_month_pos = reviews.filter(
|
|
|
location__location_id=location_id,
|
|
|
date_posted__range=(beginning_of_last_month, beginning_of_month),
|
|
|
- rating__gte=3
|
|
|
+ rating__gte=4
|
|
|
).count()
|
|
|
- neg_last_month = YelpReview.objects.filter(
|
|
|
+ last_month_neg = reviews.filter(
|
|
|
location__location_id=location_id,
|
|
|
date_posted__range=(beginning_of_last_month, beginning_of_month),
|
|
|
- rating__lte=2
|
|
|
+ rating__lt=4
|
|
|
).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 {
|
|
|
- 'positive': pos,
|
|
|
- 'positive_growth': pos_growth,
|
|
|
- 'negative': neg,
|
|
|
- 'negative_growth': neg_growth,
|
|
|
- 'total': total,
|
|
|
- 'total_growth': total_growth
|
|
|
+ 'this_month_pos': this_month_pos,
|
|
|
+ 'last_month_pos': last_month_pos,
|
|
|
+ 'this_month_neg': this_month_neg,
|
|
|
+ 'last_month_neg': last_month_neg
|
|
|
}
|
|
|
|
|
|
|
|
@@ -154,13 +150,13 @@ def get_this_month_analytics(location_id):
|
|
|
.annotate(total=Count('create_time__day'))
|
|
|
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(
|
|
|
page__location_id=location_id,
|
|
@@ -173,16 +169,18 @@ def get_this_month_analytics(location_id):
|
|
|
label = []
|
|
|
facebook = []
|
|
|
google = []
|
|
|
+ yelp = []
|
|
|
for day in range(1, now.day+1):
|
|
|
label.append(day)
|
|
|
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))
|
|
|
|
|
|
return {
|
|
|
'label': label,
|
|
|
'google': google,
|
|
|
'facebook': facebook,
|
|
|
+ 'yelp': yelp
|
|
|
}
|
|
|
|
|
|
|