Skip to content

Commit

Permalink
Finnished ThisSensorManager
Browse files Browse the repository at this point in the history
  • Loading branch information
JakubAndrysek committed Apr 30, 2020
1 parent e08fcb7 commit 081a801
Show file tree
Hide file tree
Showing 6 changed files with 153 additions and 33 deletions.
26 changes: 23 additions & 3 deletions app/CoreModule/Model/ThisSensorManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,10 +192,10 @@ public function getAllTime($sName, $ids)
$first = $this->database->table($sName)->where("id=?", array_key_first($ids[0]) )->fetch()->time->getTimestamp();
$last = $this->database->table($sName)->where("id=?", array_key_last($ids)+1)->fetch()->time->getTimestamp();
$res = $last-$first;
return new DateInterval("PT".$res."S");

return array(new DateInterval("PT".$res."S"), $res);
}


public function testPretty()
{
// dump($x = Pretty::return(true, array(1,2,3), "IT is ok", "Je to ok"));
Expand Down Expand Up @@ -259,8 +259,28 @@ public function getStopTime($sName, $ids)
// $first = $this->database->table($sName)->where("id=?", $ids[0])->fetch()->time->getTimestamp();
// $last = $this->database->table($sName)->where("id=?", end($ids))->fetch()->time->getTimestamp();
// $res = $last-$first;
return new DateInterval("PT".$time."S");
return array(new DateInterval("PT".$time."S"), $time);

}

public function getAproxStopTime($stopTimestamp, $stopCount)
{
$time = ceil($stopTimestamp/$stopCount);
return array(new DateInterval("PT".$time."S"), $time);
}

public function getWorkTime($allTimestamp, $stopTimestamp)
{
$time = $allTimestamp-$stopTimestamp;
return array(new DateInterval("PT".$time."S"), $time);
}



public function getAproxWorkTime($workTimestamp, $workCount)
{
$time = ceil($workTimestamp/$workCount);
return array(new DateInterval("PT".$time."S"), $time);
}

public function getWorkTimeOld($sName, $ids): DateInterval
Expand Down
69 changes: 45 additions & 24 deletions app/CoreModule/Presenters/TestPresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,19 +79,19 @@ public function runSafely($array)

public function renderDefault()
{
// //$this->thisSensorManager->resetDB("Tester");
// //$this->thisSensorManager->resetDB("Debug");

// $ids = $this->thisSensorManager->getAllIdState("Tester", '2020-04-24 22:00:00', '2020-04-24 22:30:00', $this->thisSensorManager::OLDWORK);
// $runTime = $this->thisSensorManager->getWorkTime("Tester",$ids);
// $ids = $this->thisSensorManager->getAllIdState("Debug", '2020-04-24 22:00:00', '2020-04-24 22:30:00', $this->thisSensorManager::OLDWORK);
// $runTime = $this->thisSensorManager->getWorkTime("Debug",$ids);


// $this->template->allEventsCount = $this->thisSensorManager->countAllEvents("Tester");
// $this->template->allEventsCount0 = $this->thisSensorManager->countAllEventsState("Tester", $this->thisSensorManager::OLDSTOP);
// $this->template->allEventsCount1 = $this->thisSensorManager->countAllEventsState("Tester", $this->thisSensorManager::OLDWORK);
// $this->template->allEvents = $this->thisSensorManager->getAllEvents("Tester");
// $this->template->allEventsCount = $this->thisSensorManager->countAllEvents("Debug");
// $this->template->allEventsCount0 = $this->thisSensorManager->countAllEventsState("Debug", $this->thisSensorManager::OLDSTOP);
// $this->template->allEventsCount1 = $this->thisSensorManager->countAllEventsState("Debug", $this->thisSensorManager::OLDWORK);
// $this->template->allEvents = $this->thisSensorManager->getAllEvents("Debug");

// $this->template->firstEvent = $this->thisSensorManager->getFirstIdState("Tester", '2020-04-24 22:00:00', $this->thisSensorManager::OLDWORK);
// $this->template->lastEvent = $this->thisSensorManager->getLastIdState("Tester", '2020-04-24 22:20:00', $this->thisSensorManager::OLDWORK);
// $this->template->firstEvent = $this->thisSensorManager->getFirstIdState("Debug", '2020-04-24 22:00:00', $this->thisSensorManager::OLDWORK);
// $this->template->lastEvent = $this->thisSensorManager->getLastIdState("Debug", '2020-04-24 22:20:00', $this->thisSensorManager::OLDWORK);
// $this->thisSensorManager::MINUTE;


Expand All @@ -101,7 +101,7 @@ public function renderDefault()
// $this->template->runTime = $runTime;
// $this->template->runTimeAdd = DateTime::from("2000-01-01 00:00:00")->add($runTime);

// $allTime = $this->thisSensorManager->getAllTime("Tester",$ids);
// $allTime = $this->thisSensorManager->getAllTime("Debug",$ids);
// $this->template->allTime = $allTime;
// $this->template->allTimeAdd = DateTime::from("2000-01-01 00:00:00")->add($allTime);

Expand All @@ -114,36 +114,57 @@ public function renderDefault()



// echo "XXX:".$this->thisSensorManager->getAllEventsOlder("Tester", '2020-04-17 15:56:30')."<br>";
// echo "XXX:".$this->thisSensorManager->getAllEventsOlder("Debug", '2020-04-17 15:56:30')."<br>";
// echo "Time<br>";
// foreach($this->thisSensorManager->getAllEventsYounger("Tester", '2020-04-17 15:52:30') as $event)
// foreach($this->thisSensorManager->getAllEventsYounger("Debug", '2020-04-17 15:52:30') as $event)
// {
// echo $event->id."->". $event->state."->".$event->time."<br>";
// }

// echo "All<br>";
// foreach($this->thisSensorManager->getAllEvents("Tester") as $event)
// foreach($this->thisSensorManager->getAllEvents("Debug") as $event)
// {
// echo $event->id."->". $event->state."->".$event->time."<br>";
// }
}

public function actionDebug()
{
$stopIds = $this->thisSensorManager->getAllIdState("Tester", '2020-04-24 22:00:00', '2020-04-24 22:30:00', $this->thisSensorManager::STOP);
$stopTime = $this->thisSensorManager->getStopTime("Tester",$stopIds);
$this->template->stopTime = $stopTime;
$this->template->allEventsCount = $this->thisSensorManager->countAllEvents("Debug");
$this->template->allEventsCountF = $allCountF = $this->thisSensorManager->countAllEventsState("Debug", $this->thisSensorManager::FINISHED);
$this->template->allEventsCountS = $allCountS = $this->thisSensorManager->countAllEventsState("Debug", $this->thisSensorManager::STOP);
$this->template->allEventsCountR = $allCountR = $this->thisSensorManager->countAllEventsState("Debug", $this->thisSensorManager::REWORK);
$this->template->allEvents = $this->thisSensorManager->getAllEvents("Debug");

$ids = $this->thisSensorManager->getAllId("Debug", '2020-04-24 22:02:00', '2020-04-24 22:30:00');
dump($ids);
$ids = $this->thisSensorManager->getAllId("Debug", '2020-04-24 22:00:00', '2020-04-24 22:30:00');
$start = Datetime::from("2000-01-01 00:00:00");

$allTime = $this->thisSensorManager->getAllTime("Debug", $ids);
$this->template->allTime = $allTime; //Date interval

$stopTime = $this->thisSensorManager->getStopTime("Debug", $ids);
$this->template->stopTime = $stopTime; //Date interval

$workTime = $this->thisSensorManager->getWorkTime($allTime[1], $stopTime[1]);
$this->template->workTime = $workTime; //Date interval

$stopAproxTime = $this->thisSensorManager->getAproxStopTime($stopTime[1], $allCountS);
$this->template->stopAproxTime = $stopAproxTime; //Date interval

$workAproxTime = $this->thisSensorManager->getAproxWorkTime($workTime[1], $allCountF);
$this->template->workAproxTime = $workAproxTime; //Date interval

// echo"Work";
// dump($workTime);

// dump($ids);
// $this->error("TEST ERROR", IResponse::S404_NOT_FOUND);
// dump($this->runSafely($this->thisSensorManager->addEvent("asd", 1)));
// dump($this->thisSensorManager->testPretty());
$start = Datetime::from("2000-01-01 00:00:00");
dump($all = $this->thisSensorManager->getAllTime("Debug", $ids));
dump($stop = $this->thisSensorManager->getStopTime("Debug", $ids));
$start->add($all);
dump($start);

// dump($stop = $this->thisSensorManager->getStopTime("Debug", $ids));
// $start->add($allTime[0]);
// dump($start);
}

public function renderRun(): void
Expand Down Expand Up @@ -313,7 +334,7 @@ public function renderRun(): void

public function actionReset()
{
$this->thisSensorManager->resetDB("Tester");
$this->thisSensorManager->resetDB("Debug");
}

}
Expand Down
2 changes: 1 addition & 1 deletion app/CoreModule/Presenters/templates/@layout.latte
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
<div class="page">

{snippet header}
<nav class="navbar navbar-expand-md bg-dark navbar-dark "><!--fixed-top-->
<nav class="navbar navbar-expand-md bg-dark navbar-dark fixed-top"><!--fixed-top-->

<!-- Brand/logo -->
<a class="navbar-brand ajax" href="{$basePath}">
Expand Down
83 changes: 82 additions & 1 deletion app/CoreModule/Presenters/templates/test/debug.latte
Original file line number Diff line number Diff line change
@@ -1,3 +1,84 @@
{block title}Debug{/block}

{block content}
{block content}

<div class="container text-center " style="margin-top:80px">
<h1>Debug - <small>{$time}</small></h1>
</div>
<div class="container">
<h2>All events</h2>
{foreach $allEvents as $event}
{if $iterator->first}
<table class="table table-striped">
<thead>
<tr>
<th>ID</th>
<th>State</th>
<th>Time</th>
</tr>
</thead>
<tbody>
{/if}
<tr id="row-{$iterator->counter}">
<td>{$event->id}</td>
{if $event->state == "FINISHED"}
<td class="text-success">
{$event->state}
</td>
{elseif $event->state == "STOP"}
<td class="text-danger">
{$event->state}
</td>
{elseif $event->state == "REWORK"}
<td class="text-info">
{$event->state}
</td>
{else}
<td class="">
{$event->state}
</td>
{/if}



<td>{$event->time}</td>
</tr>
{if $iterator->last}
</tbody>
</table>
{/if}
{/foreach}
<h2>Counts</h2>
<div class="move-right">
<h4>All events count: {$allEventsCount}</h4>
<h4>All events state count (FINSHED): {$allEventsCountF}</h4>
<h4>All events state count (STOP): {$allEventsCountS}</h4>
<h4>All events state count (REWORK): {$allEventsCountR}</h4>
</div>

<h2>Times</h2>
<div class="move-right">
<h4>All time: {$allTime[0]|date:'%s'}s -> {$allTime[1]|date:'i:s'} Minute:Second</h4>
<h4>Stop time: {$stopTime[0]|date:'%s'}s -> {$stopTime[1]|date:'i:s'} Minute:Second</h4>
<h4>Work time: {$workTime[0]|date:'%s'}s -> {$workTime[1]|date:'i:s'} Minute:Second</h4>
</div>

<h2>Aprox</h2>
<div class="move-right">
<h4>Stop aprox time: {$stopAproxTime[0]|date:'%s'}s -> {$stopAproxTime[1]|date:'i:s'} Minute:Second</h4>
<h4>Work aprox time: {$workAproxTime[0]|date:'%s'}s -> {$workAproxTime[1]|date:'i:s'} Minute:Second</h4>
</div>
{* {dump $allEvents} *}
{* <h4>First event state (1): {$firstEvent}</h4>
<h4>Last event state (1): {$lastEvent}</h4> *}
<h4></h4>
<h4></h4>
</div>

<style>
.move-right
{
padding-left: 2em;
}
</style>
3 changes: 0 additions & 3 deletions app/CoreModule/Presenters/templates/test/default.latte
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,3 @@
<h3></h3>
</div>

<script>
{* javascript:location.reload(true) *}
</script>
3 changes: 2 additions & 1 deletion www/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,5 @@ div.my-circle {

.my-form{
padding: 2px;
}
}

0 comments on commit 081a801

Please sign in to comment.