|
|
@@ -0,0 +1,320 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+Core::addScript("public/js/Chart.bundle.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");
|
|
|
+$date_resolution = http::value("date_resolution");
|
|
|
+$project_ids = http::value("project_ids", "int");
|
|
|
+if(!is_array($project_ids)) $project_ids = [];
|
|
|
+
|
|
|
+$all_projects = Project::query([
|
|
|
+ "customer_id" => $customer->id
|
|
|
+]);
|
|
|
+
|
|
|
+$data = [];
|
|
|
+
|
|
|
+$charts = [];
|
|
|
+
|
|
|
+$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,
|
|
|
+ "id" => $project_ids,
|
|
|
+ ]);
|
|
|
+
|
|
|
+ $tests = Test::query([
|
|
|
+ "project_id" => $project_ids,
|
|
|
+ "status" => Test::STATUS_COMPLETED
|
|
|
+ ]);
|
|
|
+
|
|
|
+ User::load(array_column($tests, "tester_id"));
|
|
|
+
|
|
|
+ $min_year = date("Y");
|
|
|
+ $max_year = date("Y");
|
|
|
+
|
|
|
+ switch($date_range) {
|
|
|
+
|
|
|
+
|
|
|
+ case "ytd":
|
|
|
+ // Nothing to do
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+
|
|
|
+ case "custom":
|
|
|
+ // TODO
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ $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,
|
|
|
+ ];
|
|
|
+
|
|
|
+ $total_data = (object) [
|
|
|
+ "maleTesterCount" => 0,
|
|
|
+ "femaleTesterCount" => 0,
|
|
|
+ "maleChallengerCount" => 0,
|
|
|
+ "femaleChallengerCount" => 0,
|
|
|
+ "passCount" => 0,
|
|
|
+ "failCount" => 0,
|
|
|
+ ];
|
|
|
+
|
|
|
+
|
|
|
+ // Initialise date-array based on date range and resolution
|
|
|
+ for($year = $min_year; $year <= $max_year; $year++) {
|
|
|
+ switch($date_resolution) {
|
|
|
+ case "monthly":
|
|
|
+
|
|
|
+ foreach(range(1, 12) as $month) {
|
|
|
+ $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")));
|
|
|
+ }
|
|
|
+
|
|
|
+ break;
|
|
|
+
|
|
|
+ case "quarterly":
|
|
|
+ default:
|
|
|
+
|
|
|
+ foreach(range(1, 4) as $quarter) {
|
|
|
+ $key = "$year-$quarter";
|
|
|
+ $data[$key] = clone $empty_data;
|
|
|
+ $data[$key]->label = "Q$quarter $year";
|
|
|
+ }
|
|
|
+
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ // Increment counts based on test results
|
|
|
+ foreach($tests as $test) {
|
|
|
+
|
|
|
+ $tester = $test->getTester();
|
|
|
+
|
|
|
+ $dt = new DateTime($test->dts_start . " UTC");
|
|
|
+ $dt->setTimezone(new DateTimeZone(TIMEZONE));
|
|
|
+
|
|
|
+ $year = $dt->format("Y");
|
|
|
+ $month = $dt->format("m");
|
|
|
+ $quarter = ceil($month / 3);
|
|
|
+
|
|
|
+ switch($date_resolution) {
|
|
|
+ case "monthly":
|
|
|
+ $key = "$year-$month";
|
|
|
+ break;
|
|
|
+ case "quarterly":
|
|
|
+ default:
|
|
|
+ $key = "$year-$quarter";
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ $data[$key]->testCount++;
|
|
|
+
|
|
|
+ if($test->pass) {
|
|
|
+ $data[$key]->passCount++;
|
|
|
+ $total_data->passCount++;
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ $data[$key]->failCount++;
|
|
|
+ $total_data->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++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ $x_data_labels = array_values(array_map(function($d) {
|
|
|
+ return $d->label;
|
|
|
+ }, $data));
|
|
|
+
|
|
|
+ // Challenger Gender
|
|
|
+ $chart = new Chart;
|
|
|
+ $chart->setType("pie");
|
|
|
+ $chart->setTitle("Staff Gender");
|
|
|
+ $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");
|
|
|
+ $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");
|
|
|
+ $chart->setLabels(["Pass", "Fail"]);
|
|
|
+ $chart->addDataset("Counts", [
|
|
|
+ $total_data->passCount,
|
|
|
+ $total_data->failCount,
|
|
|
+ ], [
|
|
|
+ "background_colours" => [
|
|
|
+ "#4CAF50",
|
|
|
+ "#F44336",
|
|
|
+ ]
|
|
|
+ ]);
|
|
|
+ $charts[] = $chart;
|
|
|
+
|
|
|
+ // Tester Genders by Month
|
|
|
+ $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 Month");
|
|
|
+ $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
|
|
|
+ $test_counts = array_values(array_map(function($d) {
|
|
|
+ return $d->testCount;
|
|
|
+ }, $data));
|
|
|
+
|
|
|
+ $chart = new Chart;
|
|
|
+ $chart->setType("bar");
|
|
|
+ $chart->setTitle("Tests by Month");
|
|
|
+ $chart->setLabels($x_data_labels);
|
|
|
+ $chart->addDataset("Tests", $test_counts, [
|
|
|
+ "background_colours" => "#2196F3"
|
|
|
+ ]);
|
|
|
+ $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", "date_resolution", "all_projects", "project_ids", "charts", "data", "total_data"));
|
|
|
+View::includeOnce("footer");
|
|
|
+
|
|
|
+?>
|