Skip to content

Commit

Permalink
Merge pull request #7 from Pletacka-IoT/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
JakubAndrysek authored Nov 9, 2020
2 parents 45d34a8 + 5af92e7 commit fb5f838
Show file tree
Hide file tree
Showing 623 changed files with 12,343 additions and 87,601 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ doc
Pletacka-website
Backup
adminer.php
.idea
composer.lock
48 changes: 0 additions & 48 deletions .idea/Pletacka-website.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

52 changes: 0 additions & 52 deletions .idea/php.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion .idea/sqldialects.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -98,49 +98,58 @@ public function getClassName(string $sting): string



public function prepareNumberBox(array $allSenNumbers, string $workShift, DateTime $selectionFrom, DateTime $timeboxTo): NumbersPretty
public function prepareNumberBox(array $allSenNumbers, string $workShift, DateTime $selectionFrom, DateTime $to): NumbersPretty
{
$selectionTo = new DateTime();
$selectionTo->setTime($selectionTo->format("H")-1, 0);
// One hour between times is generated in selection
$timeboxFrom = new DateTime();
$timeboxFrom->setTime(intval($timeboxFrom->format("H")), 0);
$numberBox = new NumbersPretty();
$sensorCount = 0;
$timeboxTo = new DateTime();

$numberBox = new NumbersPretty();
$sensorCount = 0;
$addCounter = false;

foreach ($allSenNumbers as $sensorNumber)
{
$sensorNumberData = $this->databaseSelectionManager->getSelectionData($sensorNumber, DatabaseSelectionManager::HOUR,$workShift, $selectionFrom, $timeboxTo);
if($sensorNumberData->t_all)
{
$numberBox->state = true;
$addCounter = true;
$numberBox->finished += $sensorNumberData->c_FINISHED;
$numberBox->stopTime += $sensorNumberData->t_stop;
$numberBox->workTime += $sensorNumberData->t_work;
$numberBox->allTime += $sensorNumberData->t_all;
}

$sensorEvents = $this->thisSensorManager->getAllEvents($sensorNumber, $timeboxFrom, $timeboxTo);
if($sensorEvents)
{
$numberBox->state = true;
$addCounter = true;
$previousEvent = $this->thisSensorManager->getPreviousEvent($sensorNumber, $sensorEvents);

$sensorEvents = $this->thisSensorManager->getAllEvents($sensorNumber, $timeboxFrom, $timeboxTo);

if($sensorEvents)
{
$previousEvent = $this->thisSensorManager->getPreviousEvent($sensorNumber, $sensorEvents);
$timebox = new TimeBox($sensorEvents, $timeboxFrom, $timeboxTo);
$stopTime = $timebox->stopTime($previousEvent);
$numberBox->stopTime += $stopTime;
$allTime = $timebox->allTime($previousEvent);
$numberBox->allTime += $allTime;
$numberBox->workTime += $timebox->workTime($allTime, $stopTime);
$timebox = new TimeBox($sensorEvents, $timeboxFrom, $timeboxTo);
$stopTime = $timebox->stopTime($previousEvent);
$numberBox->stopTime += $stopTime;
$allTime = $timebox->allTime($previousEvent);
$numberBox->allTime += $allTime;
$numberBox->workTime += $timebox->workTime($allTime, $stopTime);

$numberBox->finished += $timebox->countEvents(TimeBox::FINISHED);
}
$numberBox->finished += $timebox->countEvents(TimeBox::FINISHED);
}
if($addCounter)
{
$sensorCount++;
$addCounter = false;
}
}

if($numberBox->state)
if($numberBox->state)
{
$numberBox->finishedCountToPairs();
$numberBox->finishedCountToPairs();
$numberBox->divideTimeVariablesByCount($sensorCount);

$numberBox->stopTimeStr = $this->humanTime($numberBox->stopTime);
Expand Down
107 changes: 68 additions & 39 deletions app/CoreModule/Forms/SensorsFormFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,61 +17,90 @@ final class SensorsFormFactory

const
FORM_MSG_REQUIRED = 'Tohle pole je povinné.',
FORM_MSG_RULE = 'Tohle pole má neplatný formát.';
FORM_MSG_RULE = 'Tohle pole má neplatný formát.';

protected $formFactory;
protected $formFactory;

public function __construct(FormFactory $formFactory)
{
$this->formFactory = $formFactory;
}
public function __construct(FormFactory $formFactory)
{
$this->formFactory = $formFactory;
}

/**

/**
* Create sensor Form from-to
*/
public function createCreateFromTo(callable $onSuccess): Form
{
$form = $this->formFactory->create();

$form->addText('from', 'Od:')
->setRequired(self::FORM_MSG_REQUIRED)
->addRule(Form::INTEGER, self::FORM_MSG_RULE);

$form->addText('to', 'Do:')
->setRequired(self::FORM_MSG_REQUIRED)
->addRule(Form::INTEGER, self::FORM_MSG_RULE);

$form->addText('description', 'Popis:');

$form->addSubmit('send', 'Přidej - akce může chvíli trvat');

$form->onSuccess[] = function (Form $form, \stdClass $values) use ($onSuccess) {

$onSuccess($form, $values);
};

return $form;
}

/**
* Edit sensor Form
*/
public function createEdit(callable $onSuccess): Form
{
$form = $this->formFactory->create();

$form->addHidden('oldNumber');

$form->addText('number', 'Číslo:')
->setRequired(self::FORM_MSG_REQUIRED)
->addRule(Form::INTEGER, self::FORM_MSG_RULE);

$form->addText('description', 'Popis:');
$form->addSubmit('send', 'Uprav');

$form->onSuccess[] = function (Form $form, \stdClass $values) use ($onSuccess) {

$onSuccess($form, $values);
};

return $form;
}


/**
* Create sensor Form
*/
*/
public function createCreate(callable $onSuccess): Form
{
$form = $this->formFactory->create();

$form->addText('number', 'Číslo:')
->setRequired(self::FORM_MSG_REQUIRED)
->addRule(Form::INTEGER, self::FORM_MSG_RULE);

$form->addText('description', 'Popis:');

$form->addSubmit('send', 'Přidej');

$form->onSuccess[] = function (Form $form, \stdClass $values) use ($onSuccess) {

$onSuccess($form, $values);
};

return $form;
}

/**
* Edit sensor Form
*/
public function createEdit(callable $onSuccess): Form
{
$form = $this->formFactory->create();
$form->addText('description', 'Popis:');

$form->addHidden('oldNumber');

$form->addText('number', 'Číslo:')
->setRequired(self::FORM_MSG_REQUIRED)
->addRule(Form::INTEGER, self::FORM_MSG_RULE);
$form->addSubmit('send', 'Přidej');

$form->addText('description', 'Popis:');
$form->addSubmit('send', 'Uprav');

$form->onSuccess[] = function (Form $form, \stdClass $values) use ($onSuccess) {

$onSuccess($form, $values);
};
return $form;
}

return $form;
}

/**
* Edit sensor Form - with old name parameter
Expand Down
36 changes: 36 additions & 0 deletions app/CoreModule/Presenters/SensorsSettingsPresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,42 @@ public function createComponentAddSensorForm(): Form
}


public function createComponentAddFromToForm(): Form
{
return $this->sensorsFormFactory->createCreateFromTo(function (Form $form, \stdClass $values) {
if($values->from<=$values->to)
{
$countOK = 0;
$countError = 0;
for($i = $values->from; $i<=$values->to; $i++)
{
$returnMessage = $this->sensorsManager->addNewSensor($i, $values->description." - ".$i);
if($returnMessage->state)
{
$countOK++;
}
else
{
$countError++;

}

}
$this->flashMessage("Vytvořeno - ".$countOK, 'success');
if($countError>0)
{
$this->flashMessage("Nevytvořeno - ".$countError, 'error');
}
$this->redirect('SensorsSettings:default');
}
else
{
$this->flashMessage("Neplatné zadání rozmezí", 'success');
}
});
}



////////////////////////////////////////////////
// Default page
Expand Down
1 change: 0 additions & 1 deletion app/CoreModule/Presenters/templates/@layout.latte
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

<link rel="stylesheet" href="{$basePath}/css/external/boostrap.css">
<link rel="stylesheet" href="{$basePath}/css/external/c3.css">
<link rel="stylesheet" href="{$basePath}/css/external/font.min.css">
<link rel="stylesheet" href="{$basePath}/css/external/daterangepicker.css" />
<link rel="stylesheet" href="{$basePath}/css/style.css">

Expand Down
Loading

0 comments on commit fb5f838

Please sign in to comment.