@@ 165-184 (lines=20) @@ | ||
162 | * @param Variable $variable |
|
163 | * @return array |
|
164 | */ |
|
165 | public function getDayHistory(Variable $variable) |
|
166 | { |
|
167 | /** @var EntityManager $em */ |
|
168 | $em = $this->getDoctrine()->getManager(); |
|
169 | ||
170 | $q = $em->createQueryBuilder(); |
|
171 | $res = $q-> |
|
172 | select('AVG(vh.value) as av')-> |
|
173 | addSelect('DATE_FORMAT(vh.time,\'%Y-%m-%d %H:00\') as df')-> |
|
174 | from('AppBundle:VariableHistory', 'vh')-> |
|
175 | where('vh.time >= :date')-> |
|
176 | setParameter('date', new \DateTime('-48 hour'))-> |
|
177 | andWhere('vh.var = :var_id')-> |
|
178 | setParameter('var_id', $variable->getId())-> |
|
179 | groupBy('df')-> |
|
180 | orderBy('df', 'asc')-> |
|
181 | getQuery(); |
|
182 | ||
183 | return $res->getArrayResult(); |
|
184 | } |
|
185 | ||
186 | /** |
|
187 | * @param Variable $variable |
|
@@ 190-210 (lines=21) @@ | ||
187 | * @param Variable $variable |
|
188 | * @return array |
|
189 | */ |
|
190 | public function getExtremes(Variable $variable) |
|
191 | { |
|
192 | /** |
|
193 | * @var EntityManager $em |
|
194 | */ |
|
195 | $em = $this->getDoctrine()->getManager(); |
|
196 | ||
197 | $q = $em->createQueryBuilder(); |
|
198 | $res = $q-> |
|
199 | select('AVG(vh.value) as average') |
|
200 | ->addSelect('MIN(vh.value) as minimum') |
|
201 | ->addSelect('MAX(vh.value) as maximum') |
|
202 | ->from('AppBundle:VariableHistory', 'vh') |
|
203 | ->where('vh.time >= :date') |
|
204 | ->setParameter('date', new \DateTime('-24 hour')) |
|
205 | ->andWhere('vh.var = :var_id') |
|
206 | ->setParameter('var_id', $variable->getId()) |
|
207 | ->getQuery(); |
|
208 | ||
209 | return $res->getArrayResult()[0]; |
|
210 | } |
|
211 | ||
212 | /** |
|
213 | * @param Variable $variable |
|
@@ 216-233 (lines=18) @@ | ||
213 | * @param Variable $variable |
|
214 | * @return array |
|
215 | */ |
|
216 | public function getLastValue(Variable $variable) |
|
217 | { |
|
218 | /** @var EntityManager $em */ |
|
219 | $em = $this->getDoctrine()->getManager(); |
|
220 | ||
221 | $q = $em->createQueryBuilder(); |
|
222 | $res = $q-> |
|
223 | select('vh.value as av')-> |
|
224 | addSelect('vh.time as df')-> |
|
225 | from('AppBundle:VariableHistory', 'vh')-> |
|
226 | where('vh.var = :var_id')-> |
|
227 | setParameter('var_id', $variable->getId())-> |
|
228 | orderBy('df', 'desc')-> |
|
229 | setMaxResults(1)-> |
|
230 | getQuery(); |
|
231 | ||
232 | return $res->getSingleResult(); |
|
233 | } |
|
234 | } |
|
235 |