Revize 72a438f3
Přidáno uživatelem Jakub Vašta před téměř 5 roky(ů)
website/public/js/zcu-heatmap.js | ||
---|---|---|
52 | 52 |
} |
53 | 53 |
// eslint-disable-next-line no-unused-vars |
54 | 54 |
function initMap () { |
55 |
|
|
56 |
startX = localStorage.getItem('lat') || startX; |
|
57 |
startY = localStorage.getItem('lng') || startY; |
|
58 |
startZoom = localStorage.getItem('zoom') || startZoom; |
|
59 |
|
|
55 | 60 |
mymap = L.map('heatmap').setView([startX, startY], startZoom) |
56 | 61 |
|
57 | 62 |
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', { |
... | ... | |
125 | 130 |
} |
126 | 131 |
|
127 | 132 |
// eslint-disable-next-line no-unused-vars |
128 |
function setMapView (latitude = startX, longitude = startY, zoom = startZoom) { |
|
133 |
function setMapView (latitude, longitude, zoom) { |
|
134 |
localStorage.setItem('lat', latitude); |
|
135 |
localStorage.setItem('lng', longitude); |
|
136 |
localStorage.setItem('zoom', zoom); |
|
129 | 137 |
mymap.setView([latitude, longitude], zoom) |
130 | 138 |
} |
131 | 139 |
|
website/src/Controller/HeatmapController.php | ||
---|---|---|
68 | 68 |
public function dataSourcePoistions(IOpenDataManager $manager, $name = 'NONE') { |
69 | 69 |
return $this->json($manager->getDataSourcePositions($name)); |
70 | 70 |
} |
71 |
|
|
72 |
/** |
|
73 |
* @Route("heatmap/last", name="last") |
|
74 |
*/ |
|
75 |
public function lastAvailableCollections(IOpenDataManager $manager) { |
|
76 |
return $this->json($manager->getLastAvailableCollections()); |
|
77 |
} |
|
71 | 78 |
} |
website/src/IOpenDataManager.php | ||
---|---|---|
16 | 16 |
public function getMaxCollectionNumberAtDay($name, $date); |
17 | 17 |
|
18 | 18 |
public function getDataSourcePositions($name); |
19 |
|
|
20 |
public function getLastAvailableCollections(); |
|
19 | 21 |
} |
website/src/OpenDataManager.php | ||
---|---|---|
3 | 3 |
namespace App\OpenData; |
4 | 4 |
|
5 | 5 |
use MongoDB\Driver\Query; |
6 |
use MongoDB\Driver\Command; |
|
7 | 6 |
use MongoDB\Driver\Manager; |
8 | 7 |
|
9 | 8 |
class OpenDataManager implements IOpenDataManager { |
... | ... | |
54 | 53 |
} |
55 | 54 |
|
56 | 55 |
public function isCollectionAvailable($name, $date) { |
57 |
$command = new Command(['listCollections' => 1, 'filter' => ['name' => $name.$date]]); |
|
58 |
$result = $this->manager->executeCommand('open-data-db', $command)->toArray(); |
|
56 |
$result = $this->manager->executeQuery('open-data-db.'.$name, new Query(['date' => $date], [])); |
|
59 | 57 |
|
60 |
return !empty($result); |
|
58 |
return !empty($result->toArray());
|
|
61 | 59 |
} |
62 | 60 |
|
63 | 61 |
public function getDatesWithAvailableCollection() { |
64 |
$command = new Command(['listCollections' => 1]); |
|
65 |
$result = $this->manager->executeCommand('open-data-db', $command)->toArray(); |
|
62 |
$available = $this->getAvailableCollections(); |
|
63 |
$result = []; |
|
64 |
|
|
65 |
foreach ($available as $key => $value) { |
|
66 |
$dates = $this->manager->executeQuery('open-data-db.'.$value['key-name'], new Query([], ['projection' => ['date' => true, '_id' => false]])); |
|
67 |
$dates->setTypeMap(['root' => 'array']); |
|
68 |
$result = array_merge($result, array_map(function ($item) {return $item['date']; }, $dates->toArray())); |
|
69 |
} |
|
70 |
|
|
71 |
return array_values(array_unique($result)); |
|
72 |
} |
|
73 |
|
|
74 |
public function getLastAvailableCollections() { |
|
75 |
$available = $this->getAvailableCollections(); |
|
76 |
$result = []; |
|
77 |
|
|
78 |
foreach ($available as $key => $value) { |
|
79 |
$date = $this->manager->executeQuery('open-data-db.'.$value['key-name'], new Query([], ['sort' => ['date' => -1], 'limit' => 1, 'projection' => ['date' => true, '_id' => false]])); |
|
80 |
$date->setTypeMap(['root' => 'array']); |
|
66 | 81 |
|
67 |
$dates = []; |
|
68 |
foreach ($result as $value) { |
|
69 |
if (preg_match('/\\d{4}-\\d{2}-\\d{2}/', $value->name)) { |
|
70 |
array_push($dates, substr($value->name, -10)); |
|
82 |
$date_array = $date->toArray(); |
|
83 |
if (!empty($date_array)) { |
|
84 |
$result[$value['key-name']] = $date_array[0]['date']; |
|
71 | 85 |
} |
72 | 86 |
} |
73 | 87 |
|
74 |
return array_values(array_unique($dates));
|
|
88 |
return $result;
|
|
75 | 89 |
} |
76 | 90 |
|
77 | 91 |
public function getMaxCollectionNumberAtDay($name, $date) { |
website/templates/heatmap.html.twig | ||
---|---|---|
95 | 95 |
</a> |
96 | 96 |
<div class="locations collapse show" id="mapLocations"> |
97 | 97 |
<ul> |
98 |
<li onclick="setMapView()">Kampus ZČU</li> |
|
98 |
<li onclick="setMapView(49.7248, 13.3521, 17)">Kampus ZČU</li>
|
|
99 | 99 |
<li onclick="setMapView(49.7367263, 13.3709177, 18)">FPE – Pedagogická fakulta</li> |
100 | 100 |
<li onclick="setMapView(49.7474950, 13.3748308, 18)">FPR – Právnická fakulta</li> |
101 | 101 |
<li onclick="setMapView(49.7450169, 13.3702668, 18)">FZS – Fakulta zdravotnických studií</li> |
Také k dispozici: Unified diff
+ location persistence
+ last available collections
+ available collections code rework