Skip to content
This repository has been archived by the owner on Jun 18, 2022. It is now read-only.

Commit

Permalink
added heat map to dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
cedricve committed Mar 2, 2016
1 parent 9db3562 commit c0e2041
Show file tree
Hide file tree
Showing 14 changed files with 295 additions and 80 deletions.
1 change: 1 addition & 0 deletions app/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@

Route::get('images/latest_sequence', 'Controllers\ImageController@getLatestSequence');
Route::get('images/days', 'Controllers\ImageController@getDays');
Route::get('images/regions', 'Controllers\ImageController@getRegions');
Route::get('images/perhour/{days?}', 'Controllers\ImageController@getImagesPerHour');
Route::get('images/perday/{days?}', 'Controllers\ImageController@getImagesPerDay');
Route::get('images/perweekday/{days?}', 'Controllers\ImageController@getAverageImagesPerWeekDay');
Expand Down
11 changes: 11 additions & 0 deletions app/controllers/ImageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,17 @@ public function getDays()

return Response::json($days);
}

/*************************************
* Get all regions
*/
public function getRegions()
{
$numberOfRegions = 250;
$regions = $this->imageHandler->getRegions($numberOfRegions);

return Response::json($regions);
}

/*************************************
* Get the latest image that was taken.
Expand Down
33 changes: 33 additions & 0 deletions app/repositories/imagehandler/ImageFileSystemHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,39 @@ public function getDays($numberOfDays)
return $days;
}
}

public function getRegions($numberOfRegions)
{
// -------------------------------------
// Cache images directory for x seconds

$key = $this->user->username . "_regions";

$regions = $this->cache->storeAndGet($key, function() use ($numberOfRegions)
{
$heap = $this->getImagesFromFilesystem();

$regions = [];

$i = 0;
while($i++ < $numberOfRegions && $heap->valid())
{
$image = new Image;
$image->setTimezone($this->date->timezone);
$image->parse($heap->current());

array_push($regions, [
"regionCoordinates" => $image->getRegion(),
"numberOfChanges" => $image->getChanges()
]);
$heap->next();
}

return $regions;
});

return $regions;
}

public function getImages()
{
Expand Down
5 changes: 5 additions & 0 deletions app/repositories/imagehandler/ImageHandlerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ public function getLastHourOfDay($day);
* Calculate the last x days
*/
public function getDays($numberOfDays);

/********************************
* Get all regions
*/
public function getRegions($numberOfRegions);

/*******************************
* Get all images
Expand Down
22 changes: 21 additions & 1 deletion app/views/dashboard.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
<li>
<a class="activity"><i href="#"class="fa fa-fw fa-refresh"></i> Last activity</a>
</li>
<li>
<a class="heat"><i href="#"class="fa fa-fw fa-fire"></i> Heatmap</a>
</li>
</ul>
</li>
</ul>
Expand All @@ -32,6 +35,10 @@
<li class="activity">
<canvas id="latest-activity-sequence"></canvas>
</li>
<li class="heat">
<img src="<?=App::make("Controllers\ImageController")->getLatestImage()?>" id="latest-image" style="display: none;"/>
<div class="heatmap" style="width: 100%;"></div>
</li>
</ul>
</div>
</div>
Expand Down Expand Up @@ -81,11 +88,12 @@
require(["app/controllers/dashboard_live",
"app/controllers/dashboard_sequencer",
"app/controllers/dashboard_heatmap",
"app/controllers/dashboard_pie",
"app/controllers/dashboard_graph",
"app/controllers/dashboard_radar"
],
function(Streamer, Sequencer, Pie, Graph, Radar)
function(Streamer, Sequencer, Heatmap, Pie, Graph, Radar)
{
Streamer.initialize(
{
Expand All @@ -96,6 +104,18 @@ function(Streamer, Sequencer, Pie, Graph, Radar)
callback: function(){}
});
Heatmap.initialize(
{
element: "heatmap",
url: _baseUrl + "/api/v1/images/regions",
callback: function(){}
});
$("ul.dropdown-menu li a.heat").click(function(event)
{
Heatmap.redraw();
});
Sequencer.initialize(
{
element: "canvas",
Expand Down
4 changes: 2 additions & 2 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM ubuntu:latest
FROM phusion/baseimage:latest

MAINTAINER "Cédric Verstraeten" <hello@cedric.ws>

Expand Down Expand Up @@ -52,7 +52,7 @@ ENV BRANCH develop

RUN git clone https://github.com/kerberos-io/web /var/www/web && \
cd /var/www/web && \
git checkout $BRANCH && \
git checkout develop && \
chown -Rf www-data.www-data /var/www/web && \
curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer && \
cd /var/www/web && \
Expand Down
3 changes: 2 additions & 1 deletion public/bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"fancybox": "*",
"csshake": "*",
"chartjs": "*",
"mjpegcanvas": "~0.4.0"
"mjpegcanvas": "~0.4.0",
"heatmap.js-amd": "*"
}
}
Loading

0 comments on commit c0e2041

Please sign in to comment.