Skip to content

Commit

Permalink
Merge pull request #6 from Pletacka-IoT/dev
Browse files Browse the repository at this point in the history
New Homepage (Numbers + Bubbles)
  • Loading branch information
JakubAndrysek authored Nov 7, 2020
2 parents 8b0bd62 + 86b975c commit 45d34a8
Show file tree
Hide file tree
Showing 29 changed files with 1,280 additions and 431 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace App\CoreModule\Controls\PletackaChartControl;
namespace App\CoreModule\Component\PletackaChartControl;

use Nette;
use App\Forms\FormFactory;
Expand Down Expand Up @@ -179,7 +179,7 @@ public function renderDay( string $color, string $nameType, string $state, strin
break;

case "WORK_TIME":
//$this->template->render(__DIR__ . '/PletackaChartControl.latte');
//$this->template->render(__DIR__ . '/StatusBubblesControl.latte');
echo "AHOJ";

break;
Expand Down Expand Up @@ -218,7 +218,7 @@ public function renderDay( string $color, string $nameType, string $state, strin
//
//
// // Render
// $this->template->render(__DIR__ . '/PletackaChartControl.latte');
// $this->template->render(__DIR__ . '/StatusBubblesControl.latte');
//
// }
// }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@

declare(strict_types=1);

namespace App\CoreModule\Controls\PletackaChartControl;
namespace App\CoreModule\Component\PletackaChartControl;

//use App\CoreModule\Controls\PletackaChartControl;
use App\CoreModule\Model\ThisSensorManager;
use App\CoreModule\Model\ThisChartManager;
use App\CoreModule\Model\WorkShiftManager;
Expand Down
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>
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";
}

}
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);
}
}
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>
Loading

0 comments on commit 45d34a8

Please sign in to comment.