analytics.html 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. {% extends "base.html" %}
  2. {% block report %}
  3. <div class="mt-2">
  4. <select id="location" class="select-style">
  5. {% for loc in location_list %}
  6. <option class="btn btn-secondary m-1" value="{{loc.location_id}}">{{ loc.care_name }}</option>
  7. {% endfor %}
  8. </select>
  9. <select id="timeInterval" class="select-style">
  10. <option value="month">Monthly</option>
  11. <option value="week">Weekly</option>
  12. <option value="day">Daily</option>
  13. </select>
  14. </div>
  15. <div>
  16. <h2 style="text-align:center" class="mt-4">Total Review in Last One Year</h2>
  17. <canvas id="barChart" width="400" height="100" class="mt-2"></canvas>
  18. </div>
  19. <div>
  20. <h2 style="text-align:center" class="mt-4">Total Star ratings in Last One Year</h2>
  21. <canvas id="lineChart" width="400" height="100" class="mt-4"></canvas>
  22. </div>
  23. <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js" integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous"></script>
  24. <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>
  25. <script>
  26. $(document).ready(function(){
  27. var endpoint = '/analytics/month';
  28. params = {
  29. "location_id": 'all'
  30. }
  31. $.ajax({
  32. type: "get",
  33. url: endpoint,
  34. data: params,
  35. dataType: 'json',
  36. success: function(data) {
  37. var ctx = document.getElementById('lineChart').getContext('2d');
  38. var ctxBar = document.getElementById('barChart').getContext('2d');
  39. var myChart = new Chart(ctx, {
  40. type: 'line',
  41. data: {
  42. labels: data.month,
  43. datasets: [
  44. {
  45. label: '5 Star',
  46. data: data.five_star,
  47. borderColor: 'rgb(75, 192, 192)',
  48. backgroundColor: 'rgb(75, 192, 192)',
  49. borderWidth: 3,
  50. fill: false
  51. },
  52. {
  53. label: '4 Star',
  54. data: data.four_star,
  55. borderColor: 'rgb(54, 162, 235)',
  56. backgroundColor: 'rgb(54, 162, 235)',
  57. borderWidth: 3,
  58. fill: false
  59. },
  60. {
  61. label: '3 Star',
  62. data: data.three_star,
  63. borderColor: 'rgb(153, 102, 255)',
  64. backgroundColor: 'rgb(153, 102, 255)',
  65. borderWidth: 3,
  66. fill: false
  67. },
  68. {
  69. label: '2 Star',
  70. data: data.two_star,
  71. borderColor: 'rgb(255, 159, 64)',
  72. backgroundColor: 'rgb(255, 159, 64)',
  73. borderWidth: 3,
  74. fill: false
  75. },
  76. {
  77. label: '1 Star',
  78. data: data.one_star,
  79. borderColor: 'rgb(255, 99, 132)',
  80. backgroundColor: 'rgb(255, 99, 132)',
  81. borderWidth: 3,
  82. fill: false
  83. },
  84. ]
  85. },
  86. options: {
  87. scales: {
  88. yAxes: [{
  89. ticks: {
  90. beginAtZero: true
  91. }
  92. }]
  93. }
  94. }
  95. });
  96. var myChart = new Chart(ctxBar, {
  97. type: 'bar',
  98. data: {
  99. labels: data.month,
  100. datasets: [
  101. {
  102. label: 'All Reviews',
  103. data: data.total_reviews,
  104. borderColor: 'rgb(75, 192, 192)',
  105. backgroundColor: 'rgb(75, 192, 192)',
  106. borderWidth: 3,
  107. fill: false
  108. }]
  109. },
  110. options: {
  111. scales: {
  112. yAxes: [{
  113. ticks: {
  114. beginAtZero: true
  115. }
  116. }]
  117. }
  118. }
  119. });
  120. },
  121. error: function(error_data) {
  122. console.log(error_data);
  123. }
  124. });
  125. });
  126. </script>
  127. {% endblock report %}