Parcourir la source

Adds region and area manager charts.

Alan Lam il y a 8 ans
Parent
commit
f0a0837b69
6 fichiers modifiés avec 269 ajouts et 126 suppressions
  1. 121 6
      controllers/performance.php
  2. 0 0
      public/css/bootstrap.min.css
  3. 10 4
      scss/_main.scss
  4. 53 52
      views/footer.php
  5. 56 51
      views/header.php
  6. 29 13
      views/performance.php

+ 121 - 6
controllers/performance.php

@@ -15,8 +15,6 @@ Core::addBreadcrumb("/account/performance?customer_id=$customer->id", $page_titl
 
 $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
@@ -32,6 +30,28 @@ $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",
+];
+
 $submit = http::value("submit");
 if($submit) {
 	try {
@@ -43,10 +63,11 @@ if($submit) {
 
 		// Get all tests
 		$projects = Project::query([
-			"customer_id" => $customer->id,
-			"id" => $project_ids,
+			"customer_id" => $customer->id
 		]);
 
+		$project_ids = array_column($projects, "id");
+
 		$tests = Test::query([
 			"project_id" => $project_ids,
 			"status" => Test::STATUS_COMPLETED
@@ -152,6 +173,9 @@ if($submit) {
 		$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":
@@ -177,6 +201,8 @@ if($submit) {
 							$a[$key]->label = $label;
 						}
 
+						$keys[] = $key;
+						$key_labels[] = $label;
 					}
 
 					break;
@@ -203,11 +229,13 @@ if($submit) {
 							$a[$key] = clone $empty_data;
 							$a[$key]->label = $label;
 						}
+
+						$keys[] = $key;
+						$key_labels[] = $label;
 					}
 
 					break;
 			}
-
 		}
 
 		$max_unix = 0;
@@ -244,6 +272,8 @@ if($submit) {
 			}
 
 			$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++;
@@ -446,10 +476,95 @@ if($submit) {
 		]);
 		$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;
+
 		}
 
 
@@ -466,7 +581,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", "locations_missing_region", "locations_missing_area_manager"));
+View::include("performance", compact("customer", "date_range", "date_resolution", "all_projects", "project_ids", "charts", "data", "total_data", "locations_missing_region", "locations_missing_area_manager", "region_data"));
 View::includeOnce("footer");
 
 ?>

Fichier diff supprimé car celui-ci est trop grand
+ 0 - 0
public/css/bootstrap.min.css


+ 10 - 4
scss/_main.scss

@@ -1,5 +1,14 @@
 body {
-	padding-top: 56px;
+	display: flex;
+	flex-flow: column;
+	height: 100%;
+}
+
+body > .page-header {
+}
+
+body > .page-content {
+	flex: 1;
 }
 
 .text-monospace {
@@ -80,9 +89,6 @@ body {
 }
 
 .breadcrumb-nav {
-	position: sticky;
-	top: 56px;
-	z-index: 100;
 }
 
 ol.breadcrumb {

+ 53 - 52
views/footer.php

@@ -1,66 +1,67 @@
-		<?php
-		if(Core::$show_footer_content) {
-		?>
+			<?php
+			if(Core::$show_footer_content) {
+			?>
 
-		<footer class="my-3">
-			<div class="container">
+			<footer class="my-3">
+				<div class="container">
 
-				<hr />
+					<hr />
 
-				<div class="row">
-					<div class="col-md mb-3">
-						<h5>Navigation</h5>
-						<ul class="nav flex-column">
-							<li><a href="/home">Home</a></li>
+					<div class="row">
+						<div class="col-md mb-3">
+							<h5>Navigation</h5>
+							<ul class="nav flex-column">
+								<li><a href="/home">Home</a></li>
 
-							<?php
-							if(!Core::$user) {
-								?>
-								<li><a href="/services">Services</a></li>
-								<li><a href="/become-a-tester">Become a tester</a></li>
-								<li><a href="/contact">Contact</a></li>
-								<li><a href="/jobs">Jobs</a></li>
 								<?php
-							}
-							else {
+								if(!Core::$user) {
+									?>
+									<li><a href="/services">Services</a></li>
+									<li><a href="/become-a-tester">Become a tester</a></li>
+									<li><a href="/contact">Contact</a></li>
+									<li><a href="/jobs">Jobs</a></li>
+									<?php
+								}
+								else {
+									?>
+									<li><a href="/contact">Contact</a></li>
+									<li><a href="/account">Account</a></li>
+									<?php
+								}
 								?>
-								<li><a href="/contact">Contact</a></li>
-								<li><a href="/account">Account</a></li>
-								<?php
-							}
-							?>
-						</ul>
-					</div>
-					<div class="col-md mb-3">
-						<h5>Follow Us</h5>
-						<ul class="nav flex-column">
-							<li><i class="fab fa-fw fa-facebook"></i> <a href="https://www.facebook.com/checkpolicy" target="_blank">Facebook</a></li>
-							<li><i class="fab fa-fw fa-whatsapp"></i> <a href="https://api.whatsapp.com/send?phone=447841353775" target="_blank">WhatsApp</a></li>
-						</ul>
-					</div>
-					<div class="col-md mb-3">
-						<h5>Our Location</h5>
-						<ul class="nav flex-column">
-							<li><i class="fal fa-fw fa-map-marker"></i> 8 Market Street, Liskeard, Cornwall, PL14 3JJ</li>
-							<li><i class="fal fa-fw fa-phone"></i> <a href="tel:07841+353775">07841 353775</a></li>
-							<li><i class="fal fa-fw fa-envelope"></i> <a href="mailto:admin@<?=DOMAIN?>">admin@<?=DOMAIN?></a></li>
-						</ul>
+							</ul>
+						</div>
+						<div class="col-md mb-3">
+							<h5>Follow Us</h5>
+							<ul class="nav flex-column">
+								<li><i class="fab fa-fw fa-facebook"></i> <a href="https://www.facebook.com/checkpolicy" target="_blank">Facebook</a></li>
+								<li><i class="fab fa-fw fa-whatsapp"></i> <a href="https://api.whatsapp.com/send?phone=447841353775" target="_blank">WhatsApp</a></li>
+							</ul>
+						</div>
+						<div class="col-md mb-3">
+							<h5>Our Location</h5>
+							<ul class="nav flex-column">
+								<li><i class="fal fa-fw fa-map-marker"></i> 8 Market Street, Liskeard, Cornwall, PL14 3JJ</li>
+								<li><i class="fal fa-fw fa-phone"></i> <a href="tel:07841+353775">07841 353775</a></li>
+								<li><i class="fal fa-fw fa-envelope"></i> <a href="mailto:admin@<?=DOMAIN?>">admin@<?=DOMAIN?></a></li>
+							</ul>
+						</div>
 					</div>
-				</div>
 
 
-				<div class="text-center">
-					&copy; <?=date("Y")?> <?=APP_NAME?><br />
-					<small>
-						<a href="/privacy-policy">Privacy Policy</a>
-					</small>
+					<div class="text-center">
+						&copy; <?=date("Y")?> <?=APP_NAME?><br />
+						<small>
+							<a href="/privacy-policy">Privacy Policy</a>
+						</small>
+					</div>
 				</div>
-			</div>
 
-		</footer>
-		<?php
-		}
-		?>
+			</footer>
+			<?php
+			}
+			?>
+		</div> <!-- .page-content -->
 
 		<?php
 		$scripts = Core::getScripts();

+ 56 - 51
views/header.php

@@ -48,7 +48,8 @@ if(!PRODUCTION) {
 	</head>
 	<body>
 
-		<div class="fixed-top" style="overflow-y: auto; max-height: 100%;">
+		<div class="page-header">
+
 			<nav class="navbar navbar-expand-lg navbar-light bg-light">
 				<div class="navbar-brand p-0">
 					<a href="/">
@@ -105,70 +106,74 @@ if(!PRODUCTION) {
 				</div>
 
 			</nav>
-		</div>
-
-		<?php
-		if(count(Core::$breadcrumbs) > 1) {
-			View::include("breadcrumbs");
-		}
 
-		if(!PRODUCTION) {
-			$style = (count(Core::$breadcrumbs) > 1) ? "margin-top: -1rem;" : "";
-			?>
-			<div class="p-2 mb-3 bg-danger text-white text-center" style="<?=$style?>">
-				<strong>PLEASE NOTE:</strong> This is a development version of the site.
-			</div>
 			<?php
-		}
+			if(count(Core::$breadcrumbs) > 1) {
+				View::include("breadcrumbs");
+			}
 
-		if(Core::$show_alerts) {
-			$alerts = Core::getAlerts();
-			if($alerts) {
+			if(!PRODUCTION) {
+				$style = (count(Core::$breadcrumbs) > 1) ? "margin-top: -1rem;" : "";
 				?>
-				<div class="container">
+				<div class="p-2 mb-3 bg-danger text-white text-center" style="<?=$style?>">
+					<strong>PLEASE NOTE:</strong> This is a development version of the site.
+				</div>
 				<?php
-				foreach($alerts as $alert) {
-					list($class, $message) = $alert;
+			}
 
-					$icon = "info-circle";
-					if($class == "success") $icon = "check";
-					if($class == "warning") $icon = "exclamation-triangle";
-					if($class == "error") $icon = "exclamation-circle";
+		?>
+		</div>
+		<div class="page-content">
+			<?php
 
+			if(Core::$show_alerts) {
+				$alerts = Core::getAlerts();
+				if($alerts) {
+					?>
+					<div class="container">
+					<?php
+					foreach($alerts as $alert) {
+						list($class, $message) = $alert;
+
+						$icon = "info-circle";
+						if($class == "success") $icon = "check";
+						if($class == "warning") $icon = "exclamation-triangle";
+						if($class == "error") $icon = "exclamation-circle";
+
+						?>
+						<div class="alert alert-<?=$class?> alert-dismissable fade show">
+							<button type="button" class="close" data-dismiss="alert" aria-label="Close">
+								<span aria-hidden="true">&times;</span>
+							</button>
+							<i class="fal fa-fw fa-<?=$icon?>"></i> <?=htmlspecialchars($message)?>
+						</div>
+						<?php
+					}
 					?>
-					<div class="alert alert-<?=$class?> alert-dismissable fade show">
-						<button type="button" class="close" data-dismiss="alert" aria-label="Close">
-							<span aria-hidden="true">&times;</span>
-						</button>
-						<i class="fal fa-fw fa-<?=$icon?>"></i> <?=htmlspecialchars($message)?>
 					</div>
 					<?php
 				}
-				?>
-				</div>
-				<?php
 			}
-		}
 
-		if(!Core::$cookie_alert_shown) {
-			?>
-			<div class="container mt-3">
-				<div class="alert alert-info alert-dismissable fade show">
-					<button type="button" class="close" data-dismiss="alert" aria-label="Close">
-						<span aria-hidden="true">&times;</span>
-					</button>
-					<div class="row">
-						<div class="col-auto pr-0">
-							<i class="fal fa-fw fa-info-circle"></i>
-						</div>
-						<div class="col">
-							<strong>This site uses cookies to improve functionality and personalisation.</strong><br />
-							By continuing to use the site, you consent to our use of cookies and our privacy policy.
+			if(!Core::$cookie_alert_shown) {
+				?>
+				<div class="container mt-3">
+					<div class="alert alert-info alert-dismissable fade show">
+						<button type="button" class="close" data-dismiss="alert" aria-label="Close">
+							<span aria-hidden="true">&times;</span>
+						</button>
+						<div class="row">
+							<div class="col-auto pr-0">
+								<i class="fal fa-fw fa-info-circle"></i>
+							</div>
+							<div class="col">
+								<strong>This site uses cookies to improve functionality and personalisation.</strong><br />
+								By continuing to use the site, you consent to our use of cookies and our privacy policy.
+							</div>
 						</div>
 					</div>
 				</div>
-			</div>
-			<?php
-		}
+				<?php
+			}
 
-		?>
+			?>

+ 29 - 13
views/performance.php

@@ -7,8 +7,8 @@ $date_resolutions = [
 
 $date_ranges = [
 	"ytd" => "Year to Date",
-	"unbound" => "Unbound",
-	"custom" => "Custom",
+	//"unbound" => "Unbound",
+	//"custom" => "Custom",
 ];
 
 ?>
@@ -149,21 +149,37 @@ $date_ranges = [
 	}
 	?>
 
-
 	<div class="row">
-	<?php
-	foreach($charts as $chart) {
-		?>
-		<div class="col col-md-6 my-4">
+		<div class="col-md-4" style="position: relative;">
+			<h3>Chart List</h3>
+			<div class="list-group" style="position: sticky; top: 1rem;">
+			<?php
+			foreach($charts as $index => $chart) {
+				?>
+				<a class="list-group-item list-group-item-action" href="#chart-<?=$index?>">
+					<?=htmlspecialchars($chart->getTitle())?>
+				</a>
+				<?php
+			}
+			?>
+			</div>
+		</div>
+		<div class="col-md">
+		<?php
+		foreach($charts as $index => $chart) {
+			if($index > 0) {
+				?>
+				<br />
+				<?php
+			}
+			?>
+			<a id="chart-<?=$index?>"></a>
 			<canvas id="<?=$chart->getID()?>" data-chart="<?=htmlspecialchars($chart->getJSON())?>" width="400" height="400">
 			</canvas>
+			<?php
+		}
+		?>
 		</div>
-		<?php
-	}
-	?>
 	</div>
 
-	<pre><?=print_r($total_data, true)?></pre>
-	<pre><?=print_r($data, true)?></pre>
-
 </div>

Certains fichiers n'ont pas été affichés car il y a eu trop de fichiers modifiés dans ce diff