Mohidul Islam 4 лет назад
Родитель
Сommit
921dff18b3

+ 12 - 0
gauth/models.py

@@ -24,6 +24,18 @@ class Location(models.Model):
     def __str__(self):
         return self.care_name if self.care_name else self.location_name
 
+    @property
+    def managers(self):
+        return self.locationmanager_set.all()
+
+    @property
+    def all_facebook_review(self):
+        return self.facebookpage.facebookreview_set.all()
+
+    @property
+    def all_google_review(self):
+        return self.review_set.all()
+
 
 class LocationManager(models.Model):
     name = models.CharField(max_length=255)

+ 0 - 0
manager/__init__.py


+ 3 - 0
manager/admin.py

@@ -0,0 +1,3 @@
+from django.contrib import admin
+
+# Register your models here.

+ 5 - 0
manager/apps.py

@@ -0,0 +1,5 @@
+from django.apps import AppConfig
+
+
+class ManagerConfig(AppConfig):
+    name = 'manager'

+ 0 - 0
manager/migrations/__init__.py


+ 3 - 0
manager/models.py

@@ -0,0 +1,3 @@
+from django.db import models
+
+# Create your models here.

+ 65 - 0
manager/templates/locations.html

@@ -0,0 +1,65 @@
+{% load static %}
+<html lang="en">
+  <head>
+    <meta charset="utf-8">
+    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
+    <meta name="description" content="">
+    <meta name="author" content="">
+    <title>SignatureCare Review Portal</title>
+    <link rel="canonical" href="https://getbootstrap.com/docs/4.0/examples/dashboard/">
+    <!-- Bootstrap core CSS -->
+    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
+    <!-- Custom styles for this template -->
+    <link rel="stylesheet" type="text/css" href="{% static 'user-dashboard.css' %}">
+    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
+  </head>
+
+  <body>
+    <nav class="navbar navbar-dark bg-dark">
+      <div class="container">
+        <ul class="navbar-nav px-3">
+        <li class="nav-item text-nowrap">
+          <a class="nav-link" href="{% url 'home-view' %}" style="color: white; font-size:20px">SignatureCare Review Portal</a>
+        </li>
+        </ul>
+        <ul class="navbar-nav px-3">
+          <li class="nav-item text-nowrap">
+            <a class="nav-link" href="{% url 'logout' %}">Sign out</a>
+          </li>
+        </ul>
+      </div>
+    </nav>
+
+    <div class="container">
+      <div class="row">
+      {% for loc in all_locations %}
+      <div class="col-sm-6">
+        <div class="card mt-2 mb-2 graph-card-shadow">
+          <div class="card-header">
+            <span style="font-size: larger; font-family: sans-serif; font-weight: bold;">{{ loc.care_name }}</span>
+            <span style="float: right;">
+                <i class="fa fa-hospital-o mr-2" aria-hidden="true"></i>
+                <spen>{{ loc.location_name }}</spen>
+            </span>
+          </div>
+          <div class="card-body">
+<!--            <span>Google Review URL: <a href="{{ loc.website_url }}">{{ loc.website_url }}</a></span><br>-->
+<!--            <span>Facebook Page URL: <a href="https://web.facebook.com/{{ loc.facebookpage.id }}">"https://web.facebook.com/{{ loc.facebookpage.id }}</a></span>-->
+            <span>
+              Total Review:
+              <span > <i class="fa fa-google" aria-hidden="true" style="color: #ff7700; margin-left: 1rem;"></i> {{ loc.all_google_review.count }}</span>
+              <span > <i class="fa fa-facebook" aria-hidden="true" style="color: blue; margin-left: 2rem;"></i> {{ loc.all_facebook_review.count }} </span>
+            </span>
+          </div>
+        </div>
+      </div>
+    {% endfor %}
+      </div>
+    </div>
+    <script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
+    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
+    <nav class="navbar navbar-dark sticky-top bg-dark flex-md-nowrap mt-4">
+      <span style="color: white;">&copy;2020 SignatureCare Review Portal. - Developed by Byte Trek Ltd. </span>
+    </nav>
+  </body>
+</html>

+ 3 - 0
manager/tests.py

@@ -0,0 +1,3 @@
+from django.test import TestCase
+
+# Create your tests here.

+ 7 - 0
manager/urls.py

@@ -0,0 +1,7 @@
+from django.urls import path
+
+from .views import LocationListView
+
+urlpatterns = [
+    path('', LocationListView.as_view(), name='location-list')
+]

+ 10 - 0
manager/views.py

@@ -0,0 +1,10 @@
+from django.shortcuts import render
+from django.views.generic import View
+
+from gauth.models import Location, LocationManager
+
+
+class LocationListView(View):
+    def get(self, request, *args, **kwargs):
+        locations = Location.objects.all()
+        return render(request, 'locations.html', {'all_locations': locations})

+ 2 - 1
review_automation/settings/base.py

@@ -33,7 +33,8 @@ PROJECTS_APPS = [
     'name_extractor.apps.NameExtractorConfig',
     'yelp.apps.YelpConfig',
     'facebook_app.apps.FacebookConfig',
-    'user.apps.UserConfig'
+    'user.apps.UserConfig',
+    'manager.apps.ManagerConfig',
 ]
 
 INSTALLED_APPS = DJANGO_DEFAULT_APPS + THIRD_PARTY_APPS + PROJECTS_APPS

+ 1 - 0
review_automation/urls.py

@@ -15,6 +15,7 @@ urlpatterns = [
     path('leaderboard/', include('name_extractor.urls')),
     path('facebook/', include('facebook_app.urls')),
     path('user/', include('user.urls')),
+    path('managers/', include('manager.urls')),
 ] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
 
 

+ 2 - 2
user/templates/user-base.html

@@ -5,7 +5,7 @@
     <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
     <meta name="description" content="">
     <meta name="author" content="">
-    <title>Byte Trek Review Bot</title>
+    <title>SignatureCare Review Portal</title>
     <link rel="canonical" href="https://getbootstrap.com/docs/4.0/examples/dashboard/">
     <!-- Bootstrap core CSS -->
     <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
@@ -26,7 +26,7 @@
 
   <body>
     <nav class="navbar navbar-dark sticky-top bg-dark flex-md-nowrap p-0">
-      <a class="navbar-brand col-sm-3 col-md-2 mr-0" href="{% url 'home-view' %}">BT Review Bot</a>
+      <a class="navbar-brand col-sm-3 col-md-2 mr-0" href="{% url 'home-view' %}">SignatureCare Review Portal</a>
       <ul class="navbar-nav px-3">
         <li class="nav-item text-nowrap">
           <a class="nav-link" href="{% url 'logout' %}">Sign out</a>

+ 28 - 71
user/templates/user-dashboard.html

@@ -10,13 +10,14 @@
       <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</td> <td>Count</td></tr>
             <tr>
-              <td><i class="fa fa-pencil-square-o" aria-hidden="true"></i>  Total Review</td>
-              <td>{{ google_total }}</td>
+              <td>This month (so far)</td>
+              <td>{{ google_this_month }}</td>
             </tr>
             <tr>
-              <td><i class="fa fa-line-chart" aria-hidden="true"></i>  Growth</td>
-              <td>{{ google_total_growth }} %</td>
+              <td>Last month</td>
+              <td>{{ google_last_month }}</td>
             </tr>
           </table>
         </div>
@@ -47,12 +48,14 @@
         <div class="card-body">
           <table class="table">
             <tr>
-              <td><i class="fa fa-pencil-square-o" aria-hidden="true"></i>  Total Review</td>
-              <td>{{ facebook_total }}</td>
+              <td><i class="fa fa-pencil-square-o" aria-hidden="true"></i> Reviews</td> <td>Count</td></tr>
+            <tr>
+              <td>This month (so far)</td>
+              <td>{{ facebook_this_month }}</td>
             </tr>
             <tr>
-              <td><i class="fa fa-line-chart" aria-hidden="true"></i>  Growth</td>
-              <td>{{ facebook_total_growth }} %</td>
+              <td>Last month</td>
+              <td>{{ facebook_last_month }}</td>
             </tr>
           </table>
         </div>
@@ -63,68 +66,7 @@
 
 <!--    canvas-->
   <canvas class="my-4" id="myChart" width="900" height="300"></canvas>
-
-  <h2>Section title</h2>
-  <div class="table-responsive">
-    <table class="table">
-      <thead>
-        <tr class="table-info">
-          <th>Platform</th>
-          <th>Total <br>Positive Review</th>
-          <th>Positive <br> review Growth</th>
-          <th>Total <br>Negative Review</th>
-          <th>Negative <br> review Growth</th>
-        </tr>
-      </thead>
-      <tbody>
-        <tr>
-          <td>Google</td>
-          <td>{{ google_pos }}</td>
-          {% if google_pos_gr > 0 %}
-            <td class="table-success"><i class="fa fa-arrow-circle-o-up mr-2" aria-hidden="true"></i>{{ google_pos_gr }} %</td>
-          {% else %}
-            <td class="table-danger"><i class="fa fa-arrow-circle-o-down mr-2" aria-hidden="true"></i>{{ google_pos_gr }} %</td>
-          {% endif %}
-          <td>{{ google_neg }}</td>
-          {% if google_neg_gr < 0 %}
-            <td class="table-success"><i class="fa fa-arrow-circle-o-down mr-2" aria-hidden="true"></i>{{ google_neg_gr }} %</td>
-          {% else %}
-            <td class="table-danger"><i class="fa fa-arrow-circle-o-up mr-2" aria-hidden="true"></i>{{ google_neg_gr }} %</td>
-          {% endif %}
-        </tr>
-<!--        <tr>-->
-<!--          <td>Yelp</td>-->
-<!--          <td>{{ yelp_pos }}</td>-->
-<!--          {% if yelp_pos_gr > 0 %}-->
-<!--            <td class="table-success"><i class="fa fa-arrow-circle-o-up mr-2" aria-hidden="true"></i>{{ yelp_pos_gr }} %</td>-->
-<!--          {% else %}-->
-<!--            <td class="table-danger"><i class="fa fa-arrow-circle-o-down mr-2" aria-hidden="true"></i>{{ yelp_pos_gr }} %</td>-->
-<!--          {% endif %}-->
-<!--          <td>{{ yelp_neg }}</td>-->
-<!--          {% if yelp_neg_gr < 0 %}-->
-<!--            <td class="table-success"><i class="fa fa-arrow-circle-o-down mr-2" aria-hidden="true"></i>{{ yelp_neg_gr }} %</td>-->
-<!--          {% else %}-->
-<!--            <td class="table-danger"><i class="fa fa-arrow-circle-o-up mr-2" aria-hidden="true"></i>{{ yelp_neg_gr }} %</td>-->
-<!--          {% endif %}-->
-<!--        </tr>-->
-        <tr style="border-bottom: 1px solid #dee2e6">
-          <td>Facebook</td>
-          <td>{{ facebook_pos }}</td>
-          {% if facebook_pos_gr > 0 %}
-            <td class="table-success"><i class="fa fa-arrow-circle-o-up mr-2" aria-hidden="true"></i>{{ facebook_pos_gr }} %</td>
-          {% else %}
-            <td class="table-danger"><i class="fa fa-arrow-circle-o-down mr-2" aria-hidden="true"></i>{{ facebook_pos_gr }} %</td>
-          {% endif %}
-          <td>{{ facebook_neg }}</td>
-          {% if facebook_neg_gr < 0 %}
-            <td class="table-success"><i class="fa fa-arrow-circle-o-down mr-2" aria-hidden="true"></i>{{ facebook_neg_gr }} %</td>
-          {% else %}
-            <td class="table-danger"><i class="fa fa-arrow-circle-o-up mr-2" aria-hidden="true"></i>{{ facebook_neg_gr }} %</td>
-          {% endif %}
-        </tr>
-      </tbody>
-    </table>
-  </div>
+ </div>
 
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js" integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous"></script>
 <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.9.3/Chart.bundle.min.js" integrity="sha256-TQq84xX6vkwR0Qs1qH5ADkP+MvH0W+9E7TdHJsoIQiM=" crossorigin="anonymous"></script>
@@ -171,11 +113,26 @@
             options: {
                 scales: {
                     yAxes: [{
+                        display: true,
+                        scaleLabel: {
+                          display: true,
+                          fontSize: 16,
+                          fontStyle: 'italic',
+                          labelString: 'Total review count'
+                        },
                         ticks: {
-                            beginAtZero: true
+                            beginAtZero: true,
+                            stepSize: 1
                         }
                     }],
                     xAxes: [{
+                        display: true,
+                            scaleLabel: {
+                              display: true,
+                              fontSize: 16,
+                              fontStyle: 'italic',
+                              labelString: 'Day of the month'
+                            },
                         gridLines: {
                             drawOnChartArea:false
                         }

+ 26 - 64
user/utils.py

@@ -30,39 +30,21 @@ def get_google_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 = Review.objects.filter(
-        location_id=location_id,
-        create_time__range=(beginning_of_month, now),
-        star_rating__gte=3
-    ).count()
-    neg = Review.objects.filter(
-        location_id=location_id,
-        create_time__range=(beginning_of_month, now),
-        star_rating__lte=2
-    ).count()
-    pos_last_month = Review.objects.filter(
+    reviews = Review.objects.all()
+
+    this_month = reviews.filter(
         location_id=location_id,
-        create_time__range=(beginning_of_last_month, beginning_of_month),
-        star_rating__gte=3
+        create_time__range=(beginning_of_month, now)
     ).count()
-    neg_last_month = Review.objects.filter(
+
+    last_month = reviews.filter(
         location_id=location_id,
-        create_time__range=(beginning_of_last_month, beginning_of_month),
-        star_rating__lte=2
+        create_time__range=(beginning_of_last_month, beginning_of_month)
     ).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': this_month,
+        'last_month': last_month
     }
 
 
@@ -71,39 +53,21 @@ def get_facebook_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 = FacebookReview.objects.filter(
-        page__location_id=location_id,
-        create_time__range=(beginning_of_month, now),
-        recommendation_type=True
-    ).count()
-    neg = FacebookReview.objects.filter(
-        page__location_id=location_id,
-        create_time__range=(beginning_of_month, now),
-        recommendation_type=False
-    ).count()
-    pos_last_month = FacebookReview.objects.filter(
+    reviews = FacebookReview.objects.all()
+
+    this_month = reviews.filter(
         page__location_id=location_id,
-        create_time__range=(beginning_of_last_month, beginning_of_month),
-        recommendation_type=True
+        create_time__range=(beginning_of_month, now)
     ).count()
-    neg_last_month = FacebookReview.objects.filter(
+
+    last_month = reviews.filter(
         page__location_id=location_id,
-        create_time__range=(beginning_of_last_month, beginning_of_month),
-        recommendation_type=False
+        create_time__range=(beginning_of_last_month, beginning_of_month)
     ).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': this_month,
+        'last_month': last_month
     }
 
 
@@ -160,13 +124,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,
@@ -178,19 +142,17 @@ def get_this_month_analytics(location_id):
 
     label = []
     facebook = []
-    yelp = []
     google = []
     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
     }
 
 

+ 4 - 21
user/views.py

@@ -20,7 +20,6 @@ from django.contrib.auth.mixins import LoginRequiredMixin
 from .utils import (
     get_google_review_report,
     get_facebook_report,
-    get_yelp_review_report,
     get_this_month_analytics,
     get_review_count_by_month,
     date_str2datetime
@@ -65,32 +64,16 @@ class LoginRedirectURL(View):
 
 class LocationAnalytics(LoginRequiredMixin, View):
     def get(self, request, *args, **kwargs):
-        # print(dir(request.user))
         user_location_id = request.user.useraccount.location_id
 
         google_report = get_google_review_report(user_location_id)
         facebook_report = get_facebook_report(user_location_id)
-        yelp_report = get_yelp_review_report(user_location_id)
 
         context = {
-            'google_pos': google_report.get('positive'),
-            'google_pos_gr': google_report.get('positive_growth'),
-            'google_neg': google_report.get('negative'),
-            'google_neg_gr': google_report.get('negative_growth'),
-            'google_total': google_report.get('total'),
-            'google_total_growth': google_report.get('total_growth'),
-            'yelp_pos': yelp_report.get('positive'),
-            'yelp_pos_gr': yelp_report.get('positive_growth'),
-            'yelp_neg': yelp_report.get('negative'),
-            'yelp_neg_gr': yelp_report.get('negative_growth'),
-            'yelp_total': yelp_report.get('total'),
-            'yelp_total_growth': yelp_report.get('total_growth'),
-            'facebook_pos': facebook_report.get('positive'),
-            'facebook_pos_gr': facebook_report.get('positive_growth'),
-            'facebook_neg': facebook_report.get('negative'),
-            'facebook_neg_gr': facebook_report.get('negative_growth'),
-            'facebook_total': facebook_report.get('total'),
-            'facebook_total_growth': facebook_report.get('total_growth'),
+            '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'),
         }
         return render(request, 'user-dashboard.html', context=context)