reports_build_charts.php 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. <?php
  2. // Tests by Cleanliness
  3. $chart = new Chart;
  4. $chart->setType("doughnut");
  5. $chart->setTitle("Tests by Cleanliness $date_range_label");
  6. $chart->setLabels(["Very dirty", "Dirty", "Adequate", "Clean", "Very Clean"]);
  7. $chart->addDataset("Tests", [
  8. $total_data->cleanlinessCounts[0],
  9. $total_data->cleanlinessCounts[1],
  10. $total_data->cleanlinessCounts[2],
  11. $total_data->cleanlinessCounts[3],
  12. $total_data->cleanlinessCounts[4],
  13. ], [
  14. "background_colours" => [
  15. "#F44336",
  16. "#FFAB91",
  17. "#FBC02D",
  18. "#FFEB3B",
  19. "#4CAF50",
  20. ],
  21. "datalabels" => Chart::DATALABELS_BOX,
  22. ]);
  23. $chart->setPrintSuffixes("");
  24. $chart->print = true;
  25. $chart->printPercentages = true;
  26. $charts[] = $chart;
  27. // Cleanliness (Each Period)
  28. foreach($keys as $index => $key) {
  29. $key_label = $key_labels[$index];
  30. $period_data = $data[$key];
  31. if($period_data->testCount == 0) continue;
  32. $chart = new Chart;
  33. $chart->setType("pie");
  34. $chart->setTitle("$key_label Cleanliness");
  35. $chart->setLabels(["Very dirty", "Dirty", "Adequate", "Clean", "Very Clean"]);
  36. $chart->addDataset("Counts", [
  37. $period_data->cleanlinessCounts[0],
  38. $period_data->cleanlinessCounts[1],
  39. $period_data->cleanlinessCounts[2],
  40. $period_data->cleanlinessCounts[3],
  41. $period_data->cleanlinessCounts[4],
  42. ], [
  43. "background_colours" => [
  44. "#F44336",
  45. "#FFAB91",
  46. "#FBC02D",
  47. "#FFEB3B",
  48. "#4CAF50",
  49. ],
  50. "datalabels" => Chart::DATALABELS_BOX,
  51. ]);
  52. $charts[] = $chart;
  53. }
  54. // Tester Gender
  55. $chart = new Chart;
  56. $chart->setType("pie");
  57. $chart->setTitle("Tester Gender $date_range_label");
  58. $chart->setLabels(["Male", "Female"]);
  59. $chart->addDataset("Counts", [
  60. $total_data->maleTesterCount,
  61. $total_data->femaleTesterCount,
  62. ], [
  63. "background_colours" => [
  64. "#2196F3",
  65. "#E91E63",
  66. ],
  67. "datalabels" => Chart::DATALABELS_BOX,
  68. ]);
  69. $charts[] = $chart;
  70. // Staff Badge Worn
  71. $staff_badge_worn_counts = array_column($data, "staffBadgeWornCounts");
  72. $unknown_counts = array_column($staff_badge_worn_counts, 0);
  73. $no_counts = array_column($staff_badge_worn_counts, 1);
  74. $yes_counts = array_column($staff_badge_worn_counts, 2);
  75. $chart = new Chart;
  76. $chart->setType("bar");
  77. $chart->setTitle("Staff Badge Worn by $resolution_name");
  78. $chart->setLabels($x_data_labels);
  79. $chart->addDataset("Don't know", $unknown_counts, [
  80. "background_colours" => "#CCCCCC"
  81. ]);
  82. $chart->addDataset("No", $no_counts, [
  83. "background_colours" => "#F44336"
  84. ]);
  85. $chart->addDataset("Yes", $yes_counts, [
  86. "background_colours" => "#4CAF50"
  87. ]);
  88. $charts[] = $chart;
  89. // Staff Offered Drink
  90. $staff_offered_drink_counts = array_column($data, "staffOfferedDrinkCounts");
  91. $no_counts = array_column($staff_offered_drink_counts, 0);
  92. $yes_counts = array_column($staff_offered_drink_counts, 1);
  93. $chart = new Chart;
  94. $chart->setType("bar");
  95. $chart->setTitle("Staff Offered Drink by $resolution_name");
  96. $chart->setLabels($x_data_labels);
  97. $chart->addDataset("No", $no_counts, [
  98. "background_colours" => "#F44336"
  99. ]);
  100. $chart->addDataset("Yes", $yes_counts, [
  101. "background_colours" => "#4CAF50"
  102. ]);
  103. $charts[] = $chart;
  104. // Staff Offered Promotion
  105. $staff_offered_promotion_counts = array_column($data, "staffOfferedPromotionCounts");
  106. $no_counts = array_column($staff_offered_promotion_counts, 0);
  107. $yes_counts = array_column($staff_offered_promotion_counts, 1);
  108. $chart = new Chart;
  109. $chart->setType("bar");
  110. $chart->setTitle("Staff Offered Promotion by $resolution_name");
  111. $chart->setLabels($x_data_labels);
  112. $chart->addDataset("No", $no_counts, [
  113. "background_colours" => "#F44336"
  114. ]);
  115. $chart->addDataset("Yes", $yes_counts, [
  116. "background_colours" => "#4CAF50"
  117. ]);
  118. $charts[] = $chart;
  119. // Staff Offered Help
  120. $staff_offered_help_counts = array_column($data, "staffOfferedHelpCounts");
  121. $no_counts = array_column($staff_offered_help_counts, 0);
  122. $yes_counts = array_column($staff_offered_help_counts, 1);
  123. $chart = new Chart;
  124. $chart->setType("bar");
  125. $chart->setTitle("Staff Offered Help by $resolution_name");
  126. $chart->setLabels($x_data_labels);
  127. $chart->addDataset("No", $no_counts, [
  128. "background_colours" => "#F44336"
  129. ]);
  130. $chart->addDataset("Yes", $yes_counts, [
  131. "background_colours" => "#4CAF50"
  132. ]);
  133. $charts[] = $chart;
  134. // Staff Behaviour (Each Period)
  135. foreach($keys as $index => $key) {
  136. $key_label = $key_labels[$index];
  137. $period_data = $data[$key];
  138. if($period_data->testCount == 0) continue;
  139. $chart = new Chart;
  140. $chart->setType("pie");
  141. $chart->setTitle("$key_label Staff Behaviour");
  142. $chart->setLabels(["N/A", "Rude", "Slightly rude", "Neither rude or polite", "Polite", "Very polite"]);
  143. $chart->addDataset("Counts", [
  144. $period_data->staffBehaviourCounts[0],
  145. $period_data->staffBehaviourCounts[1],
  146. $period_data->staffBehaviourCounts[2],
  147. $period_data->staffBehaviourCounts[3],
  148. $period_data->staffBehaviourCounts[4],
  149. $period_data->staffBehaviourCounts[5],
  150. ], [
  151. "background_colours" => [
  152. "#CCCCCC",
  153. "#F44336",
  154. "#FFAB91",
  155. "#FBC02D",
  156. "#FFEB3B",
  157. "#4CAF50",
  158. ],
  159. "datalabels" => Chart::DATALABELS_BOX,
  160. ]);
  161. $charts[] = $chart;
  162. }
  163. // Staff Uniform
  164. $staff_uniform_counts = array_column($data, "staffUniformCounts");
  165. $no_counts = array_column($staff_uniform_counts, 0);
  166. $yes_counts = array_column($staff_uniform_counts, 1);
  167. $chart = new Chart;
  168. $chart->setType("bar");
  169. $chart->setTitle("Staff Uniform by $resolution_name");
  170. $chart->setLabels($x_data_labels);
  171. $chart->addDataset("No", $no_counts, [
  172. "background_colours" => "#F44336"
  173. ]);
  174. $chart->addDataset("Yes", $yes_counts, [
  175. "background_colours" => "#4CAF50"
  176. ]);
  177. $charts[] = $chart;
  178. // Tester Genders by Period
  179. $male_counts = array_values(array_map(function($d) {
  180. return $d->maleTesterCount;
  181. }, $data));
  182. $female_counts = array_values(array_map(function($d) {
  183. return $d->femaleTesterCount;
  184. }, $data));
  185. $chart = new Chart;
  186. $chart->addYAxis([
  187. "id" => "y-axis-1",
  188. "tick_config" => ["min" => 0, "max" => ceil(max(max($male_counts), max($female_counts)) / 10) * 10]
  189. ]);
  190. $chart->setType("bar");
  191. $chart->setTitle("Tester Gender by $resolution_name");
  192. $chart->setLabels($x_data_labels);
  193. $chart->addDataset("Male", $male_counts, [
  194. "background_colours" => "#2196F3"
  195. ]);
  196. $chart->addDataset("Female", $female_counts, [
  197. "background_colours" => "#E91E63"
  198. ]);
  199. $charts[] = $chart;
  200. // Test Count by Period
  201. $test_counts = array_values(array_map(function($d) {
  202. return $d->testCount;
  203. }, $data));
  204. $chart = new Chart;
  205. $chart->addYAxis([
  206. "id" => "y-axis-1",
  207. "tick_config" => ["min" => 0, "max" => ceil(max($test_counts) / 10) * 10]
  208. ]);
  209. $chart->setType("bar");
  210. $chart->setTitle("Tests by $resolution_name");
  211. $chart->setLabels($x_data_labels);
  212. $chart->addDataset("Tests", $test_counts, [
  213. "background_colours" => "#2196F3"
  214. ]);
  215. $charts[] = $chart;
  216. ?>