analytics.py 691 B

123456789101112131415161718192021
  1. from django.db.models import Count
  2. from django.utils import timezone
  3. from .models import YelpReview
  4. from name_extractor.utils import get_all_people_names
  5. def get_staff_names(reviews):
  6. all_names = []
  7. for review in reviews:
  8. names = list(get_all_people_names(review.comment))
  9. all_names.extend(names)
  10. return list(set(all_names))
  11. def get_weekly_summary(location_id):
  12. date = timezone.now() - timezone.timedelta(days=100)
  13. reviews = YelpReview.objects.filter(location__location_id=location_id, date_posted__gte=date)
  14. rating = reviews.values('rating').annotate(total=Count('rating'))
  15. names = get_staff_names(reviews)
  16. return reviews, rating, names