ソースを参照

Added weekly summary with bad reviews

Mohidul Islam 5 年 前
コミット
b2f9a0c96b

+ 142 - 0
analytics/templates/weekly_report.html

@@ -0,0 +1,142 @@
+<!DOCTYPE html>
+<html>
+  <head>
+    <style>
+      .customers {
+        font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;
+        border-collapse: collapse;
+        width: 90%;
+      }
+
+      .customers td, .customers th {
+        border: 1px solid rgb(41, 39, 39);
+        padding: 8px;
+        text-align: center;
+      }
+
+      .customers tr:nth-child(even){background-color: #f2f2f2;}
+
+      .customers tr:hover {background-color: #ddd;}
+
+      .customers th {
+        padding-top: 12px;
+        padding-bottom: 12px;
+        text-align: left;
+        background-color: #4e5253;
+        color: rgb(255, 255, 255);
+        text-align: center;
+      }
+
+      table{
+        table-layout: fixed;
+      }
+
+    </style>
+  </head>
+  <body>
+    <div align="center" style="margin-top: 25px;">
+      <img src="https://ercare24.com/wp-content/uploads/2016/07/signature-care-resized-e1462918690585.png" alt="Avatar" class="image" width=50% >
+      <h2 style="text-align:center;">Last Week Review Report</h2>
+    </div>
+    <div align="center">
+      <table class="customers">
+      <tr>
+        <th style="width: 25%;">Platform</th>
+        <th style="width: 25%;">Ratings</th>
+        <th>Name Mentioned</th>
+      </tr>
+
+      <!-- Google Reviews Summary -->
+
+      <tr>
+        <td>Google</td>
+        <td>
+          {% for r in google_ratings %}
+            {% if r.star_rating < 3 %}
+              <span style="color: red; font-weight: bold;">{{ r.star_rating }}* star: {{ r.total }}</span> </br>
+            {% else %}
+              <span>{{ r.star_rating }}* star: {{ r.total }}</span> </br>
+            {% endif %}
+          {% endfor %}
+        </td>
+        <td>
+          {% for s_n in google_staffs %}
+            {{ s_n }}, 
+          {% endfor %}
+        </td>
+      </tr>      
+      <!-- Yelp Reviews Summary -->
+
+      <tr>
+        <td>Yelp</td>
+        <td>
+          <!-- {% for r in google_ratings %}
+            {% if r.star_rating < 3 %}
+              <span style="color: red; font-weight: bold;">{{ r.star_rating }}* star: {{ r.total }}</span> </br>
+            {% else %}
+              <span>{{ r.star_rating }}* star: {{ r.total }}</span> </br>
+            {% endif %}
+          {% endfor %} -->
+        </td>
+        <td>
+          {% for s_n in google_staffs %}
+            {{ s_n }}, 
+          {% endfor %}
+        </td>
+      </tr>      
+      <!-- Facebook Reviews Summary -->
+
+      <tr>
+        <td>Facebook</td>
+        <td>
+          <!-- {% for r in google_ratings %}
+            {% if r.star_rating < 3 %}
+              <span style="color: red; font-weight: bold;">{{ r.star_rating }}* star: {{ r.total }}</span> </br>
+            {% else %}
+              <span>{{ r.star_rating }}* star: {{ r.total }}</span> </br>
+            {% endif %}
+          {% endfor %} -->
+        </td>
+        <td>
+          {% for s_n in google_staffs %}
+            {{ s_n }}, 
+          {% endfor %}
+        </td>
+      </tr>
+    </table>
+
+    <h5>Bad Reviews</h5>
+    <table class="customers">
+      <tr>
+        <th style="width: 25%;">Platform</th>
+        <th>Review</th>
+      </tr>
+      <!-- Google Bad reviews list -->
+
+      <tr>
+        <td>Google</td>
+        {% if google_bad_reviews.count > 0 %}
+        <td style="width: 100%;">
+          <table border="1px"  style="border-collapse: collapse;margin: -9px">
+            <tr style="background-color: rgb(179, 177, 177);">
+              <td style="width: 20%;">Reviewer Name</td>
+              <td style="width: 70%;">Comment</td>
+              <td style="width: 10%;">Rating</td>
+            </tr> 
+          {% for review in google_bad_reviews %}
+            <tr>
+              <td>{{ review.reviewer_name }}</td>
+              <td>{{ review.comment }}</td>
+              <td>{{ review.star_rating }}*</td>
+            </tr> 
+          {% endfor %}
+        </table>
+        </td>
+        {% else %}
+        <td>No bad reviews has been posted in google!</td>
+        {% endif %} 
+      </tr>    
+    </table>
+    </div>
+  </body>
+</html>

+ 7 - 1
analytics/urls.py

@@ -1,8 +1,14 @@
 from django.urls import path
-from .views import ChartDataByMonth, AnalyticsData, monthly_report
+from .views import (
+    ChartDataByMonth,
+    AnalyticsData,
+    monthly_report,
+    weekly_report
+)
 
 urlpatterns = [
     path('', AnalyticsData.as_view(), name='analytics'),
     path('analytic-data/', ChartDataByMonth.as_view()),
     path('monthly-report/<location_id>', monthly_report),
+    path('weekly-report/<location_id>', weekly_report),
 ]

+ 13 - 0
analytics/utils.py

@@ -16,6 +16,19 @@ def last_month_reviews(location_id):
     return ratings
 
 
+def weekly_reviews_summary(location_id):
+    now = timezone.now()
+    date = now - timezone.timedelta(days=7)
+    reviews = Review.objects.filter(
+        create_time__gte=date,
+        location_id=location_id
+    )
+    ratings = reviews.values('star_rating')\
+        .annotate(total=Count('star_rating'))
+
+    return reviews, ratings
+
+
 def last_data(date, location_id):
     res = Review.objects.filter(create_time__gte=date, location_id=location_id).values('star_rating')\
         .annotate(total=Count('star_rating')).order_by('star_rating')

+ 22 - 1
analytics/views.py

@@ -10,7 +10,8 @@ from name_extractor.models import Staff
 from .utils import (
     get_review_count_by_month,
     get_review_count_by_week,
-    last_month_reviews
+    last_month_reviews,
+    weekly_reviews_summary
 )
 
 
@@ -43,3 +44,23 @@ def monthly_report(requests, location_id):
         'staffs': staffs
     }
     return render(requests, 'last_month_report.html', context)
+
+
+def weekly_report(requests, location_id):
+    g_reviews, g_ratings = weekly_reviews_summary(location_id=location_id)
+
+    g_staff_names = [
+        'montgomery', 'sarah', 'sarrah', 'sarra',
+        'moss', 'katy', 'neal', 'linda', 'narinesingh', 'rajesh',
+        'neal-domanski', 'kimberly'
+    ]
+
+    g_bad_reviews = g_reviews.filter(star_rating__lte=2)
+
+    context = {
+
+        'google_ratings': g_ratings,
+        'google_staffs': g_staff_names,
+        'google_bad_reviews': g_bad_reviews
+    }
+    return render(requests, 'weekly_report.html', context)

+ 0 - 1
name_extractor/models.py

@@ -17,4 +17,3 @@ class Staff(models.Model):
     @property
     def get_nick_names(self):
         return self.nick_names.split(',')
-