Commit 4ca0b794 authored by Jacob Priddy's avatar Jacob Priddy 👌

make webserver depend on api

add door count to admin dasboard
parent 983daa39
......@@ -43,6 +43,7 @@ services:
- ./simple-saml-idp/metadata:/var/simplesamlphp-idp/metadata
depends_on:
- dbadmin
- api
logging:
options:
max-size: "10m"
......
......@@ -30,12 +30,12 @@
<div class="card-body">
<div class="row no-gutters align-items-center">
<div class="col mr-2">
<div class="text-xs font-weight-bold text-primary text-uppercase mb-1">Earnings (Monthly)
<div class="text-xs font-weight-bold text-primary text-uppercase mb-1">Doors
</div>
<div class="h5 mb-0 font-weight-bold text-gray-800">$40,000</div>
<div class="h5 mb-0 font-weight-bold text-gray-800">{{ $doorCount }}</div>
</div>
<div class="col-auto">
<i class="fas fa-calendar fa-2x text-gray-300"></i>
<i class="fas fa-microchip fa-2x text-gray-300"></i>
</div>
</div>
</div>
......
......@@ -167,4 +167,12 @@ QUERY;
), $usage->usage_count];
}, $doorUsages);
}
/**
* @inheritDoc
*/
public function countDoors(): int
{
return \App\Door::query()->count();
}
}
......@@ -21,6 +21,8 @@ class InMemoryStatisticsRepository implements StatisticsRepository
*/
protected array $mostUsedDoors = [];
protected int $doorCount;
public function addPercentage(DoorFailureRate $failureRate): void
{
$this->failureRates[] = $failureRate;
......@@ -58,4 +60,17 @@ class InMemoryStatisticsRepository implements StatisticsRepository
{
return $this->mostUsedDoors;
}
/**
* @inheritDoc
*/
public function countDoors(): int
{
return $this->doorCount;
}
public function setDoorCount(int $doorCount): void
{
$this->doorCount = $doorCount;
}
}
......@@ -15,5 +15,6 @@ class LocalStatisticsRepository extends InMemoryStatisticsRepository
$this->setActiveUsers(160);
$this->addMostUsedDoor(1743, LocalDoorsRepository::getAmazonDoor());
$this->addMostUsedDoor(635, LocalDoorsRepository::getTheBatCave());
$this->setDoorCount(14);
}
}
......@@ -16,6 +16,11 @@ interface StatisticsRepository
*/
public function countActiveUsers(Carbon $start, Carbon $end): int;
/**
* @return int
*/
public function countDoors(): int;
/**
* @param \Carbon\Carbon $start
* @param \Carbon\Carbon $end
......
......@@ -16,6 +16,8 @@ class ResponseModel
protected int $activeUsers = 0;
protected int $doorCount;
public function addFailureRate(DoorFailureRate $failureRate): void
{
$this->failureRates[] = $failureRate;
......@@ -31,6 +33,11 @@ class ResponseModel
$this->activeUsers = $active;
}
public function setDoorCount(int $count): void
{
$this->doorCount = $count;
}
public function getActiveUsers(): int
{
return $this->activeUsers;
......@@ -45,4 +52,9 @@ class ResponseModel
{
return $this->mostUsedDoors;
}
public function getDoorCount(): int
{
return $this->doorCount;
}
}
......@@ -57,10 +57,14 @@ class Statistics implements StatisticsUseCase
$usages = $this->statistics->mostUsedDoors($start, $date, self::STATISTIC_LIMIT);
$doors = $this->statistics->countDoors();
$response = new ResponseModel();
$response->setActiveUsers($this->statistics->countActiveUsers($start, $date));
$response->setDoorCount($doors);
foreach ($usages as $usage) {
$response->addMostUsedDoor($usage[1], $usage[0]);
}
......
......@@ -15,6 +15,8 @@ class WebPresenter extends BasePresenter implements Presenter
{
$this->viewModel['activeUsers'] = $responseModel->getActiveUsers();
$this->viewModel['doorCount'] = $responseModel->getDoorCount();
try {
$this->viewModel['failures']['labels'] = json_encode(array_map(static function (DoorFailureRate $rate) {
return $rate->getDoor()->getLocation();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment