Quellcode durchsuchen

added yelp data to the manager dashboard

Mohidul Islam vor 4 Jahren
Ursprung
Commit
ee2d7d3cc7
4 geänderte Dateien mit 85 neuen und 60 gelöschten Zeilen
  1. 0 1
      dashboard/static/user-dashboard.css
  2. 56 31
      manager/templates/manager-dashboard.html
  3. 4 1
      manager/views.py
  4. 25 27
      user/utils.py

+ 0 - 1
dashboard/static/user-dashboard.css

@@ -89,7 +89,6 @@ body {
     vertical-align: top;
     border-top: 0px solid #dee2e6;
     color: white;
-    font-size: larger;
     font-family: serif;
     font-weight: bold;
 }

+ 56 - 31
manager/templates/manager-dashboard.html

@@ -5,7 +5,7 @@
 <!--cart-->
 <div class="row">
 
-  <div class="col-sm-6 col-md-6">
+  <div class="col-sm-4 col-md-4">
       <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">
@@ -15,10 +15,10 @@
                 <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 (5* & 4*)
+                <i class="fa fa-thumbs-o-up" aria-hidden="true"></i> Positive
               </td>
               <td>
-                <i class="fa fa-thumbs-o-down" aria-hidden="true"></i> Negative (3* & Less)
+                <i class="fa fa-thumbs-o-down" aria-hidden="true"></i> Negative
               </td>
               </tr>
               <td>This month (so far)</td>
@@ -35,27 +35,41 @@
       </div>
   </div>
 
-<!--  <div class="col-sm-6 col-md-4">-->
-<!--      <div class="card text-white bg-danger mb-3">-->
-<!--      <div class="card-header"><h5 class="card-title">Yelp <span><i class="fa fa-yelp" 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>  Total Review</td>-->
-<!--              <td>{{ yelp_total }}</td>-->
-<!--            </tr>-->
-<!--            <tr>-->
-<!--              <td><i class="fa fa-line-chart" aria-hidden="true"></i>  Growth</td>-->
-<!--              <td>{{ yelp_total_growth }}%</td>-->
-<!--            </tr>-->
-<!--          </table>-->
-<!--        </div>-->
-<!--      </div>-->
-<!--  </div>-->
+  <div class="col-sm-4 col-md-4">
+    <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> Review Count
+            </td>
+            <td>
+              <i class="fa fa-thumbs-o-up" aria-hidden="true"></i> Positive
+            </td>
+            <td>
+              <i class="fa fa-thumbs-o-down" aria-hidden="true"></i> Negative
+            </td>
+          </tr>
+          <tr>
+            <td>This month (so far)</td>
+            <td>{{ facebook_this_month_pos }}</td>
+            <td>{{ facebook_this_month_neg }}</td>
+          </tr>
+          <tr>
+            <td>Last month</td>
+            <td>{{ facebook_last_month_pos }}</td>
+            <td>{{ facebook_last_month_neg }}</td>
+          </tr>
+        </table>
+      </div>
+    </div>
+  </div>
+
 
-  <div class="col-sm-6 col-md-6">
-      <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="col-sm-4 col-md-4">
+      <div class="card text-white mb-3" style="background: linear-gradient(to bottom left, #ff0000 0%, #ff9999 100%);">
+      <div class="card-header"><h5 class="card-title">Yelp <span><i class="fa fa-yelp" aria-hidden="true"></i></span></h5></div>
         <div class="card-body">
           <table class="table">
             <tr>
@@ -63,29 +77,32 @@
                 <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> Recommended
+                <i class="fa fa-thumbs-o-up" aria-hidden="true"></i> Positive
               </td>
               <td>
-                <i class="fa fa-thumbs-o-down" aria-hidden="true"></i> Not Recommended
+                <i class="fa fa-thumbs-o-down" aria-hidden="true"></i> Negative
               </td>
             </tr>
             <tr>
               <td>This month (so far)</td>
-              <td>{{ facebook_this_month_pos }}</td>
-              <td>{{ facebook_this_month_neg }}</td>
+              <td>{{ yelp.this_month_pos }}</td>
+              <td>{{ yelp.this_month_neg }}</td>
             </tr>
             <tr>
               <td>Last month</td>
-              <td>{{ facebook_last_month_pos }}</td>
-              <td>{{ facebook_last_month_neg }}</td>
+              <td>{{ yelp.last_month_pos }}</td>
+              <td>{{ yelp.last_month_neg }}</td>
             </tr>
           </table>
         </div>
       </div>
   </div>
-
 </div>
-
+<div style="text-align: center">
+  <span style="font-size: small; color: darkgrey;">
+    <b>NB: For Google and Yelp 5* & 4* is considered to be a positive review. And less than 4* is considered a negative review.</b>
+  </span>
+</div>
 <!--    canvas-->
   <canvas class="my-4" id="myChart" width="900" height="300"></canvas>
  </div>
@@ -130,6 +147,14 @@
                     backgroundColor: 'rgb(0, 51, 204)',
                     borderWidth: 1,
                     fill: false
+                },
+                {
+                    label: 'Yelp',
+                    data: data.yelp,
+                    borderColor: 'rgb(255, 28, 28)',
+                    backgroundColor: 'rgb(255, 94, 94)',
+                    borderWidth: 1,
+                    fill: false
                 }]
             },
             options: {

+ 4 - 1
manager/views.py

@@ -17,6 +17,7 @@ from django.contrib.auth.mixins import LoginRequiredMixin, PermissionRequiredMix
 from user.utils import (
     get_google_review_report,
     get_facebook_report,
+    get_yelp_review_report,
     date_str2datetime
 )
 from .forms import ImportStaffSpreadSheet
@@ -84,6 +85,7 @@ class LocationAnalytics(LoginRequiredMixin, View):
         location = Location.objects.get(pk=location_id)
         google_report = get_google_review_report(location_id)
         facebook_report = get_facebook_report(location_id)
+        yelp_report = get_yelp_review_report(location_id)
         context = {
             'location': location,
             'google_this_month_pos': google_report.get('this_month_pos'),
@@ -93,7 +95,8 @@ class LocationAnalytics(LoginRequiredMixin, View):
             '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')
+            'facebook_last_month_neg': facebook_report.get('last_month_neg'),
+            'yelp': yelp_report
         }
         return render(request, 'manager-dashboard.html', context=context)
 

+ 25 - 27
user/utils.py

@@ -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
     }