Projekt

Obecné

Profil

Stáhnout (4.19 KB) Statistiky
| Větev: | Revize:
1 3fc08f2d vastja
<?php
2
3
namespace App\Controller;
4
5 03c02899 vastja
use App\Entity\DataSet;
6 4b6b5f1b vastja
use App\Form\DataSetType;
7 ea92a5e5 vastja
use App\Repository\IOpenDataManager;
8 03c02899 vastja
use Symfony\Component\HttpFoundation\Request;
9 3fc08f2d vastja
use Symfony\Component\Routing\Annotation\Route;
10
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
11
12
class HeatmapController extends AbstractController {
13
    /**
14 70a3df53 vastja
     * Map page controller.
15
     *
16
     * @param IOpenDataManager $manager connection to database autowired
17
     *
18 c6708024 vastja
     * @Route("/heatmap", name="heatmap")
19 3fc08f2d vastja
     */
20 dfe43218 vastja
    public function index(Request $request, IOpenDataManager $manager) {
21 03c02899 vastja
        $dataSet = new DataSet();
22
23
        $form = $this->createForm(DataSetType::class, $dataSet);
24
        $form->handleRequest($request);
25
26 03ccdd65 vastja
        $isSubmitted = $form->isSubmitted();
27
        if ($isSubmitted) {
28 03c02899 vastja
            $dataSet = $form->getData();
29 70a3df53 vastja
            // Chceck whether the data is valid i.e. such a collection exists
30 03ccdd65 vastja
            if (false == $manager->isCollectionAvailable($dataSet->getType(), $dataSet->getDate())) {
31 70a3df53 vastja
                // Not? Populate form with empty data
32 03ccdd65 vastja
                $dataSet = new DataSet();
33 dfe43218 vastja
            }
34 03ccdd65 vastja
            $form = $this->createForm(DataSetType::class, $dataSet);
35 03c02899 vastja
        }
36
37
        return $this->render(
38
            'heatmap.html.twig',
39
            [
40
                'form' => $form->createView(),
41 03ccdd65 vastja
                'submitted' => $isSubmitted,
42 64bc2934 vastja
                'data_to_display' => $dataSet,
43 03c02899 vastja
            ]
44
        );
45 3fc08f2d vastja
    }
46
47
    /**
48 70a3df53 vastja
     * Provides specific dataset information i.e. position, number and other informations depending on data type.
49
     *
50
     * @param IOpenDataManager $manager connection to database autowired
51
     * @param string           $name    dataset name
52
     * @param string           $date    dataset date in format YYYY-mm-dd
53
     * @param string           $time    dataset time, number between 0 - 23
54
     *
55
     * @return json with dataset information
56
     *
57 64bc2934 vastja
     * @Route("heatmap/opendata/{name}/{date}/{time}", name="opendata")
58 3fc08f2d vastja
     */
59 03ccdd65 vastja
    public function opendata(IOpenDataManager $manager, $name = 'NONE', $date = '2020-01-01', $time = '1') {
60 3ae59f75 vastja
        return $this->json([
61
            'items' => $manager->getCollectionDataByName($name, $date, $time),
62
            'max' => $manager->getMaxCollectionNumberAtDay($name, $date),
63
        ]);
64 3fc08f2d vastja
    }
65 03c02899 vastja
66
    /**
67 70a3df53 vastja
     * Provides available datasets in given date.
68
     *
69
     * @param IOpenDataManager $manager connection to database autowired
70
     * @param string           $date    dataset date in format YYYY-mm-dd
71
     *
72
     * @return json with available datasets names
73
     *
74 03c02899 vastja
     * @Route("heatmap/available/{date}", name="available")
75
     */
76 afb0cc02 vastja
    public function availableDatasets(IOpenDataManager $manager, $date = '2020-01-01') {
77 03c02899 vastja
        return $this->json($manager->getAvailableCollectionsByDay($date));
78
    }
79 d8f6e6f2 vastja
80
    /**
81 70a3df53 vastja
     * Provides dates with at least one available dataset.
82
     *
83
     * @param IOpenDataManager $manager connection to database
84
     *
85
     * @return json with dates with at least one available dataset in format YYYY-mm-dd
86
     *
87 d8f6e6f2 vastja
     * @Route("heatmap/dates", name="dates")
88
     */
89
    public function datesWithAvailableDatasets(IOpenDataManager $manager) {
90
        return $this->json($manager->getDatesWithAvailableCollection());
91
    }
92 61ff7718 vastja
93
    /**
94 70a3df53 vastja
     * Provides for dataset with given name all locations.
95
     *
96
     * @param IOpenDataManager $manager connection to database autowired
97
     * @param string           $name    dataset name
98
     *
99
     * @return json with all locations for dataset with given name as [x => lat, y => lng]
100
     *
101 61ff7718 vastja
     * @Route("heatmap/positions/{name}", name="positions")
102
     */
103
    public function dataSourcePoistions(IOpenDataManager $manager, $name = 'NONE') {
104
        return $this->json($manager->getDataSourcePositions($name));
105
    }
106 72a438f3 vastja
107
    /**
108 70a3df53 vastja
     * Provides last available date for each available dataset type.
109
     *
110
     * @param IOpenDataManager $manager connection to database autowired
111
     *
112
     * @return json with last available date for each available dataset type as [collection-type-name => YYYY-mm-dd]
113
     *
114 72a438f3 vastja
     * @Route("heatmap/last", name="last")
115
     */
116
    public function lastAvailableCollections(IOpenDataManager $manager) {
117
        return $this->json($manager->getLastAvailableCollections());
118
    }
119 3fc08f2d vastja
}