浏览代码

separate positive and negative reviews in manager dashboard

Mohidul Islam 4 年之前
父节点
当前提交
937fc49e04
共有 3 个文件被更改,包括 62 次插入28 次删除
  1. 12 12
      manager/templates/manager-dashboard.html
  2. 8 4
      manager/views.py
  3. 42 12
      user/utils.py

+ 12 - 12
manager/templates/manager-dashboard.html

@@ -6,13 +6,13 @@
 <div class="row">
 
   <div class="col-sm-6 col-md-6">
-      <div class="card text-white bg-secondary mb-3">
+      <div class="card text-white mb-3" style="background: linear-gradient(to bottom left, #cc3300 0%, #ffcc00 100%);">
       <div class="card-header"><h5 class="card-title">Google <span><i class="fa fa-google" aria-hidden="true"></i></span></h5></div>
         <div class="card-body">
           <table class="table">
             <tr>
               <td>
-                <i class="fa fa-pencil-square-o" aria-hidden="true"></i> Reviews
+                <i class="fa fa-pencil-square-o" aria-hidden="true"></i> Review Count
               </td>
               <td>
                 <i class="fa fa-thumbs-o-up" aria-hidden="true"></i> Positive
@@ -22,13 +22,13 @@
               </td>
               </tr>
               <td>This month (so far)</td>
-              <td>{{ google_this_month }}</td>
-              <td>{{ google_this_month }}</td>
+              <td>{{ google_this_month_pos }}</td>
+              <td>{{ google_this_month_neg }}</td>
             </tr>
             <tr>
               <td>Last month</td>
-              <td>{{ google_last_month }}</td>
-              <td>{{ google_last_month }}</td>
+              <td>{{ google_last_month_pos }}</td>
+              <td>{{ google_last_month_neg }}</td>
             </tr>
           </table>
         </div>
@@ -54,13 +54,13 @@
 <!--  </div>-->
 
   <div class="col-sm-6 col-md-6">
-      <div class="card text-white bg-primary mb-3">
+      <div class="card text-white mb-3" style="background: linear-gradient(to bottom left, #000099 0%, #00ccff 100%);">
       <div class="card-header"><h5 class="card-title">Facebook <span><i class="fa fa-facebook" aria-hidden="true"></i></span></h5></div>
         <div class="card-body">
           <table class="table">
             <tr>
               <td>
-                <i class="fa fa-pencil-square-o" aria-hidden="true"></i> Reviews
+                <i class="fa fa-pencil-square-o" aria-hidden="true"></i> Review Count
               </td>
               <td>
                 <i class="fa fa-thumbs-o-up" aria-hidden="true"></i> Positive
@@ -71,13 +71,13 @@
             </tr>
             <tr>
               <td>This month (so far)</td>
-              <td>{{ facebook_this_month }}</td>
-              <td>{{ facebook_this_month }}</td>
+              <td>{{ facebook_this_month_pos }}</td>
+              <td>{{ facebook_this_month_neg }}</td>
             </tr>
             <tr>
               <td>Last month</td>
-              <td>{{ facebook_last_month }}</td>
-              <td>{{ facebook_last_month }}</td>
+              <td>{{ facebook_last_month_pos }}</td>
+              <td>{{ facebook_last_month_neg }}</td>
             </tr>
           </table>
         </div>

+ 8 - 4
manager/views.py

@@ -88,10 +88,14 @@ class LocationAnalytics(LoginRequiredMixin, View):
         facebook_report = get_facebook_report(location_id)
         context = {
             'location': location,
-            'google_this_month': google_report.get('this_month'),
-            'google_last_month': google_report.get('last_month'),
-            'facebook_this_month': facebook_report.get('this_month'),
-            'facebook_last_month': facebook_report.get('last_month'),
+            'google_this_month_pos': google_report.get('this_month_pos'),
+            'google_last_month_pos': google_report.get('last_month_pos'),
+            'facebook_this_month_pos': facebook_report.get('this_month_pos'),
+            'facebook_last_month_pos': facebook_report.get('last_month_pos'),
+            'google_this_month_neg': google_report.get('this_month_neg'),
+            'google_last_month_neg': google_report.get('last_month_neg'),
+            'facebook_this_month_neg': facebook_report.get('this_month_neg'),
+            'facebook_last_month_neg': facebook_report.get('last_month_neg')
         }
         return render(request, 'manager-dashboard.html', context=context)
 

+ 42 - 12
user/utils.py

@@ -32,19 +32,33 @@ def get_google_review_report(location_id):
 
     reviews = Review.objects.all()
 
-    this_month = reviews.filter(
+    this_month_pos = reviews.filter(
         location_id=location_id,
-        create_time__range=(beginning_of_month, now)
+        create_time__range=(beginning_of_month, now),
+        star_rating__gte=4
+    ).count()
+    this_month_neg = reviews.filter(
+        location_id=location_id,
+        create_time__range=(beginning_of_month, now),
+        star_rating__lte=3
     ).count()
 
-    last_month = reviews.filter(
+    last_month_pos = reviews.filter(
         location_id=location_id,
-        create_time__range=(beginning_of_last_month, beginning_of_month)
+        create_time__range=(beginning_of_last_month, beginning_of_month),
+        star_rating__gte=4
+    ).count()
+    last_month_neg = reviews.filter(
+        location_id=location_id,
+        create_time__range=(beginning_of_last_month, beginning_of_month),
+        star_rating__lt=4
     ).count()
 
     return {
-        'this_month': this_month,
-        'last_month': last_month
+        'this_month_pos': this_month_pos,
+        'last_month_pos': last_month_pos,
+        'this_month_neg': this_month_neg,
+        'last_month_neg': last_month_neg
     }
 
 
@@ -55,19 +69,35 @@ def get_facebook_report(location_id):
 
     reviews = FacebookReview.objects.all()
 
-    this_month = reviews.filter(
+    this_month_pos = reviews.filter(
+        page__location_id=location_id,
+        create_time__range=(beginning_of_month, now),
+        recommendation_type=True
+    ).count()
+
+    last_month_pos = reviews.filter(
         page__location_id=location_id,
-        create_time__range=(beginning_of_month, now)
+        create_time__range=(beginning_of_last_month, beginning_of_month),
+        recommendation_type=True
+    ).count()
+
+    this_month_neg = reviews.filter(
+        page__location_id=location_id,
+        create_time__range=(beginning_of_month, now),
+        recommendation_type=False
     ).count()
 
-    last_month = reviews.filter(
+    last_month_neg = reviews.filter(
         page__location_id=location_id,
-        create_time__range=(beginning_of_last_month, beginning_of_month)
+        create_time__range=(beginning_of_last_month, beginning_of_month),
+        recommendation_type=False
     ).count()
 
     return {
-        'this_month': this_month,
-        'last_month': last_month
+        'this_month_pos': this_month_pos,
+        'last_month_pos': last_month_pos,
+        'this_month_neg': this_month_neg,
+        'last_month_neg': last_month_neg
     }