Revize 01f99166
Přidáno uživatelem Jan Kohlíček před téměř 7 roky(ů)
backend/app/Model/Zaznam.php | ||
---|---|---|
23 | 23 |
* Vrati posledni datum pro ktere existuji nejake zaznamy. |
24 | 24 |
* @return String Posledni datum pro ktere existuji zaznamy. |
25 | 25 |
*/ |
26 |
public static function lastInsertedDate() { |
|
26 |
public static function lastInsertedDate() |
|
27 |
{ |
|
27 | 28 |
return DB::table('zaznam_cas')->select(DB::raw('max(date(datetime_od)) as last_day'))->get(); |
28 | 29 |
} |
29 | 30 |
|
... | ... | |
38 | 39 |
* @param int $direction Pozadovany smer. Null znamena oba smery. |
39 | 40 |
* @return array Prumery dopravy pro casovy usek podle typu vozidla. |
40 | 41 |
*/ |
41 |
public static function averageByDevice($deviceId, $dateFrom, $dateTo, $timeFrom, $timeTo, $direction) { |
|
42 |
$dateTimeFrom = null; |
|
43 |
$dateTimeTo = null; |
|
42 |
public static function averageByDevice($deviceId, $dateFrom, $dateTo, $timeFrom, $timeTo, $direction) |
|
43 |
{ |
|
44 | 44 |
$lastDate = null; |
45 | 45 |
$dir = null; |
46 | 46 |
|
... | ... | |
54 | 54 |
$lastDate = $lastDate[0]->last_day; |
55 | 55 |
} |
56 | 56 |
} |
57 |
$dateTimeFrom = self::concatDateTime($dateFrom, $timeFrom, $lastDate, '00:00:00'); |
|
58 |
$dateTimeTo = self::concatDateTime($dateTo, $timeTo, $lastDate, '23:59:59'); |
|
59 |
|
|
60 | 57 |
|
61 | 58 |
// vytvoreni query - vsechno to dat dohromady |
62 |
$query = DB::table('zaznam') |
|
63 |
->join('zaznam_cas', 'zaznam.zaznam_cas_id', '=', 'zaznam_cas.id') |
|
64 |
->join('vozidlo', 'zaznam.vozidlo_id', '=', 'vozidlo.id') |
|
59 |
$query = DB::table('zaznam_cas') |
|
60 |
->join('zaznam', 'zaznam.zaznam_cas_id', '=', 'zaznam_cas.id') |
|
65 | 61 |
->select(DB::raw(" |
66 |
date_format(zaznam_cas.datetime_od, '%Y-%m-%d') as dateFrom, |
|
67 |
date_format(zaznam_cas.datetime_do, '%Y-%m-%d') as dateTo, |
|
68 |
date_format(zaznam_cas.datetime_od, '%H:%i:%s') as timeFrom, |
|
69 |
date_format(zaznam_cas.datetime_do, '%H:%i:%s') as timeTo, |
|
70 |
zaznam_cas.smer as direction, |
|
71 |
avg(zaznam.rychlost_prumer) as speedAverage, |
|
72 |
sum(zaznam.vozidla_pocet) as numberVehicle, |
|
73 |
vozidlo.nazev as typeVehicle, |
|
74 |
vozidlo.id as typeVehicleId |
|
62 |
date_format(zaznam_cas.datetime_od, '%H:%i') as timeFrom, |
|
63 |
date_format(zaznam_cas.datetime_do, '%H:%i') as timeTo, |
|
64 |
ROUND(avg(zaznam.rychlost_prumer),0) as speedAverage, |
|
65 |
CAST(sum(zaznam.vozidla_pocet) as UNSIGNED) as numberVehicle, |
|
66 |
ROUND(avg(zaznam.vozidla_pocet),0) as numberVehicleAverage, |
|
67 |
zaznam.vozidlo_id as typeVehicleId |
|
75 | 68 |
")) |
76 |
->where('zaznam_cas.datetime_od', '>=', $dateTimeFrom) |
|
77 |
->where('zaznam_cas.datetime_do', '<=', $dateTimeTo) |
|
78 |
->where('zaznam_cas.zarizeni_id', '=', $deviceId) |
|
79 |
; |
|
69 |
->whereDate('zaznam_cas.datetime_od', '>=', $dateFrom == null ? $lastDate : $dateFrom) |
|
70 |
->whereDate('zaznam_cas.datetime_do', '<=', $dateTo == null ? $lastDate : $dateTo) |
|
71 |
->whereTime('zaznam_cas.datetime_od', '>=', $timeFrom == null ? '08:00:00' : $timeFrom) |
|
72 |
->whereTime('zaznam_cas.datetime_od', '<=', $timeTo == null ? '23:59:59' : $timeTo) |
|
73 |
->where('zaznam_cas.zarizeni_id', '=', $deviceId); |
|
80 | 74 |
|
81 |
if($direction != null) { |
|
75 |
if ($direction != null) {
|
|
82 | 76 |
$query = $query->where('zaznam_cas.smer', '=', $direction); |
83 | 77 |
} |
84 | 78 |
|
85 | 79 |
// pridat grouping a razeni nakonec |
86 | 80 |
$query = $query |
87 |
->groupBy('timeFrom', 'timeTo', 'typeVehicleId') |
|
88 |
->orderBy('dateFrom', 'asc') |
|
89 |
->orderBy('timeFrom', 'asc') |
|
90 |
->orderBy('typeVehicleId', 'asc'); |
|
81 |
->groupBy('zaznam_cas.datetime_od', 'zaznam.vozidlo_id') |
|
82 |
->orderBy('zaznam_cas.datetime_od', 'asc') |
|
83 |
->orderBy('zaznam.vozidlo_id', 'asc'); |
|
91 | 84 |
|
92 | 85 |
return $query->get(); |
93 | 86 |
} |
... | ... | |
104 | 97 |
* @param int $direction Pozadovany smer. Null znamena oba smery. |
105 | 98 |
* @return array Zaznamy o doprave v casovem useku pro dane zarizeni. |
106 | 99 |
*/ |
107 |
public static function findByDevice($deviceId, $dateFrom, $dateTo, $timeFrom, $timeTo, $direction) { |
|
100 |
public static function findByDevice($deviceId, $dateFrom, $dateTo, $timeFrom, $timeTo, $direction) |
|
101 |
{ |
|
108 | 102 |
$dateTimeFrom = null; |
109 | 103 |
$dateTimeTo = null; |
110 | 104 |
$lastDate = null; |
... | ... | |
139 | 133 |
->where('zaznam_cas.datetime_do', '<=', $dateTimeTo) |
140 | 134 |
->where('zaznam_cas.zarizeni_id', '=', $deviceId); |
141 | 135 |
|
142 |
if($direction != null) { |
|
136 |
if ($direction != null) {
|
|
143 | 137 |
$query = $query->where('zaznam_cas.smer', '=', $direction); |
144 | 138 |
} |
145 | 139 |
|
... | ... | |
160 | 154 |
* @param String $defTime Defaultni hodnota pro casovou slozku. |
161 | 155 |
* @return String Spojene datum a cas. |
162 | 156 |
*/ |
163 |
private static function concatDateTime($date, $time, $defDate, $defTime) { |
|
157 |
private static function concatDateTime($date, $time, $defDate, $defTime) |
|
158 |
{ |
|
164 | 159 |
$dateTime = null; |
165 | 160 |
$d = $date == null ? $defDate : $date; |
166 | 161 |
$t = $time == null ? $defTime : $time; |
... | ... | |
168 | 163 |
$dateTime = date('Y-m-d H:i:s', strtotime("$d $t")); |
169 | 164 |
return $dateTime; |
170 | 165 |
} |
166 |
|
|
171 | 167 |
} |
Také k dispozici: Unified diff
refs #6948: Oprava REST API (/devices, /devices/{id}/time-period) a script pro přidání souřadnic