Revize 03ccdd65
Přidáno uživatelem Jakub Vašta před téměř 5 roky(ů)
website/public/js/zcu-heatmap.js | ||
---|---|---|
152 | 152 |
data = [] |
153 | 153 |
|
154 | 154 |
name = $('#type').children("option:selected").text(); |
155 |
var parts = $('#date').val().split('-'); |
|
156 |
date = parts[2] + parts[1] + parts[0]; |
|
155 |
date = $('#date').val() |
|
157 | 156 |
currentTime = parseInt($('#time').children("option:selected").val()); |
158 | 157 |
setTimeline(); |
159 | 158 |
|
... | ... | |
211 | 210 |
|
212 | 211 |
function checkDataSetsAvailability(route) { |
213 | 212 |
|
214 |
var parts = $('#date').val().split('-'); |
|
215 |
|
|
216 | 213 |
$.ajax({ |
217 | 214 |
type: "POST", |
218 | 215 |
// Todo it might be good idea to change db collections format |
219 |
url: route + '/' + parts[2] + parts[1] + parts[0],
|
|
216 |
url: route + '/' + $('#date').val(),
|
|
220 | 217 |
success: function(result) { |
221 | 218 |
updateAvailableDataSets(result); |
222 | 219 |
} |
website/src/Controller/HeatmapController.php | ||
---|---|---|
19 | 19 |
$form = $this->createForm(DataSetType::class, $dataSet); |
20 | 20 |
$form->handleRequest($request); |
21 | 21 |
|
22 |
if ($form->isSubmitted()) { |
|
22 |
$isSubmitted = $form->isSubmitted(); |
|
23 |
if ($isSubmitted) { |
|
23 | 24 |
$dataSet = $form->getData(); |
24 |
$name = $manager->getXthAvailableCollectionByDay($dataSet->getType(), $dataSet->getDate()); |
|
25 |
if (false == $manager->isCollectionAvailable($name, $dataSet->getDate())) { |
|
26 |
$form = $this->createForm(DataSetType::class, new DataSet()); |
|
25 |
if (false == $manager->isCollectionAvailable($dataSet->getType(), $dataSet->getDate())) { |
|
26 |
$dataSet = new DataSet(); |
|
27 | 27 |
} |
28 |
$form = $this->createForm(DataSetType::class, $dataSet); |
|
28 | 29 |
} |
29 | 30 |
|
30 | 31 |
return $this->render( |
31 | 32 |
'heatmap.html.twig', |
32 | 33 |
[ |
33 | 34 |
'form' => $form->createView(), |
34 |
'submitted' => $form->isSubmitted(),
|
|
35 |
'submitted' => $isSubmitted,
|
|
35 | 36 |
'data_to_display' => $dataSet, |
36 | 37 |
] |
37 | 38 |
); |
... | ... | |
40 | 41 |
/** |
41 | 42 |
* @Route("heatmap/opendata/{name}/{date}/{time}", name="opendata") |
42 | 43 |
*/ |
43 |
public function opendata(IOpenDataManager $manager, $name = 'NONE', $date = '01012020', $time = '1') {
|
|
44 |
public function opendata(IOpenDataManager $manager, $name = 'NONE', $date = '2020-01-01', $time = '1') {
|
|
44 | 45 |
return $this->json([ |
45 | 46 |
'items' => $manager->getCollectionDataByName($name, $date, $time), |
46 | 47 |
'max' => $manager->getMaxCollectionNumberAtDay($name, $date), |
website/src/Entity/DataSet.php | ||
---|---|---|
17 | 17 |
} |
18 | 18 |
|
19 | 19 |
public function setDate($date) { |
20 |
$this->date = date('dmY', strtotime($date));
|
|
20 |
$this->date = date('Y-m-d', strtotime($date));
|
|
21 | 21 |
} |
22 | 22 |
|
23 | 23 |
public function getDate() { |
website/src/Form/DataSetType.php | ||
---|---|---|
22 | 22 |
} |
23 | 23 |
|
24 | 24 |
public function buildForm(FormBuilderInterface $builder, array $options) { |
25 |
|
|
26 |
$selectTypeData = $options['data']->getDate() == null ? |
|
27 |
Utils::prepareDatasetsNames($this->manager->getAvailableCollections()) : |
|
28 |
$this->manager->getAvailableCollectionsByDay($options['data']->getDate()); |
|
29 |
|
|
25 | 30 |
$builder |
26 | 31 |
->add('date', TextType::class) |
27 | 32 |
->add('time', ChoiceType::class, [ |
... | ... | |
53 | 58 |
], |
54 | 59 |
]) |
55 | 60 |
->add('type', ChoiceType::class, [ |
56 |
'choices' => Utils::prepareDatasetsNames($this->manager->getAvailableCollections()),
|
|
61 |
'choices' => $selectTypeData,
|
|
57 | 62 |
]) |
58 | 63 |
->add('submit', SubmitType::class); |
59 | 64 |
} |
website/src/IOpenDataManager.php | ||
---|---|---|
9 | 9 |
|
10 | 10 |
public function getAvailableCollectionsByDay($date); |
11 | 11 |
|
12 |
public function getXthAvailableCollectionByDay($index, $date); |
|
13 |
|
|
14 | 12 |
public function isCollectionAvailable($name, $date); |
15 | 13 |
|
16 | 14 |
public function getMaxCollectionNumberAtDay($name, $date); |
website/src/OpenDataManager.php | ||
---|---|---|
17 | 17 |
|
18 | 18 |
public function getCollectionDataByName($name, $date, $hour) { |
19 | 19 |
$valh = $hour < 10 ? '0'.$hour : $hour; |
20 |
$openData = $this->manager->executeQuery('open-data-db.'.$name.$date, new Query(['date' => $date.$valh], [])); |
|
20 |
$openData = $this->manager->executeQuery('open-data-db.'.$name.$date, new Query(['date' => $date.'-'.$valh], []));
|
|
21 | 21 |
|
22 | 22 |
$openData->setTypeMap([ |
23 | 23 |
'array' => 'array', |
... | ... | |
46 | 46 |
$index = 0; |
47 | 47 |
foreach ($available as $key => $value) { |
48 | 48 |
if ($this->isCollectionAvailable($value['name'], $date) && false == array_key_exists($value['name'], $availableInDate)) { |
49 |
$availableInDate[$value['name']] = $index++;
|
|
49 |
$availableInDate[$value['name']] = $value['name'];
|
|
50 | 50 |
} |
51 | 51 |
} |
52 | 52 |
|
53 | 53 |
return $availableInDate; |
54 | 54 |
} |
55 | 55 |
|
56 |
public function getXthAvailableCollectionByDay($index, $date) { |
|
57 |
$availableInDate = []; |
|
58 |
$available = $this->getAvailableCollections(); |
|
59 |
$currentIndex = 0; |
|
60 |
|
|
61 |
foreach ($available as $key => $value) { |
|
62 |
if ($this->isCollectionAvailable($value['name'], $date) && false == array_key_exists($value['name'], $availableInDate)) { |
|
63 |
if ($currentIndex == $index) { |
|
64 |
return $value['name']; |
|
65 |
} else { |
|
66 |
++$currentIndex; |
|
67 |
} |
|
68 |
} |
|
69 |
} |
|
70 |
|
|
71 |
return ''; |
|
72 |
} |
|
73 |
|
|
74 | 56 |
public function isCollectionAvailable($name, $date) { |
75 | 57 |
$command = new Command(['listCollections' => 1, 'filter' => ['name' => $name.$date]]); |
76 | 58 |
$result = $this->manager->executeCommand('open-data-db', $command)->toArray(); |
website/src/Utils/Utils.php | ||
---|---|---|
9 | 9 |
$index = 0; |
10 | 10 |
foreach ($datasets as $key => $value) { |
11 | 11 |
if (false == array_key_exists($value['name'], $names)) { |
12 |
$names[$value['name']] = $index++;
|
|
12 |
$names[$value['name']] = $value['name'];
|
|
13 | 13 |
} |
14 | 14 |
} |
15 | 15 |
|
website/templates/index.html.twig | ||
---|---|---|
45 | 45 |
</li> |
46 | 46 |
<li class="nav-item button"> |
47 | 47 |
<h2> |
48 |
<a href="/heatmap/?data_set[date]=2019-04-25&data_set[time]=9&data_set[type]=1" class="nav-link">Zobrazit heatmapu</a>
|
|
48 |
<a href="/heatmap/?data_set[date]=2019-04-25&data_set[time]=9&data_set[type]=JIS" class="nav-link">Zobrazit heatmapu</a>
|
|
49 | 49 |
</h2> |
50 | 50 |
</li> |
51 | 51 |
</ul> |
... | ... | |
62 | 62 |
<h3>Život na ZČU během dne</h3> |
63 | 63 |
<hr> |
64 | 64 |
<p>Zobrazte si heatmapu života univerzity hodinu po hodině během jednoho dne. Od ranního probouzení, kdy studenti a zaměstnanci přicházejí do laboratoří, přes polední špičku v menze až do samotného večera, kdy končí poslední z přednášek a cvičení.</p> |
65 |
<a href="/heatmap/?data_set[date]=2019-04-25&data_set[time]=9&data_set[type]=1" class="btn btn-primary" role="button">Vyzkoušet heatmapu</a>
|
|
65 |
<a href="/heatmap/?data_set[date]=2019-04-25&data_set[time]=9&data_set[type]=JIS" class="btn btn-primary" role="button">Vyzkoušet heatmapu</a>
|
|
66 | 66 |
|
67 | 67 |
<div class="map-point point-1"> |
68 | 68 |
<div class="desc"> |
... | ... | |
90 | 90 |
<h3>Hledání anomálií</h3> |
91 | 91 |
<hr> |
92 | 92 |
<p>Heatmapa vám také dává možnost prozkoumávat data vlastním způsobem – stačí jen zvolit konkrétní datum a čas, pro které chcete data zobrazit. Můžete tak objevit i různé anomálie, například narazit na noční návštěvníky kampusu nebo odhalit návraty na studentské koleje v brzkých ranních hodinách…</p> |
93 |
<a href="/heatmap/?data_set[date]=2019-04-25&data_set[time]=9&data_set[type]=1" class="btn btn-primary" role="button">Vyzkoušet heatmapu</a>
|
|
93 |
<a href="/heatmap/?data_set[date]=2019-04-25&data_set[time]=9&data_set[type]=JIS" class="btn btn-primary" role="button">Vyzkoušet heatmapu</a>
|
|
94 | 94 |
|
95 | 95 |
<div class="map-point point-3"> |
96 | 96 |
<div class="desc"> |
Také k dispozici: Unified diff
+ vyřešení bugu s vybíráním datové sady