-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from Pletacka-IoT/dev
New Homepage (Numbers + Bubbles)
- Loading branch information
Showing
29 changed files
with
1,280 additions
and
431 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
app/CoreModule/Component/StatusBubbblesControl/StatusBubblesControl.latte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
{block content} | ||
<h3 class="text-center text-white" style="margin-top: 15px">{$textName}</h3> | ||
<div class="table-responsive bubble-border center"> | ||
<table class="table table-borderless "> | ||
{foreach $bubblesAll as $bubblesRow} | ||
<tr> | ||
{foreach $bubblesRow as $bubbleNumber => $bubbleSensor} | ||
{if $bubbleNumber > 0} | ||
<td style="padding-left: 10px; padding-right: 5px"> | ||
<a class="ajax" href="{plink Sensors:default $bubbleNumber}"> | ||
<div class="bubble-number"> | ||
<h2>{$bubbleNumber}</h2> | ||
{* {$bubbleNumber}*} | ||
</div> | ||
</a> | ||
</td> | ||
|
||
<td style="padding-left: 5px"> | ||
<a class="ajax" href="{plink Sensors:default $bubbleNumber}"> | ||
<div class="bubble {$bubbleSensor->class} zoom"> | ||
{$bubbleSensor->value} | ||
</div> | ||
</a> | ||
</td> | ||
{else} | ||
<td></td> | ||
<td></td> | ||
{/if} | ||
{/foreach} | ||
</tr> | ||
{/foreach} | ||
</table> | ||
</div> |
210 changes: 210 additions & 0 deletions
210
app/CoreModule/Component/StatusBubbblesControl/StatusBubblesControl.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,210 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\CoreModule\Component\StatusBubblesControl; | ||
|
||
use App\CoreModule\Model\MultiSensorsManager; | ||
use App\TimeManagers\TimeBox; | ||
use App\Utils\BubblesPretty; | ||
use Nette; | ||
use App\Forms\FormFactory; | ||
use Nette\Application\UI\Form; | ||
use Nette\Database\Context; | ||
use Nette\Application\UI\Control; | ||
use App\CoreModule\Model\ThisSensorManager; | ||
use App\CoreModule\Model\ThisChartManager; | ||
use App\CoreModule\Model\WorkShiftManager; | ||
use Jakubandrysek\Chart\Serie\DateSerie; | ||
use Jakubandrysek\Chart\DateChart; | ||
use Jakubandrysek\Chart\Segment\DateSegment; | ||
use DateTimeImmutable; | ||
use Nette\Utils\DateTime; | ||
|
||
/** | ||
* @brief | ||
*/ | ||
class StatusBubblesControl extends Control{ | ||
|
||
|
||
// private $poolId; | ||
|
||
private $thisChartManager; | ||
private $thisSensorManager; | ||
private $workShiftManager; | ||
/** | ||
* @var MultiSensorsManager | ||
*/ | ||
private $multiSensorsManager; | ||
/** | ||
* @var Context | ||
*/ | ||
private $database; | ||
|
||
|
||
public function __construct(MultiSensorsManager $multiSensorsManager, | ||
ThisSensorManager $thisSensorManager, | ||
Context $database) | ||
{ | ||
$this->multiSensorsManager = $multiSensorsManager; | ||
$this->thisSensorManager = $thisSensorManager; | ||
$this->database = $database; | ||
} | ||
|
||
public function timeRemoveFirstNull($text) | ||
{ | ||
if($text[0] == 0) | ||
{ | ||
return $text[1]; | ||
} | ||
else | ||
{ | ||
return $text; | ||
} | ||
} | ||
|
||
public function humanTime(int $timeSeconds) | ||
{ | ||
if($timeSeconds>3600) | ||
{ | ||
return $this->timeRemoveFirstNull(gmdate("h", $timeSeconds))." hod"; | ||
} | ||
else | ||
{ | ||
return $this->timeRemoveFirstNull(gmdate("i", $timeSeconds))." mim"; | ||
} | ||
} | ||
|
||
public function getCountFinishedTodayWS(int $number, DateTime $from, string $state) | ||
{ | ||
return $this->database->table("A".$number)->where("time>? AND state = ?", $from, $state)->count(); | ||
} | ||
|
||
public function getClassName(string $sting): string | ||
{ | ||
return "bubble-".strtolower($sting); | ||
} | ||
|
||
|
||
|
||
public function prepareBubbleBox(int $number, DateTime $from): BubblesPretty | ||
{ | ||
if($lastEvent = $this->thisSensorManager->getLastEvent($number)) | ||
{ | ||
$lastEventState = $lastEvent->state; | ||
|
||
if($lastEvent->time>$from) | ||
{ | ||
if($lastEventState == TimeBox::STOP) | ||
{ | ||
$now = new DateTime(); | ||
return new BubblesPretty($lastEventState, | ||
$this->humanTime($now->getTimestamp() - $lastEvent->time->getTimestamp()), | ||
$this->getClassName($lastEventState)); | ||
} | ||
else | ||
{ | ||
$finishedPairs = floor($this->getCountFinishedTodayWS($number, $from, "FINISHED")/2); | ||
|
||
if($finishedPairs>0) | ||
{ | ||
if($lastEventState == TimeBox::OFF) | ||
{ | ||
return new BubblesPretty($lastEventState, $finishedPairs." p", $this->getClassName($lastEventState)); | ||
} | ||
else | ||
{ | ||
return new BubblesPretty($lastEventState, $finishedPairs." p", $this->getClassName("finished")); | ||
} | ||
} | ||
else | ||
{ | ||
return new BubblesPretty("EMPTY"); | ||
} | ||
} | ||
} | ||
else | ||
{ | ||
return new BubblesPretty("EMPTY"); | ||
} | ||
|
||
} | ||
else | ||
{ | ||
return new BubblesPretty("EMPTY"); | ||
} | ||
|
||
} | ||
|
||
|
||
|
||
public function renderDay() | ||
{ | ||
|
||
} | ||
|
||
public function render(array $roomAll, string $textName) | ||
{ | ||
$chartData = array(); | ||
$counter = 0; | ||
|
||
if(date("H")<14) | ||
{ | ||
$from = new DateTime(date("Y-m-d 0:00:00")); | ||
$to = new DateTime(date("Y-m-d 14:00:00")); | ||
} | ||
else | ||
{ | ||
$from = new DateTime(date("Y-m-d 14:00:00")); | ||
$to = new DateTime(date("Y-m-d 23:59:59")); | ||
} | ||
$now = new DateTime(); | ||
|
||
// $from="2020-04-24 08:00:00"; //For testing | ||
// $to="2020-04-24 23:00:00"; | ||
// $now = new DateTime("2020-04-24 22:30:00"); | ||
|
||
$allSensorNumbers = $this->multiSensorsManager->getAllSensorsName(); | ||
$bubblesAll = array(); | ||
$row = 0; | ||
$empty = -1; | ||
|
||
// dump(new DateTime("Y-m-d 04:00:00")); | ||
|
||
|
||
foreach($roomAll as $roomRow) | ||
{ | ||
$bubblesRow = array(); | ||
foreach($roomRow as $roomSensorNumber) | ||
{ | ||
|
||
if(array_key_exists($roomSensorNumber, $allSensorNumbers)) | ||
{ | ||
$bubbleBox = $this->prepareBubbleBox(intval($roomSensorNumber), $from); | ||
$bubbleSensor = array($roomSensorNumber => $bubbleBox); | ||
} | ||
else | ||
{ | ||
$bubbleSensor = array($empty=>null); | ||
$empty--; | ||
} | ||
$bubblesRow += $bubbleSensor; | ||
} | ||
$bubblesAll[$row] = $bubblesRow; | ||
$row++; | ||
} | ||
$this->template->bubblesAll = $bubblesAll; | ||
$this->template->textName = $textName; | ||
|
||
// $allSensors = $this->multiSensorsManager->getAllSensorsEvents($roomSensorsArray, $from, $to, false); | ||
// dump($url = $this->link("core:ahoj")); | ||
|
||
$this->template->render(__DIR__ . '/StatusBubblesControl.latte'); | ||
} | ||
|
||
public function handleClick() | ||
{ | ||
echo "OK"; | ||
} | ||
|
||
} |
44 changes: 44 additions & 0 deletions
44
app/CoreModule/Component/StatusBubbblesControl/StatusBubblesControlFactory.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\CoreModule\Component\StatusBubblesControl; | ||
|
||
use App\CoreModule\Model\MultiSensorsManager; | ||
use App\CoreModule\Model\ThisSensorManager; | ||
use App\CoreModule\Model\ThisChartManager; | ||
use App\CoreModule\Model\WorkShiftManager; | ||
use Nette\Database\Context; | ||
|
||
|
||
class StatusBubblesControlFactory | ||
{ | ||
|
||
/** | ||
* @var MultiSensorsManager | ||
*/ | ||
private $multiSensorsManager; | ||
/** | ||
* @var ThisSensorManager | ||
*/ | ||
private $thisSensorManager; | ||
/** | ||
* @var Context | ||
*/ | ||
private $database; | ||
|
||
|
||
public function __construct(MultiSensorsManager $multiSensorsManager, | ||
ThisSensorManager $thisSensorManager, | ||
Context $database) | ||
{ | ||
$this->multiSensorsManager = $multiSensorsManager; | ||
$this->thisSensorManager = $thisSensorManager; | ||
$this->database = $database; | ||
} | ||
|
||
public function create() | ||
{ | ||
return new StatusBubblesControl($this->multiSensorsManager, $this->thisSensorManager, $this->database); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
app/CoreModule/Component/StatusNumbersControl/StatusNumbersControl.latte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{block content} | ||
|
||
<div class="row"> | ||
<div class="col-sm-4 "> | ||
<h5>Upleteno</h5> | ||
<h2>{$numberBox->finished} p</h2> | ||
</div> | ||
<div class="col-sm-4 "> | ||
<h5>Úspěšnost</h5> | ||
<h2>{$numberBox->rating}%</h2> | ||
</div> | ||
<div class="col-sm-4 "> | ||
<h5>Průměrná doba stání</h5> | ||
<h2>{$numberBox->stopTimeStr}</h2> | ||
</div> | ||
</div> |
Oops, something went wrong.