reports_process_test.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. <?php
  2. /**
  3. * @var object $total_data Total data
  4. * @var array $region_data
  5. * @var array $area_manager_data
  6. * @var array $brand_data
  7. * @var array $operations_manager_data
  8. * @var array $data Periodic data
  9. * @var string $key Current period key
  10. * @var string $region
  11. * @var string $area_manager
  12. * @var string $brand
  13. * @var string $operations_manager
  14. * @var Test $test
  15. * @var User $tester
  16. * @var object $test_values
  17. */
  18. /**
  19. * @param $value
  20. * @param $pass
  21. * @param $prefix
  22. * @return void
  23. */
  24. $increment_periodic_pass_fail = static function($value, $pass, $prefix) use (&$data, $key) {
  25. if($pass) {
  26. $field = $prefix . "PassCounts";
  27. }
  28. else {
  29. $field = $prefix . "FailCounts";
  30. }
  31. if($value === null) {
  32. $index = 2;
  33. }
  34. else if($value) {
  35. $index = 1;
  36. }
  37. else {
  38. $index = 0;
  39. }
  40. $data[$key]->$field[$index]++;
  41. };
  42. $gaming_pass = null;
  43. $alcohol_pass = null;
  44. if(!$test->void_primary) {
  45. $stage_key = "stage" . $test->challenge_stage . "Count";
  46. $data[$key]->$stage_key++;
  47. $total_data->{$stage_key}++;
  48. $line_of_sight = $test_values->play_machine_line_of_sight ?? null;
  49. $eye_contact = $test->challenger_eye_contact ?? null;
  50. $gaming_pass = (bool) $test->pass;
  51. if($gaming_pass) {
  52. $data[$key]->passCount++;
  53. $total_data->passCount++;
  54. if($region) $region_data[$region][$key]->passCount++;
  55. if($area_manager) $area_manager_data[$area_manager][$key]->passCount++;
  56. if($brand) $brand_data[$brand][$key]->passCount++;
  57. if($operations_manager) $operations_manager_data[$operations_manager][$key]->passCount++;
  58. }
  59. else {
  60. $data[$key]->failCount++;
  61. $total_data->failCount++;
  62. if($region) $region_data[$region][$key]->failCount++;
  63. if($area_manager) $area_manager_data[$area_manager][$key]->failCount++;
  64. if($brand) $brand_data[$brand][$key]->failCount++;
  65. if($operations_manager) $operations_manager_data[$operations_manager][$key]->failCount++;
  66. }
  67. $pass_key = $gaming_pass ? "pass" : "fail";
  68. $data[$key]->combinedCounts[$pass_key]++;
  69. $total_data->combinedCounts[$pass_key]++;
  70. $increment_periodic_pass_fail($eye_contact, $gaming_pass, "eyeContact");
  71. $increment_periodic_pass_fail($line_of_sight, $gaming_pass, "lineOfSight");
  72. if($test->challenger_gender === "M") {
  73. $data[$key]->maleChallengerCount++;
  74. $total_data->maleChallengerCount++;
  75. }
  76. else if($test->challenger_gender === "F") {
  77. $data[$key]->femaleChallengerCount++;
  78. $total_data->femaleChallengerCount++;
  79. }
  80. else {
  81. $data[$key]->unspecifiedChallengerCount++;
  82. $total_data->unspecifiedChallengerCount++;
  83. }
  84. // Eye Contact
  85. if($test->challenger_eye_contact === null) {
  86. ++$data[$key]->eyeContactCounts[2];
  87. }
  88. else if($test->challenger_eye_contact) {
  89. ++$data[$key]->eyeContactCounts[0];
  90. }
  91. else {
  92. ++$data[$key]->eyeContactCounts[1];
  93. }
  94. // Genders Comparison
  95. $gender_prefix = "";
  96. switch($test->challenger_gender) {
  97. case "M": $gender_prefix = "male"; break;
  98. case "F": $gender_prefix = "female"; break;
  99. default: $gender_prefix = "unknown"; break;
  100. }
  101. $gender_prefix .= "Challenge";
  102. if($gender_prefix !== "unknownChallenge") {
  103. switch($tester->gender) {
  104. case "M": $gender_prefix .= "Male"; break;
  105. case "F": $gender_prefix .= "Female"; break;
  106. default: $gender_prefix = "unknownChallenge"; break;
  107. }
  108. }
  109. $data[$key]->{$gender_prefix . "Count"}++;
  110. $data[$key]->{$gender_prefix . "Stages"}[$test->challenge_stage - 1]++;
  111. if($test->pass) $data[$key]->{$gender_prefix . "PassCount"}++;
  112. if($test->pass) {
  113. $total_data->blendedCounts["pass"] += 2;
  114. }
  115. else {
  116. $total_data->blendedCounts["fail"]++;
  117. }
  118. }
  119. else {
  120. $total_data->gamingCounts["void"]++;
  121. $total_data->combinedCounts["void"]++;
  122. $total_data->blendedCounts["void"]++;
  123. }
  124. // Alcohol Pass/Fail
  125. if($test->void_secondary) {
  126. $total_data->barCounts["void"]++;
  127. $total_data->combinedCounts["void"]++;
  128. $total_data->blendedCounts["void"]++;
  129. }
  130. else if($test->challenge_stage === 5 || $test->void_primary) {
  131. $av_pass = (bool) ($test_values->bar_age_verification ?? false);
  132. $av_key = $av_pass ? "pass" : "fail";
  133. $data[$key]->barAgeVerificationCounts[$av_key]++;
  134. $total_data->barAgeVerificationCounts[$av_key]++;
  135. $alcohol_purchased = (bool) ($test_values->alcohol_purchased ?? false);
  136. $alcohol_pass = ($alcohol_purchased === false);
  137. $alcohol_key = $alcohol_pass ? "pass" : "fail";
  138. $data[$key]->barCounts[$alcohol_key]++;
  139. $total_data->barCounts[$alcohol_key]++;
  140. $data[$key]->combinedCounts[$alcohol_key]++;
  141. $total_data->combinedCounts[$alcohol_key]++;
  142. $total_data->blendedCounts[$alcohol_key]++;
  143. }
  144. if($gaming_pass || $alcohol_pass) {
  145. $total_data->mergedCounts["pass"]++;
  146. }
  147. elseif($alcohol_pass === false) {
  148. $total_data->mergedCounts["fail"]++;
  149. }
  150. else {
  151. $total_data->mergedCounts["void"]++;
  152. }