1 |
3fc08f2d
|
vastja
|
<?php
|
2 |
|
|
|
3 |
|
|
namespace App\Controller;
|
4 |
|
|
|
5 |
2f227a6c
|
ballakt
|
use App\Utils\Utils;
|
6 |
03c02899
|
vastja
|
use App\Entity\DataSet;
|
7 |
2f227a6c
|
ballakt
|
use App\Form\DatasetFormBuilder;
|
8 |
ea92a5e5
|
vastja
|
use App\Repository\IOpenDataManager;
|
9 |
03c02899
|
vastja
|
use Symfony\Component\HttpFoundation\Request;
|
10 |
3fc08f2d
|
vastja
|
use Symfony\Component\Routing\Annotation\Route;
|
11 |
|
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
12 |
|
|
|
13 |
|
|
class HeatmapController extends AbstractController {
|
14 |
|
|
/**
|
15 |
70a3df53
|
vastja
|
* Map page controller.
|
16 |
|
|
*
|
17 |
|
|
* @param IOpenDataManager $manager connection to database autowired
|
18 |
|
|
*
|
19 |
c6708024
|
vastja
|
* @Route("/heatmap", name="heatmap")
|
20 |
3fc08f2d
|
vastja
|
*/
|
21 |
dfe43218
|
vastja
|
public function index(Request $request, IOpenDataManager $manager) {
|
22 |
03c02899
|
vastja
|
$dataSet = new DataSet();
|
23 |
2f227a6c
|
ballakt
|
$datasetFormBuilder = new DatasetFormBuilder($manager);
|
24 |
|
|
$formBuilder = $datasetFormBuilder->getBuilder();
|
25 |
03c02899
|
vastja
|
|
26 |
2f227a6c
|
ballakt
|
$form = $formBuilder->getForm();
|
27 |
|
|
$form->submit($request->query->all());
|
28 |
03ccdd65
|
vastja
|
$isSubmitted = $form->isSubmitted();
|
29 |
|
|
if ($isSubmitted) {
|
30 |
03c02899
|
vastja
|
$dataSet = $form->getData();
|
31 |
2f227a6c
|
ballakt
|
//check availability
|
32 |
|
|
$notExist = false;
|
33 |
|
|
if ($dataSet->getType() && count($dataSet->getType()) > 0) {
|
34 |
|
|
foreach ($dataSet->getType() as $value) {
|
35 |
|
|
if (!$manager->isCollectionAvailable($value, $dataSet->getDate())) {
|
36 |
|
|
$notExist = true;
|
37 |
|
|
break;
|
38 |
|
|
}
|
39 |
|
|
}
|
40 |
|
|
} else {
|
41 |
|
|
$notExist = true;
|
42 |
|
|
}
|
43 |
|
|
if ($notExist) {
|
44 |
70a3df53
|
vastja
|
// Not? Populate form with empty data
|
45 |
2f227a6c
|
ballakt
|
$formBuilder = $datasetFormBuilder->getBuilder();
|
46 |
|
|
$form = $formBuilder->getForm();
|
47 |
dfe43218
|
vastja
|
}
|
48 |
03c02899
|
vastja
|
}
|
49 |
2f227a6c
|
ballakt
|
//ziskej barvy o datasetech a namapuj je na jejich jmena
|
50 |
03c02899
|
vastja
|
|
51 |
|
|
return $this->render(
|
52 |
|
|
'heatmap.html.twig',
|
53 |
|
|
[
|
54 |
|
|
'form' => $form->createView(),
|
55 |
03ccdd65
|
vastja
|
'submitted' => $isSubmitted,
|
56 |
64bc2934
|
vastja
|
'data_to_display' => $dataSet,
|
57 |
2f227a6c
|
ballakt
|
'dataset_colors' => Utils::prepareDatasetsColors($manager->getAvailableCollections()),
|
58 |
d51166e8
|
ballakt
|
'formated_current_time' => $dataSet->getFormattedTime(),
|
59 |
|
|
'current_time' => $dataSet->getTime(),
|
60 |
03c02899
|
vastja
|
]
|
61 |
|
|
);
|
62 |
3fc08f2d
|
vastja
|
}
|
63 |
|
|
|
64 |
|
|
/**
|
65 |
70a3df53
|
vastja
|
* Provides specific dataset information i.e. position, number and other informations depending on data type.
|
66 |
|
|
*
|
67 |
|
|
* @param IOpenDataManager $manager connection to database autowired
|
68 |
|
|
* @param string $name dataset name
|
69 |
|
|
* @param string $date dataset date in format YYYY-mm-dd
|
70 |
|
|
* @param string $time dataset time, number between 0 - 23
|
71 |
|
|
*
|
72 |
|
|
* @return json with dataset information
|
73 |
|
|
*
|
74 |
64bc2934
|
vastja
|
* @Route("heatmap/opendata/{name}/{date}/{time}", name="opendata")
|
75 |
3fc08f2d
|
vastja
|
*/
|
76 |
03ccdd65
|
vastja
|
public function opendata(IOpenDataManager $manager, $name = 'NONE', $date = '2020-01-01', $time = '1') {
|
77 |
3ae59f75
|
vastja
|
return $this->json([
|
78 |
|
|
'items' => $manager->getCollectionDataByName($name, $date, $time),
|
79 |
|
|
'max' => $manager->getMaxCollectionNumberAtDay($name, $date),
|
80 |
|
|
]);
|
81 |
3fc08f2d
|
vastja
|
}
|
82 |
03c02899
|
vastja
|
|
83 |
|
|
/**
|
84 |
70a3df53
|
vastja
|
* Provides available datasets in given date.
|
85 |
|
|
*
|
86 |
|
|
* @param IOpenDataManager $manager connection to database autowired
|
87 |
|
|
* @param string $date dataset date in format YYYY-mm-dd
|
88 |
|
|
*
|
89 |
|
|
* @return json with available datasets names
|
90 |
|
|
*
|
91 |
03c02899
|
vastja
|
* @Route("heatmap/available/{date}", name="available")
|
92 |
|
|
*/
|
93 |
afb0cc02
|
vastja
|
public function availableDatasets(IOpenDataManager $manager, $date = '2020-01-01') {
|
94 |
03c02899
|
vastja
|
return $this->json($manager->getAvailableCollectionsByDay($date));
|
95 |
|
|
}
|
96 |
d8f6e6f2
|
vastja
|
|
97 |
|
|
/**
|
98 |
70a3df53
|
vastja
|
* Provides dates with at least one available dataset.
|
99 |
|
|
*
|
100 |
|
|
* @param IOpenDataManager $manager connection to database
|
101 |
|
|
*
|
102 |
|
|
* @return json with dates with at least one available dataset in format YYYY-mm-dd
|
103 |
|
|
*
|
104 |
d8f6e6f2
|
vastja
|
* @Route("heatmap/dates", name="dates")
|
105 |
|
|
*/
|
106 |
|
|
public function datesWithAvailableDatasets(IOpenDataManager $manager) {
|
107 |
|
|
return $this->json($manager->getDatesWithAvailableCollection());
|
108 |
|
|
}
|
109 |
61ff7718
|
vastja
|
|
110 |
|
|
/**
|
111 |
70a3df53
|
vastja
|
* Provides for dataset with given name all locations.
|
112 |
|
|
*
|
113 |
|
|
* @param IOpenDataManager $manager connection to database autowired
|
114 |
|
|
* @param string $name dataset name
|
115 |
|
|
*
|
116 |
|
|
* @return json with all locations for dataset with given name as [x => lat, y => lng]
|
117 |
|
|
*
|
118 |
61ff7718
|
vastja
|
* @Route("heatmap/positions/{name}", name="positions")
|
119 |
|
|
*/
|
120 |
|
|
public function dataSourcePoistions(IOpenDataManager $manager, $name = 'NONE') {
|
121 |
|
|
return $this->json($manager->getDataSourcePositions($name));
|
122 |
|
|
}
|
123 |
72a438f3
|
vastja
|
|
124 |
|
|
/**
|
125 |
70a3df53
|
vastja
|
* Provides last available date for each available dataset type.
|
126 |
|
|
*
|
127 |
|
|
* @param IOpenDataManager $manager connection to database autowired
|
128 |
|
|
*
|
129 |
|
|
* @return json with last available date for each available dataset type as [collection-type-name => YYYY-mm-dd]
|
130 |
|
|
*
|
131 |
72a438f3
|
vastja
|
* @Route("heatmap/last", name="last")
|
132 |
|
|
*/
|
133 |
|
|
public function lastAvailableCollections(IOpenDataManager $manager) {
|
134 |
|
|
return $this->json($manager->getLastAvailableCollections());
|
135 |
|
|
}
|
136 |
3fc08f2d
|
vastja
|
}
|