|
|
@@ -23,6 +23,12 @@ $all_projects = Project::query([
|
|
|
]);
|
|
|
|
|
|
$data = [];
|
|
|
+$region_data = [];
|
|
|
+$area_manager_data = [];
|
|
|
+$total_data = false;
|
|
|
+
|
|
|
+$locations_missing_region = [];
|
|
|
+$locations_missing_area_manager = [];
|
|
|
|
|
|
$charts = [];
|
|
|
|
|
|
@@ -47,13 +53,35 @@ if($submit) {
|
|
|
]);
|
|
|
|
|
|
User::load(array_column($tests, "tester_id"));
|
|
|
+ $locations = Location::load(array_column($tests, "location_id"));
|
|
|
+
|
|
|
+ $regions = array_filter(array_column($locations, "region"));
|
|
|
+ $area_managers = array_filter(array_column($locations, "area_manager"));
|
|
|
+
|
|
|
+ uksort($regions, "strnatcasecmp");
|
|
|
+ uksort($area_managers, "strnatcasecmp");
|
|
|
+
|
|
|
+ foreach($regions as $region) {
|
|
|
+ $region_data[$region] = [];
|
|
|
+ }
|
|
|
+
|
|
|
+ foreach($area_managers as $area_manager) {
|
|
|
+ $area_manager_data[$area_manager] = [];
|
|
|
+ }
|
|
|
+
|
|
|
+ $has_regions = !empty($region_data);
|
|
|
+ $has_area_managers = !empty($area_manager_data);
|
|
|
+
|
|
|
+
|
|
|
+ foreach($locations as $location) {
|
|
|
+ if($has_regions && !$location->region) $locations_missing_region[] = $location;
|
|
|
+ if($has_area_managers && !$location->area_manager) $locations_missing_area_manager[] = $location;
|
|
|
+ }
|
|
|
|
|
|
$min_year = date("Y");
|
|
|
$max_year = date("Y");
|
|
|
|
|
|
switch($date_range) {
|
|
|
-
|
|
|
-
|
|
|
case "ytd":
|
|
|
// Nothing to do
|
|
|
break;
|
|
|
@@ -98,6 +126,12 @@ if($submit) {
|
|
|
|
|
|
"femaleChallengeFemaleCount" => 0,
|
|
|
"femaleChallengeFemalePassCount" => 0,
|
|
|
+
|
|
|
+ "stage1Count" => 0,
|
|
|
+ "stage2Count" => 0,
|
|
|
+ "stage3Count" => 0,
|
|
|
+ "stage4Count" => 0,
|
|
|
+ "stage5Count" => 0,
|
|
|
];
|
|
|
|
|
|
$total_data = (object) [
|
|
|
@@ -107,19 +141,42 @@ if($submit) {
|
|
|
"femaleChallengerCount" => 0,
|
|
|
"passCount" => 0,
|
|
|
"failCount" => 0,
|
|
|
+
|
|
|
+ "stage1Count" => 0,
|
|
|
+ "stage2Count" => 0,
|
|
|
+ "stage3Count" => 0,
|
|
|
+ "stage4Count" => 0,
|
|
|
+ "stage5Count" => 0,
|
|
|
];
|
|
|
|
|
|
+ $resolution_name = "";
|
|
|
|
|
|
// Initialise date-array based on date range and resolution
|
|
|
for($year = $min_year; $year <= $max_year; $year++) {
|
|
|
switch($date_resolution) {
|
|
|
case "monthly":
|
|
|
|
|
|
+ $resolution_name = "Month";
|
|
|
+
|
|
|
foreach(range(1, 12) as $month) {
|
|
|
+
|
|
|
+ $label = date("M Y", mktime(0, 0, 0, $month, 1, date("Y")));
|
|
|
+
|
|
|
$month = str_pad($month, 2, "0", STR_PAD_LEFT);
|
|
|
$key = "$year-$month";
|
|
|
$data[$key] = clone $empty_data;
|
|
|
- $data[$key]->label = date("M Y", mktime(0, 0, 0, $month, 1, date("Y")));
|
|
|
+ $data[$key]->label = $label;
|
|
|
+
|
|
|
+ foreach($region_data as &$r) {
|
|
|
+ $r[$key] = clone $empty_data;
|
|
|
+ $r[$key]->label = $label;
|
|
|
+ }
|
|
|
+
|
|
|
+ foreach($area_manager_data as &$a) {
|
|
|
+ $a[$key] = clone $empty_data;
|
|
|
+ $a[$key]->label = $label;
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
break;
|
|
|
@@ -127,10 +184,25 @@ if($submit) {
|
|
|
case "quarterly":
|
|
|
default:
|
|
|
|
|
|
+ $resolution_name = "Quarter";
|
|
|
+
|
|
|
foreach(range(1, 4) as $quarter) {
|
|
|
+
|
|
|
+ $label = "Q$quarter $year";
|
|
|
+
|
|
|
$key = "$year-$quarter";
|
|
|
$data[$key] = clone $empty_data;
|
|
|
- $data[$key]->label = "Q$quarter $year";
|
|
|
+ $data[$key]->label = $label;
|
|
|
+
|
|
|
+ foreach($region_data as &$r) {
|
|
|
+ $r[$key] = clone $empty_data;
|
|
|
+ $r[$key]->label = $label;
|
|
|
+ }
|
|
|
+
|
|
|
+ foreach($area_manager_data as &$a) {
|
|
|
+ $a[$key] = clone $empty_data;
|
|
|
+ $a[$key]->label = $label;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
break;
|
|
|
@@ -138,18 +210,29 @@ if($submit) {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ $max_unix = 0;
|
|
|
+
|
|
|
// Increment counts based on test results
|
|
|
foreach($tests as $test) {
|
|
|
|
|
|
$tester = $test->getTester();
|
|
|
+ $location = $test->getLocation();
|
|
|
+
|
|
|
+ $region = $location->region;
|
|
|
+ $area_manager = $location->area_manager;
|
|
|
|
|
|
$dt = new DateTime($test->dts_start . " UTC");
|
|
|
$dt->setTimezone(new DateTimeZone(TIMEZONE));
|
|
|
|
|
|
+ $unix = $dt->format("U");
|
|
|
$year = $dt->format("Y");
|
|
|
$month = $dt->format("m");
|
|
|
$quarter = ceil($month / 3);
|
|
|
|
|
|
+ if($unix > $max_unix) {
|
|
|
+ $max_unix = $unix;
|
|
|
+ }
|
|
|
+
|
|
|
switch($date_resolution) {
|
|
|
case "monthly":
|
|
|
$key = "$year-$month";
|
|
|
@@ -162,13 +245,20 @@ if($submit) {
|
|
|
|
|
|
$data[$key]->testCount++;
|
|
|
|
|
|
+ $stage_key = "stage" . $test->challenge_stage . "Count";
|
|
|
+ $data[$key]->$stage_key++;
|
|
|
+
|
|
|
if($test->pass) {
|
|
|
$data[$key]->passCount++;
|
|
|
$total_data->passCount++;
|
|
|
+ if($region) $region_data[$region][$key]->passCount++;
|
|
|
+ if($area_manager) $area_manager_data[$area_manager][$key]->passCount++;
|
|
|
}
|
|
|
else {
|
|
|
$data[$key]->failCount++;
|
|
|
$total_data->failCount++;
|
|
|
+ if($region) $region_data[$region][$key]->failCount++;
|
|
|
+ if($area_manager) $area_manager_data[$area_manager][$key]->failCount++;
|
|
|
}
|
|
|
|
|
|
if($tester->gender == "M") {
|
|
|
@@ -212,11 +302,24 @@ if($submit) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ $current_month = date("m", $max_unix);
|
|
|
+ $current_quarter = ceil(date("n", $max_unix) / 3);
|
|
|
|
|
|
$x_data_labels = array_values(array_map(function($d) {
|
|
|
return $d->label;
|
|
|
}, $data));
|
|
|
|
|
|
+ // Current Period
|
|
|
+ if($date_resolution == "monthly") {
|
|
|
+ $key = date("Y") . "-" . $current_month;
|
|
|
+ $current_period_name = date("M Y", $max_unix);
|
|
|
+ }
|
|
|
+ if($date_resolution == "quarterly") {
|
|
|
+ $key = date("Y") . "-" . $current_quarter;
|
|
|
+ $current_period_name = "Q" . $current_quarter . " " . date("Y", $max_unix);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
// Challenger Gender
|
|
|
$chart = new Chart;
|
|
|
$chart->setType("pie");
|
|
|
@@ -265,7 +368,50 @@ if($submit) {
|
|
|
]);
|
|
|
$charts[] = $chart;
|
|
|
|
|
|
- // Tester Genders by Month
|
|
|
+ // Performance by Period
|
|
|
+ $performance = array_values(array_map(function($d) {
|
|
|
+ if($d->testCount == 0) return 0;
|
|
|
+ return round(($d->passCount / $d->testCount) * 100);
|
|
|
+ }, $data));
|
|
|
+
|
|
|
+ $chart = new Chart;
|
|
|
+ $chart->setType("bar");
|
|
|
+ $chart->setTitle("Performance by $resolution_name");
|
|
|
+ $chart->setLabels($x_data_labels);
|
|
|
+ $chart->addDataset("Performance (%)", $performance, [
|
|
|
+ "background_colours" => "#2196F3"
|
|
|
+ ]);
|
|
|
+ $charts[] = $chart;
|
|
|
+
|
|
|
+ // Point of Challenge (Current Period)
|
|
|
+
|
|
|
+ $period_data = $data[$key];
|
|
|
+
|
|
|
+ $chart = new Chart;
|
|
|
+ $chart->setType("pie");
|
|
|
+ $chart->setTitle("$current_period_name Performance by Point of Challenge");
|
|
|
+ $chart->setLabels(["On Entry", "While Browsing", "During Play", "On Exit", "No Challenge"]);
|
|
|
+ $chart->addDataset("Counts", [
|
|
|
+ $period_data->stage1Count,
|
|
|
+ $period_data->stage2Count,
|
|
|
+ $period_data->stage3Count,
|
|
|
+ $period_data->stage4Count,
|
|
|
+ $period_data->stage5Count,
|
|
|
+ ], [
|
|
|
+ "background_colours" => [
|
|
|
+ "#4CAF50",
|
|
|
+ "#FFEB3B",
|
|
|
+ "#FBC02D",
|
|
|
+ "#FFAB91",
|
|
|
+ "#F44336",
|
|
|
+ ]
|
|
|
+ ]);
|
|
|
+ $charts[] = $chart;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ // Tester Genders by Period
|
|
|
$male_counts = array_values(array_map(function($d) {
|
|
|
return $d->maleTesterCount;
|
|
|
}, $data));
|
|
|
@@ -276,7 +422,7 @@ if($submit) {
|
|
|
|
|
|
$chart = new Chart;
|
|
|
$chart->setType("bar");
|
|
|
- $chart->setTitle("Tester Gender by Month");
|
|
|
+ $chart->setTitle("Tester Gender by $resolution_name");
|
|
|
$chart->setLabels($x_data_labels);
|
|
|
$chart->addDataset("Male", $male_counts, [
|
|
|
"background_colours" => "#2196F3"
|
|
|
@@ -286,20 +432,26 @@ if($submit) {
|
|
|
]);
|
|
|
$charts[] = $chart;
|
|
|
|
|
|
- // Test Count
|
|
|
+ // Test Count by Period
|
|
|
$test_counts = array_values(array_map(function($d) {
|
|
|
return $d->testCount;
|
|
|
}, $data));
|
|
|
|
|
|
$chart = new Chart;
|
|
|
$chart->setType("bar");
|
|
|
- $chart->setTitle("Tests by Month");
|
|
|
+ $chart->setTitle("Tests by $resolution_name");
|
|
|
$chart->setLabels($x_data_labels);
|
|
|
$chart->addDataset("Tests", $test_counts, [
|
|
|
"background_colours" => "#2196F3"
|
|
|
]);
|
|
|
$charts[] = $chart;
|
|
|
|
|
|
+ if($has_regions) {
|
|
|
+ }
|
|
|
+
|
|
|
+ if($has_area_managers) {
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
|
|
|
}
|
|
|
@@ -314,7 +466,7 @@ if($submit) {
|
|
|
|
|
|
|
|
|
View::includeOnce("header", compact("page_title"));
|
|
|
-View::include("performance", compact("customer", "date_range", "date_resolution", "all_projects", "project_ids", "charts", "data", "total_data"));
|
|
|
+View::include("performance", compact("customer", "date_range", "date_resolution", "all_projects", "project_ids", "charts", "data", "total_data", "locations_missing_region", "locations_missing_area_manager"));
|
|
|
View::includeOnce("footer");
|
|
|
|
|
|
?>
|