commit 03ccdd657da292e8a1f84fdb442643b862e29b88
Author: vastja <vastja@gmail.com>
Date:   Mon May 11 21:43:05 2020 +0200

    + vyřešení bugu s vybíráním datové sady

diff --git a/website/public/js/zcu-heatmap.js b/website/public/js/zcu-heatmap.js
index 68e4833..d96253e 100644
--- a/website/public/js/zcu-heatmap.js
+++ b/website/public/js/zcu-heatmap.js
@@ -152,8 +152,7 @@ function loadCurrentTimeHeatmap(route) {
   data = []
 
   name = $('#type').children("option:selected").text();
-  var parts = $('#date').val().split('-');
-  date = parts[2] + parts[1] + parts[0];
+  date = $('#date').val()
   currentTime = parseInt($('#time').children("option:selected").val());
   setTimeline();
 
@@ -211,12 +210,10 @@ function drawHeatmap(data) {
 
 function checkDataSetsAvailability(route) {
 
-  var parts = $('#date').val().split('-');
-  
   $.ajax({
     type: "POST",
     // Todo it might be good idea to change db collections format
-    url: route + '/' + parts[2] + parts[1] + parts[0],
+    url: route + '/' + $('#date').val(),
     success: function(result) {
       updateAvailableDataSets(result);
     }
diff --git a/website/src/Controller/HeatmapController.php b/website/src/Controller/HeatmapController.php
index 52ac429..66c2314 100644
--- a/website/src/Controller/HeatmapController.php
+++ b/website/src/Controller/HeatmapController.php
@@ -19,19 +19,20 @@ class HeatmapController extends AbstractController {
         $form = $this->createForm(DataSetType::class, $dataSet);
         $form->handleRequest($request);
 
-        if ($form->isSubmitted()) {
+        $isSubmitted = $form->isSubmitted();
+        if ($isSubmitted) {
             $dataSet = $form->getData();
-            $name = $manager->getXthAvailableCollectionByDay($dataSet->getType(), $dataSet->getDate());
-            if (false == $manager->isCollectionAvailable($name, $dataSet->getDate())) {
-                $form = $this->createForm(DataSetType::class, new DataSet());
+            if (false == $manager->isCollectionAvailable($dataSet->getType(), $dataSet->getDate())) {
+                $dataSet = new DataSet();
             }
+            $form = $this->createForm(DataSetType::class, $dataSet);
         }
 
         return $this->render(
             'heatmap.html.twig',
             [
                 'form' => $form->createView(),
-                'submitted' => $form->isSubmitted(),
+                'submitted' => $isSubmitted,
                 'data_to_display' => $dataSet,
             ]
         );
@@ -40,7 +41,7 @@ class HeatmapController extends AbstractController {
     /**
      * @Route("heatmap/opendata/{name}/{date}/{time}", name="opendata")
      */
-    public function opendata(IOpenDataManager $manager, $name = 'NONE', $date = '01012020', $time = '1') {
+    public function opendata(IOpenDataManager $manager, $name = 'NONE', $date = '2020-01-01', $time = '1') {
         return $this->json([
             'items' => $manager->getCollectionDataByName($name, $date, $time),
             'max' => $manager->getMaxCollectionNumberAtDay($name, $date),
diff --git a/website/src/Entity/DataSet.php b/website/src/Entity/DataSet.php
index d6c294f..4e3be69 100644
--- a/website/src/Entity/DataSet.php
+++ b/website/src/Entity/DataSet.php
@@ -17,7 +17,7 @@ class DataSet {
     }
 
     public function setDate($date) {
-        $this->date = date('dmY', strtotime($date));
+        $this->date = date('Y-m-d', strtotime($date));
     }
 
     public function getDate() {
diff --git a/website/src/Form/DataSetType.php b/website/src/Form/DataSetType.php
index b4bb2b0..7a512c1 100644
--- a/website/src/Form/DataSetType.php
+++ b/website/src/Form/DataSetType.php
@@ -22,6 +22,11 @@ class DataSetType extends AbstractType {
     }
 
     public function buildForm(FormBuilderInterface $builder, array $options) {
+        
+        $selectTypeData = $options['data']->getDate() == null ?
+            Utils::prepareDatasetsNames($this->manager->getAvailableCollections()) :
+            $this->manager->getAvailableCollectionsByDay($options['data']->getDate());
+        
         $builder
             ->add('date', TextType::class)
             ->add('time', ChoiceType::class, [
@@ -53,7 +58,7 @@ class DataSetType extends AbstractType {
                 ],
             ])
             ->add('type', ChoiceType::class, [
-                'choices' => Utils::prepareDatasetsNames($this->manager->getAvailableCollections()),
+                'choices' => $selectTypeData,
             ])
             ->add('submit', SubmitType::class);
     }
diff --git a/website/src/IOpenDataManager.php b/website/src/IOpenDataManager.php
index 7bb6b28..1bfcc77 100644
--- a/website/src/IOpenDataManager.php
+++ b/website/src/IOpenDataManager.php
@@ -9,8 +9,6 @@ interface IOpenDataManager {
 
     public function getAvailableCollectionsByDay($date);
 
-    public function getXthAvailableCollectionByDay($index, $date);
-
     public function isCollectionAvailable($name, $date);
 
     public function getMaxCollectionNumberAtDay($name, $date);
diff --git a/website/src/OpenDataManager.php b/website/src/OpenDataManager.php
index 5ac40d4..a87d510 100644
--- a/website/src/OpenDataManager.php
+++ b/website/src/OpenDataManager.php
@@ -17,7 +17,7 @@ class OpenDataManager implements IOpenDataManager {
 
     public function getCollectionDataByName($name, $date, $hour) {
         $valh = $hour < 10 ? '0'.$hour : $hour;
-        $openData = $this->manager->executeQuery('open-data-db.'.$name.$date, new Query(['date' => $date.$valh], []));
+        $openData = $this->manager->executeQuery('open-data-db.'.$name.$date, new Query(['date' => $date.'-'.$valh], []));
 
         $openData->setTypeMap([
             'array' => 'array',
@@ -46,31 +46,13 @@ class OpenDataManager implements IOpenDataManager {
         $index = 0;
         foreach ($available as $key => $value) {
             if ($this->isCollectionAvailable($value['name'], $date) && false == array_key_exists($value['name'], $availableInDate)) {
-                $availableInDate[$value['name']] = $index++;
+                $availableInDate[$value['name']] = $value['name'];
             }
         }
 
         return $availableInDate;
     }
 
-    public function getXthAvailableCollectionByDay($index, $date) {
-        $availableInDate = [];
-        $available = $this->getAvailableCollections();
-        $currentIndex = 0;
-
-        foreach ($available as $key => $value) {
-            if ($this->isCollectionAvailable($value['name'], $date) && false == array_key_exists($value['name'], $availableInDate)) {
-                if ($currentIndex == $index) {
-                    return $value['name'];
-                } else {
-                    ++$currentIndex;
-                }
-            }
-        }
-
-        return '';
-    }
-
     public function isCollectionAvailable($name, $date) {
         $command = new Command(['listCollections' => 1, 'filter' => ['name' => $name.$date]]);
         $result = $this->manager->executeCommand('open-data-db', $command)->toArray();
diff --git a/website/src/Utils/Utils.php b/website/src/Utils/Utils.php
index 78bdd8a..658132c 100644
--- a/website/src/Utils/Utils.php
+++ b/website/src/Utils/Utils.php
@@ -9,7 +9,7 @@ class Utils {
         $index = 0;
         foreach ($datasets as $key => $value) {
             if (false == array_key_exists($value['name'], $names)) {
-                $names[$value['name']] = $index++;
+                $names[$value['name']] = $value['name'];
             }
         }
 
diff --git a/website/templates/index.html.twig b/website/templates/index.html.twig
index 3207ca6..f18b63d 100644
--- a/website/templates/index.html.twig
+++ b/website/templates/index.html.twig
@@ -45,7 +45,7 @@
           </li>
           <li class="nav-item button">
             <h2>
-              <a href="/heatmap/?data_set[date]=2019-04-25&amp;data_set[time]=9&amp;data_set[type]=1" class="nav-link">Zobrazit heatmapu</a>
+              <a href="/heatmap/?data_set[date]=2019-04-25&amp;data_set[time]=9&amp;data_set[type]=JIS" class="nav-link">Zobrazit heatmapu</a>
             </h2>
           </li>
         </ul>
@@ -62,7 +62,7 @@
             <h3>Život na ZČU během dne</h3>
             <hr>
             <p>Zobrazte si heatmapu života univerzity hodinu po hodině během jednoho dne. Od ranního probouzení, kdy studenti a&nbsp;zaměstnanci přicházejí do laboratoří, přes polední špičku v&nbsp;menze až do samotného večera, kdy končí poslední z&nbsp;přednášek a&nbsp;cvičení.</p>
-            <a href="/heatmap/?data_set[date]=2019-04-25&amp;data_set[time]=9&amp;data_set[type]=1" class="btn btn-primary" role="button">Vyzkoušet heatmapu</a>
+            <a href="/heatmap/?data_set[date]=2019-04-25&amp;data_set[time]=9&amp;data_set[type]=JIS" class="btn btn-primary" role="button">Vyzkoušet heatmapu</a>
 
             <div class="map-point point-1">
               <div class="desc">
@@ -90,7 +90,7 @@
             <h3>Hledání anomálií</h3>
             <hr>
             <p>Heatmapa vám také dává možnost prozkoumávat data vlastním způsobem &ndash; stačí jen zvolit konkrétní datum a&nbsp;čas, pro které chcete data zobrazit. Můžete tak objevit i&nbsp;různé anomálie, například narazit na noční návštěvníky kampusu nebo odhalit návraty na studentské koleje v&nbsp;brzkých ranních hodinách&hellip;</p>
-            <a href="/heatmap/?data_set[date]=2019-04-25&amp;data_set[time]=9&amp;data_set[type]=1" class="btn btn-primary" role="button">Vyzkoušet heatmapu</a>
+            <a href="/heatmap/?data_set[date]=2019-04-25&amp;data_set[time]=9&amp;data_set[type]=JIS" class="btn btn-primary" role="button">Vyzkoušet heatmapu</a>
 
             <div class="map-point point-3">
               <div class="desc">
