|
|
@@ -0,0 +1,714 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+Core::addScript("public/js/Chart.bundle.min.js");
|
|
|
+Core::addScript("public/js/chartjs-plugin-datalabels.min.js");
|
|
|
+Core::addScript("public/js/app-performance.js");
|
|
|
+
|
|
|
+Core::addBreadcrumb("/account", "Account");
|
|
|
+Core::addBreadcrumb("/account/performance", "Performance");
|
|
|
+
|
|
|
+$customer = Customer::getForAdmin();
|
|
|
+if(!$customer) throw new Exception("You do not have permission to access this page.");
|
|
|
+
|
|
|
+$page_title = "$customer->name Performance";
|
|
|
+
|
|
|
+Core::addBreadcrumb("/account/performance?customer_id=$customer->id", $page_title);
|
|
|
+
|
|
|
+$date_range = http::value("date_range");
|
|
|
+if(!$date_range) $date_range = "ytd";
|
|
|
+
|
|
|
+$date_resolution = http::value("date_resolution");
|
|
|
+
|
|
|
+$from_quarter = http::value("from_quarter");
|
|
|
+$to_quarter = http::value("to_quarter");
|
|
|
+
|
|
|
+$all_projects = Project::query([
|
|
|
+ "customer_id" => $customer->id
|
|
|
+]);
|
|
|
+
|
|
|
+$data = [];
|
|
|
+$region_data = [];
|
|
|
+$area_manager_data = [];
|
|
|
+$total_data = false;
|
|
|
+
|
|
|
+$locations_missing_region = [];
|
|
|
+$locations_missing_area_manager = [];
|
|
|
+
|
|
|
+$charts = [];
|
|
|
+
|
|
|
+$colours = [
|
|
|
+ "#f44336",
|
|
|
+ "#673ab7",
|
|
|
+ "#03a9f4",
|
|
|
+ "#4caf50",
|
|
|
+ "#ffeb3b",
|
|
|
+ "#ff5722",
|
|
|
+ "#607d8b",
|
|
|
+ "#e91e63",
|
|
|
+ "#3f51b5",
|
|
|
+ "#00bcd4",
|
|
|
+ "#8bc34a",
|
|
|
+ "#ffc107",
|
|
|
+ "#795548",
|
|
|
+ "#9c27b0",
|
|
|
+ "#2196f3",
|
|
|
+ "#009688",
|
|
|
+ "#cddc39",
|
|
|
+ "#ff9800",
|
|
|
+ "#9e9e9e",
|
|
|
+];
|
|
|
+
|
|
|
+$project_ids = [];
|
|
|
+
|
|
|
+$submit = http::value("submit");
|
|
|
+if($submit) {
|
|
|
+ try {
|
|
|
+ Core::validateCSRFToken($submit);
|
|
|
+
|
|
|
+ $form_exception = new FormException;
|
|
|
+ if($form_exception->hasErrors()) throw $form_exception;
|
|
|
+
|
|
|
+
|
|
|
+ // Get all tests
|
|
|
+ $projects = Project::query([
|
|
|
+ "customer_id" => $customer->id
|
|
|
+ ]);
|
|
|
+
|
|
|
+ $project_ids = array_column($projects, "id");
|
|
|
+
|
|
|
+ $tests = Test::query([
|
|
|
+ "project_id" => $project_ids,
|
|
|
+ "status" => Test::STATUS_COMPLETED
|
|
|
+ ]);
|
|
|
+
|
|
|
+ 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");
|
|
|
+
|
|
|
+ $min_unix = strtotime("$min_year-01-01 UTC");
|
|
|
+ $max_unix = strtotime("$max_year-12-31 23:59:59 UTC");
|
|
|
+
|
|
|
+ switch($date_range) {
|
|
|
+ case "ytd":
|
|
|
+ // Nothing to do
|
|
|
+ $date_range_label = "YTD";
|
|
|
+ break;
|
|
|
+
|
|
|
+ case "unbound":
|
|
|
+ // Work out year range
|
|
|
+ foreach($tests as $test) {
|
|
|
+ $dt = new DateTime($test->dts_start . " UTC");
|
|
|
+ $dt->setTimezone(new DateTimeZone(TIMEZONE));
|
|
|
+
|
|
|
+ $year = $dt->format("Y");
|
|
|
+
|
|
|
+ if($year < $min_year) $min_year = $year;
|
|
|
+ if($year > $max_year) $max_year = $year;
|
|
|
+ }
|
|
|
+ $date_range_label = "$min_year - $max_year";
|
|
|
+ break;
|
|
|
+
|
|
|
+ case "custom":
|
|
|
+ $check = strcmp($from_quarter, $to_quarter);
|
|
|
+ if($check > 0) {
|
|
|
+ $temp = $to_quarter;
|
|
|
+ $from_quarter = $to_quarter;
|
|
|
+ $to_quarter = $temp;
|
|
|
+ }
|
|
|
+
|
|
|
+ list($min_year, $min_quarter) = explode("-", $from_quarter);
|
|
|
+ list($max_year, $max_quarter) = explode("-", $to_quarter);
|
|
|
+
|
|
|
+ switch($min_quarter) {
|
|
|
+ case 1: $unix_string = "$min_year-01-01 UTC"; break;
|
|
|
+ case 2: $unix_string = "$min_year-04-01 UTC"; break;
|
|
|
+ case 3: $unix_string = "$min_year-07-01 UTC"; break;
|
|
|
+ case 4: $unix_string = "$min_year-10-01 UTC"; break;
|
|
|
+ }
|
|
|
+
|
|
|
+ $min_unix = strtotime($unix_string);
|
|
|
+
|
|
|
+ switch($max_quarter) {
|
|
|
+ case 1: $unix_string = "$max_year-03-31 23:59:59 UTC"; break;
|
|
|
+ case 2: $unix_string = "$max_year-06-30 23:59:59 UTC"; break;
|
|
|
+ case 3: $unix_string = "$max_year-09-30 23:59:59 UTC"; break;
|
|
|
+ case 4: $unix_string = "$max_year-12-31 23:59:59 UTC"; break;
|
|
|
+ }
|
|
|
+
|
|
|
+ $max_unix = strtotime($unix_string);
|
|
|
+
|
|
|
+ $date_range_label = "$min_year Q$min_quarter - $max_year Q$max_quarter";
|
|
|
+
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ // Filter tests based on date range
|
|
|
+ $tests = array_filter($tests, function($test) use ($min_unix, $max_unix) {
|
|
|
+
|
|
|
+ $dt = new DateTime($test->dts_start . " UTC");
|
|
|
+ $unix = $dt->format("U");
|
|
|
+
|
|
|
+ if($unix < $min_unix) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ if($unix > $max_unix) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ return true;
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+ $empty_data = (object) [
|
|
|
+ "label" => "",
|
|
|
+ "testCount" => 0,
|
|
|
+ "passCount" => 0,
|
|
|
+ "failCount" => 0,
|
|
|
+
|
|
|
+ "maleTesterCount" => 0,
|
|
|
+ "femaleTesterCount" => 0,
|
|
|
+ "maleChallengerCount" => 0,
|
|
|
+ "femaleChallengerCount" => 0,
|
|
|
+
|
|
|
+ "maleChallengeMaleCount" => 0,
|
|
|
+ "maleChallengeMalePassCount" => 0,
|
|
|
+
|
|
|
+ "maleChallengeFemaleCount" => 0,
|
|
|
+ "maleChallengeFemalePassCount" => 0,
|
|
|
+
|
|
|
+ "femaleChallengeMaleCount" => 0,
|
|
|
+ "femaleChallengeMalePassCount" => 0,
|
|
|
+
|
|
|
+ "femaleChallengeFemaleCount" => 0,
|
|
|
+ "femaleChallengeFemalePassCount" => 0,
|
|
|
+
|
|
|
+ "stage1Count" => 0,
|
|
|
+ "stage2Count" => 0,
|
|
|
+ "stage3Count" => 0,
|
|
|
+ "stage4Count" => 0,
|
|
|
+ "stage5Count" => 0,
|
|
|
+ ];
|
|
|
+
|
|
|
+ $total_data = (object) [
|
|
|
+ "maleTesterCount" => 0,
|
|
|
+ "femaleTesterCount" => 0,
|
|
|
+ "maleChallengerCount" => 0,
|
|
|
+ "femaleChallengerCount" => 0,
|
|
|
+ "testCount" => 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
|
|
|
+ $keys = [];
|
|
|
+ $key_labels = [];
|
|
|
+
|
|
|
+ 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 = $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;
|
|
|
+ }
|
|
|
+
|
|
|
+ $keys[] = $key;
|
|
|
+ $key_labels[] = $label;
|
|
|
+ }
|
|
|
+
|
|
|
+ break;
|
|
|
+
|
|
|
+ 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 = $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;
|
|
|
+ }
|
|
|
+
|
|
|
+ $keys[] = $key;
|
|
|
+ $key_labels[] = $label;
|
|
|
+ }
|
|
|
+
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ $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";
|
|
|
+ break;
|
|
|
+ case "quarterly":
|
|
|
+ default:
|
|
|
+ $key = "$year-$quarter";
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ $total_data->testCount++;
|
|
|
+ $data[$key]->testCount++;
|
|
|
+ if($region) $region_data[$region][$key]->testCount++;
|
|
|
+ if($area_manager) $area_manager_data[$area_manager][$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") {
|
|
|
+ $data[$key]->maleTesterCount++;
|
|
|
+ $total_data->maleTesterCount++;
|
|
|
+ }
|
|
|
+ if($tester->gender == "F") {
|
|
|
+ $data[$key]->femaleTesterCount++;
|
|
|
+ $total_data->femaleTesterCount++;
|
|
|
+ }
|
|
|
+
|
|
|
+ if($test->challenger_gender == "M") {
|
|
|
+ $data[$key]->maleChallengerCount++;
|
|
|
+ $total_data->maleChallengerCount++;
|
|
|
+ }
|
|
|
+ if($test->challenger_gender == "F") {
|
|
|
+ $data[$key]->femaleChallengerCount++;
|
|
|
+ $total_data->femaleChallengerCount++;
|
|
|
+ }
|
|
|
+
|
|
|
+ if($tester->gender == "M") {
|
|
|
+ if($test->challenger_gender == "M") {
|
|
|
+ $data[$key]->maleChallengeMaleCount++;
|
|
|
+ if($test->pass) $data[$key]->maleChallengeMalePassCount++;
|
|
|
+ }
|
|
|
+ if($test->challenger_gender == "F") {
|
|
|
+ $data[$key]->femaleChallengeMaleCount++;
|
|
|
+ if($test->pass) $data[$key]->femaleChallengeMalePassCount++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if($tester->gender == "F") {
|
|
|
+ if($test->challenger_gender == "M") {
|
|
|
+ $data[$key]->maleChallengeFemaleCount++;
|
|
|
+ if($test->pass) $data[$key]->maleChallengeFemalePassCount++;
|
|
|
+ }
|
|
|
+ if($test->challenger_gender == "F") {
|
|
|
+ $data[$key]->femaleChallengeFemaleCount++;
|
|
|
+ if($test->pass) $data[$key]->femaleChallengeFemalePassCount++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ $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);
|
|
|
+ }
|
|
|
+
|
|
|
+ // Tests by Stage
|
|
|
+
|
|
|
+ $chart = new Chart;
|
|
|
+ $chart->setType("pie");
|
|
|
+ $chart->setTitle("Tests by Stage $date_range_label");
|
|
|
+ $chart->setLabels(["On Entry", "While Browsing", "During Play", "On Exit", "No Challenge"]);
|
|
|
+ $chart->addDataset("Counts", [
|
|
|
+ array_sum(array_column($data, "stage1Count")),
|
|
|
+ array_sum(array_column($data, "stage2Count")),
|
|
|
+ array_sum(array_column($data, "stage3Count")),
|
|
|
+ array_sum(array_column($data, "stage4Count")),
|
|
|
+ array_sum(array_column($data, "stage5Count")),
|
|
|
+ ], [
|
|
|
+ "background_colours" => [
|
|
|
+ "#4CAF50",
|
|
|
+ "#FFEB3B",
|
|
|
+ "#FBC02D",
|
|
|
+ "#FFAB91",
|
|
|
+ "#F44336",
|
|
|
+ ]
|
|
|
+ ]);
|
|
|
+ $charts[] = $chart;
|
|
|
+
|
|
|
+
|
|
|
+ // Challenger Gender
|
|
|
+ $chart = new Chart;
|
|
|
+ $chart->setType("pie");
|
|
|
+ $chart->setTitle("Staff Gender $date_range_label");
|
|
|
+ $chart->setLabels(["Male", "Female"]);
|
|
|
+ $chart->addDataset("Counts", [
|
|
|
+ $total_data->maleChallengerCount,
|
|
|
+ $total_data->femaleChallengerCount,
|
|
|
+ ], [
|
|
|
+ "background_colours" => [
|
|
|
+ "#2196F3",
|
|
|
+ "#E91E63",
|
|
|
+ ]
|
|
|
+ ]);
|
|
|
+ $charts[] = $chart;
|
|
|
+
|
|
|
+ // Tester Gender
|
|
|
+ $chart = new Chart;
|
|
|
+ $chart->setType("pie");
|
|
|
+ $chart->setTitle("Tester Gender $date_range_label");
|
|
|
+ $chart->setLabels(["Male", "Female"]);
|
|
|
+ $chart->addDataset("Counts", [
|
|
|
+ $total_data->maleTesterCount,
|
|
|
+ $total_data->femaleTesterCount,
|
|
|
+ ], [
|
|
|
+ "background_colours" => [
|
|
|
+ "#2196F3",
|
|
|
+ "#E91E63",
|
|
|
+ ]
|
|
|
+ ]);
|
|
|
+ $charts[] = $chart;
|
|
|
+
|
|
|
+ // Pass / Fail
|
|
|
+ $chart = new Chart;
|
|
|
+ $chart->setType("pie");
|
|
|
+ $chart->setTitle("Pass / Fail $date_range_label");
|
|
|
+ $chart->setLabels(["Pass", "Fail"]);
|
|
|
+ $chart->addDataset("Counts", [
|
|
|
+ $total_data->passCount,
|
|
|
+ $total_data->failCount,
|
|
|
+ ], [
|
|
|
+ "background_colours" => [
|
|
|
+ "#4CAF50",
|
|
|
+ "#F44336",
|
|
|
+ ]
|
|
|
+ ]);
|
|
|
+ $charts[] = $chart;
|
|
|
+
|
|
|
+ // 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;
|
|
|
+
|
|
|
+ // Monthly Totals by Period
|
|
|
+
|
|
|
+ $test_counts = array_column($data, "testCount");
|
|
|
+ $pass_counts = array_column($data, "passCount");
|
|
|
+ $fail_counts = array_column($data, "failCount");
|
|
|
+
|
|
|
+ $chart = new Chart;
|
|
|
+ $chart->setType("bar");
|
|
|
+ $chart->setTitle("Totals by $resolution_name");
|
|
|
+ $chart->setLabels($x_data_labels);
|
|
|
+ $chart->addYAxis("linear", "left", "y-axis-1");
|
|
|
+ $chart->addYAxis("linear", "right", "y-axis-2", false);
|
|
|
+
|
|
|
+ $chart->addDataset("Test Count", $test_counts, [
|
|
|
+ "background_colours" => "#2196F3",
|
|
|
+ "type" => "bar",
|
|
|
+ "y_axis_id" => "y-axis-1",
|
|
|
+ ]);
|
|
|
+ $chart->addDataset("Pass", $pass_counts, [
|
|
|
+ "background_colours" => "#4CAF50",
|
|
|
+ "type" => "bar",
|
|
|
+ "y_axis_id" => "y-axis-1",
|
|
|
+ ]);
|
|
|
+ $chart->addDataset("Fail", $fail_counts, [
|
|
|
+ "background_colours" => "#F44336",
|
|
|
+ "type" => "bar",
|
|
|
+ "y_axis_id" => "y-axis-1",
|
|
|
+ ]);
|
|
|
+ $chart->addDataset("Performance (%)", $performance, [
|
|
|
+ "border_colours" => "#FFEB3B",
|
|
|
+ "background_colours" => "transparent",
|
|
|
+ "type" => "line",
|
|
|
+ "y_axis_id" => "y-axis-2",
|
|
|
+ ]);
|
|
|
+ $charts[] = $chart;
|
|
|
+
|
|
|
+ // Point of Challenge (Each Period)
|
|
|
+
|
|
|
+ foreach($keys as $index => $key) {
|
|
|
+ $key_label = $key_labels[$index];
|
|
|
+
|
|
|
+ $period_data = $data[$key];
|
|
|
+
|
|
|
+ if($period_data->testCount == 0) continue;
|
|
|
+
|
|
|
+ $chart = new Chart;
|
|
|
+ $chart->setType("pie");
|
|
|
+ $chart->setTitle("$key_label 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));
|
|
|
+
|
|
|
+ $female_counts = array_values(array_map(function($d) {
|
|
|
+ return $d->femaleTesterCount;
|
|
|
+ }, $data));
|
|
|
+
|
|
|
+ $chart = new Chart;
|
|
|
+ $chart->setType("bar");
|
|
|
+ $chart->setTitle("Tester Gender by $resolution_name");
|
|
|
+ $chart->setLabels($x_data_labels);
|
|
|
+ $chart->addDataset("Male", $male_counts, [
|
|
|
+ "background_colours" => "#2196F3"
|
|
|
+ ]);
|
|
|
+ $chart->addDataset("Female", $female_counts, [
|
|
|
+ "background_colours" => "#E91E63"
|
|
|
+ ]);
|
|
|
+ $charts[] = $chart;
|
|
|
+
|
|
|
+ // 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 $resolution_name");
|
|
|
+ $chart->setLabels($x_data_labels);
|
|
|
+ $chart->addDataset("Tests", $test_counts, [
|
|
|
+ "background_colours" => "#2196F3"
|
|
|
+ ]);
|
|
|
+ $charts[] = $chart;
|
|
|
+
|
|
|
+ $pass_counts = array_column($data, "passCount");
|
|
|
+ $fail_counts = array_column($data, "failCount");
|
|
|
+
|
|
|
+
|
|
|
+ if($has_regions) {
|
|
|
+
|
|
|
+ $x_data_labels = array_map(function($key) {
|
|
|
+ return "Region $key";
|
|
|
+ }, $regions);
|
|
|
+
|
|
|
+ // Region Performance (Selected Date Range)
|
|
|
+ $data_values = [];
|
|
|
+ foreach($region_data as $region => $r_data) {
|
|
|
+ $total_region_test_count = array_sum(array_column($r_data, "testCount"));
|
|
|
+ $total_region_pass_count = array_sum(array_column($r_data, "passCount"));
|
|
|
+
|
|
|
+ $data_values[] = ($total_region_test_count == 0) ? 0 : round(($total_region_pass_count * 100) / $total_region_test_count);
|
|
|
+ }
|
|
|
+
|
|
|
+ $chart = new Chart;
|
|
|
+ $chart->setType("bar");
|
|
|
+ $chart->setTitle("Region Performance");
|
|
|
+ $chart->setLabels($x_data_labels);
|
|
|
+ $chart->addDataset("Performance", $data_values , [
|
|
|
+ "background_colours" => "#2196F3"
|
|
|
+ ]);
|
|
|
+ $charts[] = $chart;
|
|
|
+
|
|
|
+ // Region Performance by Period
|
|
|
+ $chart = new Chart;
|
|
|
+ $chart->setType("bar");
|
|
|
+ $chart->setTitle("Region Performance by $resolution_name");
|
|
|
+ $chart->setLabels($x_data_labels);
|
|
|
+
|
|
|
+ foreach($keys as $index => $key) {
|
|
|
+ $data_values = [];
|
|
|
+ foreach($regions as $region) {
|
|
|
+ $r_data = $region_data[$region][$key];
|
|
|
+ $data_values[] = ($r_data->testCount == 0) ? 0 : round(($r_data->passCount * 100) / $r_data->testCount);
|
|
|
+ }
|
|
|
+ $chart->addDataset($key_labels[$index], $data_values, ["background_colours" => $colours[$index]]);
|
|
|
+ }
|
|
|
+
|
|
|
+ $charts[] = $chart;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ if($has_area_managers) {
|
|
|
+
|
|
|
+ $x_data_labels = array_map(function($key) {
|
|
|
+ return "$key";
|
|
|
+ }, $area_managers);
|
|
|
+
|
|
|
+ // Area Performance (Selected Date Range)
|
|
|
+ $data_values = [];
|
|
|
+ foreach($area_manager_data as $area_manager => $a_data) {
|
|
|
+ $total_area_manager_test_count = array_sum(array_column($a_data, "testCount"));
|
|
|
+ $total_area_manager_pass_count = array_sum(array_column($a_data, "passCount"));
|
|
|
+ $total_area_manager_fail_count = array_sum(array_column($a_data, "failCount"));
|
|
|
+
|
|
|
+ $data_values[] = ($total_region_test_count == 0) ? 0 : round(($total_area_manager_pass_count * 100) / $total_area_manager_test_count);
|
|
|
+ }
|
|
|
+
|
|
|
+ $chart = new Chart;
|
|
|
+ $chart->setType("bar");
|
|
|
+ $chart->setTitle("Area Manager Performance");
|
|
|
+ $chart->setLabels($x_data_labels);
|
|
|
+ $chart->addDataset("Performance", $data_values , [
|
|
|
+ "background_colours" => "#2196F3"
|
|
|
+ ]);
|
|
|
+ $charts[] = $chart;
|
|
|
+
|
|
|
+ // Area Performance by Period
|
|
|
+ $chart = new Chart;
|
|
|
+ $chart->setType("bar");
|
|
|
+ $chart->setTitle("Area Manager Performance by $resolution_name");
|
|
|
+ $chart->setLabels($x_data_labels);
|
|
|
+
|
|
|
+ foreach($keys as $index => $key) {
|
|
|
+ $data_values = [];
|
|
|
+ foreach($area_managers as $area_manager) {
|
|
|
+ $a_data = $area_manager_data[$area_manager][$key];
|
|
|
+ $data_values[] = ($a_data->testCount == 0) ? 0 : round(($a_data->passCount * 100) / $a_data->testCount);
|
|
|
+ }
|
|
|
+ $chart->addDataset($key_labels[$index], $data_values, ["background_colours" => $colours[$index]]);
|
|
|
+ }
|
|
|
+
|
|
|
+ $charts[] = $chart;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+ catch(FormException $e) {
|
|
|
+ $e->generateAlerts();
|
|
|
+ }
|
|
|
+ catch(Exception $e) {
|
|
|
+ Core::addAlert("danger", $e->getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+View::includeOnce("header", compact("page_title"));
|
|
|
+View::include("performance", compact("customer", "date_range", "from_quarter", "to_quarter", "date_resolution", "all_projects", "project_ids", "charts", "data", "total_data", "locations_missing_region", "locations_missing_area_manager", "region_data"));
|
|
|
+View::includeOnce("footer");
|
|
|
+
|
|
|
+?>
|