Przeglądaj źródła

Added graph to location lists

Mohidul Islam 3 lat temu
rodzic
commit
2d70dd22c7

+ 89 - 18
manager/templates/locations.html

@@ -78,32 +78,18 @@
                 <span style="font-size: larger; font-family: sans-serif; font-weight: bold;">{{ loc.care_name }}</span>
                 <span style="font-size: larger; font-family: sans-serif; font-weight: bold;">{{ loc.care_name }}</span>
                 <span style="float: right;">
                 <span style="float: right;">
                     <i class="fa fa-hospital-o mr-2" aria-hidden="true"></i>
                     <i class="fa fa-hospital-o mr-2" aria-hidden="true"></i>
-                    <spen>{{ loc.location_name }}</spen>
                 </span>
                 </span>
               </div>
               </div>
               <div class="card-body">
               <div class="card-body">
-                <table class="table">
-                  <tr>
-                    <td><i class="fa fa-google" aria-hidden="true" style="color: #ff7700; margin-left: 1rem;">oogle</i></td>
-                    <td style="color: {% if loc.last_week_pos_google_review_count == 0 %} grey {% else %} #212F3D {% endif %}"><i class="fa fa-thumbs-o-up" style="color: green;" aria-hidden="true"></i> {{ loc.last_week_pos_google_review_count }}</td>
-                    <td style="color: {% if loc.last_week_neg_google_review_count == 0 %} grey {% else %} #212F3D {% endif %}"><i class="fa fa-thumbs-o-down" style="color: red;" aria-hidden="true"></i> {{ loc.last_week_neg_google_review_count }}</td>
-                  </tr>
-                  <tr>
-                    <td><i class="fa fa-facebook" aria-hidden="true" style="color: blue; margin-left: 2rem;">acebook</i></td>
-                    <td style="color: {% if loc.last_week_pos_facebook_review_count == 0 %} grey {% else %} #212F3D {% endif %}"><i class="fa fa-thumbs-o-up" style="color: green;" aria-hidden="true"></i> {{ loc.last_week_pos_facebook_review_count }}</td>
-                    <td style="color: {% if loc.last_week_neg_facebook_review_count == 0 %} grey {% else %} #212F3D {% endif %}"><i class="fa fa-thumbs-o-down" style="color: red;" aria-hidden="true"></i> {{ loc.last_week_neg_facebook_review_count }}</td>
-                  </tr>
-                  <tr>
-                    <td><i class="fa fa-yelp" aria-hidden="true" style="color: red; margin-left: 2rem;"> Yelp</i></td>
-                    <td style="color: {% if loc.last_week_pos_yelp_review_count == 0 %} grey {% else %} #212F3D {% endif %}"><i class="fa fa-thumbs-o-up" style="color: green;" aria-hidden="true"></i> {{ loc.last_week_pos_yelp_review_count }}</td>
-                    <td style="color: {% if loc.last_week_neg_yelp_review_count == 0 %} grey {% else %} #212F3D {% endif %}"><i class="fa fa-thumbs-o-down" style="color: red;" aria-hidden="true"></i> {{ loc.last_week_neg_yelp_review_count }}</td>
-                  </tr>
-                </table>
+                <canvas class="my-4" id="id_canvas_{{ loc.care_name }}" width="250" height="150"></canvas>
               </div>
               </div>
             </div>
             </div>
             </a>
             </a>
           </div>
           </div>
         {% endfor %}
         {% endfor %}
+
+
+
       </div>
       </div>
       <!-- Modal -->
       <!-- Modal -->
         <div class="modal fade" id="fileUploadModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
         <div class="modal fade" id="fileUploadModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
@@ -133,6 +119,91 @@
     </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/jquery/3.4.1/jquery.min.js" integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" 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>
     <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
+    <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>
+    <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.7.1/Chart.min.js"></script>
+
+
+<script>
+  var endpoint = 'graphs/all_location';
+
+  params = {
+      "days": 10
+  }
+  $.ajax({
+    type: "get",
+    url: endpoint,
+    data: params,
+    dataType: 'json',
+    success: function(data) {
+    review_counts = data.review_counts;
+    for (let i = 0; i < review_counts.length; i++) {
+      var ctx = document.getElementById("id_canvas_"+review_counts[i].name);
+      var myBarChart = new Chart(ctx, {
+      type: 'bar',
+      data: {
+        labels: data.labels,
+        datasets: [
+          {
+            label: 'Positive',
+            data: review_counts[i].positive,
+            borderColor: 'rgb(52, 128, 0 )',
+            backgroundColor: 'rgb(52, 128, 0 )',
+            borderWidth: 1,
+            fill: false
+        },
+        {
+          label: 'Negative',
+          data: review_counts[i].negative,
+          borderColor: 'rgb(200, 0, 21)',
+          backgroundColor: 'rgb(200, 0, 21)',
+          borderWidth: 1,
+          fill: false
+        }]
+        },
+        options: {
+          scales: {
+              yAxes: [{
+                  display: true,
+                  scaleLabel: {
+                    display: true,
+                    fontSize: 12,
+                    fontStyle: 'italic',
+                    labelString: 'Review count'
+                  },
+                  ticks: {
+                      beginAtZero: true,
+                      stepSize: 1
+                  }
+              }],
+              xAxes: [{
+                  display: true,
+                      scaleLabel: {
+                        display: false,
+                        fontSize: 16,
+                        fontStyle: 'italic',
+                        labelString: 'Day of the month'
+                      },
+                  gridLines: {
+                      drawOnChartArea:false
+                  }
+              }]
+          },
+          title: {
+              display: false,
+              fontSize: 16,
+              text: "Review of this month in all platforms."
+          }
+        }
+      });
+    }
+    },
+    error: function(error_data) {
+       console.log(error_data);
+    }
+  });
+</script>
+
     <nav class="navbar navbar-dark sticky-top bg-dark flex-md-nowrap mt-4">
     <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>
       <span style="color: white;">&copy;2020 SignatureCare Review Portal. - Developed by Byte Trek Ltd. </span>
     </nav>
     </nav>

+ 3 - 0
manager/urls.py

@@ -9,12 +9,15 @@ from .views import (
     StaffLeaderBoard,
     StaffLeaderBoard,
     SyncStaffLeaderBoard,
     SyncStaffLeaderBoard,
     StaffDelete,
     StaffDelete,
+    AllLocationSummary,
 )
 )
+
 urlpatterns = [
 urlpatterns = [
     path('', LocationListView.as_view(), name='location-list'),
     path('', LocationListView.as_view(), name='location-list'),
     path('analytics/<str:location_id>', LocationAnalytics.as_view(), name='location-analytics-man'),
     path('analytics/<str:location_id>', LocationAnalytics.as_view(), name='location-analytics-man'),
     path('reviews/<platform>/<str:location_id>', ReviewListLocationWise.as_view(), name='location-wise-review-list-man'),
     path('reviews/<platform>/<str:location_id>', ReviewListLocationWise.as_view(), name='location-wise-review-list-man'),
     path('graph/<str:location_id>', ReviewAnalyticsGraph.as_view(), name='location-analytics-graph-man'),
     path('graph/<str:location_id>', ReviewAnalyticsGraph.as_view(), name='location-analytics-graph-man'),
+    path('graphs/all_location', AllLocationSummary.as_view(), name='all-location-graph-man'),
     path('staff/<str:location_id>', StaffLeaderBoard.as_view(), name='staff-leaderboard-man'),
     path('staff/<str:location_id>', StaffLeaderBoard.as_view(), name='staff-leaderboard-man'),
     path('staff/delete/<staff_id>', StaffDelete.as_view(), name='staff-delete-man'),
     path('staff/delete/<staff_id>', StaffDelete.as_view(), name='staff-delete-man'),
     path('sync-staff-list/<str:location_id>', SyncStaffLeaderBoard.as_view(), name='sync-staff-list-man'),
     path('sync-staff-list/<str:location_id>', SyncStaffLeaderBoard.as_view(), name='sync-staff-list-man'),

+ 32 - 0
manager/views.py

@@ -1,4 +1,7 @@
 import openpyxl
 import openpyxl
+from rest_framework import status
+from rest_framework.views import APIView
+from rest_framework.response import Response
 from gauth.models import Location, LocationManager
 from gauth.models import Location, LocationManager
 from django.http import Http404
 from django.http import Http404
 from django.shortcuts import render, redirect
 from django.shortcuts import render, redirect
@@ -243,3 +246,32 @@ class StaffDelete(View):
         staff = get_object_or_404(Staff, id=staff_id)
         staff = get_object_or_404(Staff, id=staff_id)
         staff.delete()
         staff.delete()
         return redirect('staff-leaderboard-man', location_id=staff.location_id)
         return redirect('staff-leaderboard-man', location_id=staff.location_id)
+
+
+class AllLocationSummary(APIView):
+    def get(self, request, *args, **kwargs):
+        days = request.GET['days']
+        if not days:
+            return Response({'error': 'No location Found'}, status=status.HTTP_400_BAD_REQUEST)
+        locations = Location.objects.all()
+        review_counts = []
+        for location in locations:
+            loc_json = {
+                'name': location.care_name,
+                'positive': [
+                    location.last_week_pos_google_review_count,
+                    location.last_week_pos_facebook_review_count,
+                    location.last_week_pos_yelp_review_count
+                ],
+                'negative': [
+                    location.last_week_neg_google_review_count,
+                    location.last_week_neg_facebook_review_count,
+                    location.last_week_neg_yelp_review_count
+                ]
+            }
+            review_counts.append(loc_json)
+            response = {
+                'labels': ['Google', 'Facebook', 'Yelp'],
+                'review_counts': review_counts,
+            }
+        return Response(response)

+ 1 - 0
review_automation/settings/config.py

@@ -3,6 +3,7 @@ CRONJOBS = [
     ('0 * * * *', 'review.background_job.background_task_every_hour'),
     ('0 * * * *', 'review.background_job.background_task_every_hour'),
     ('0 0 * * SUN', 'analytics.background_job.send_email_weekly_summary'),
     ('0 0 * * SUN', 'analytics.background_job.send_email_weekly_summary'),
     ('0 */12 * * *', 'facebook_app.background_job.schedule_task'),
     ('0 */12 * * *', 'facebook_app.background_job.schedule_task'),
+    ('0 0 * * *', 'yelp.utils.populate_yelp_reviews'),
 ]
 ]