reports_build_charts.php 6.5 KB

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