/**
  * проверка наличия событий в данной комнате за последнее время. Возвращает количество событий
  * @param \AppBundle\Entity\Rooms $room
  * @param string $min_delay
  * @return integer
  */
 public function checkStatus(\AppBundle\Entity\Rooms $room, $min_delay)
 {
     $this->minDelay = $min_delay;
     $em = $this->getEntityManager();
     $n = new \DateTime("now", new \DateTimeZone("Europe/Moscow"));
     $ev_time = $n->sub(new \DateInterval($this->minDelay));
     $query = $em->createQuery("select h\n            from AppBundle:Histories h\n            join h.ev e\n            where e.room = :room and\n                  h.evTime >:ev_time")->setParameter('room', $room->getId())->setParameter("ev_time", $ev_time);
     $ev = $query->getResult();
     return "##" . count($ev);
 }
Exemple #2
0
 /**
  * Выдает массив с усредненными показаниями датчиков за интервал PT7M для заданной комнаты
  * @param \AppBundle\Entity\Rooms $room
  * @return Array
  */
 public function getLastStat(\AppBundle\Entity\Rooms $room)
 {
     $qb = $this->createQueryBuilder('th');
     $qb->select('avg(th.co2) as avg_co2', 'avg(th.t) as avg_t', 'avg(th.h)  as avg_h', 'avg(th.voc)  as avg_voc', 'max(th.deh) as deh')->where('th.room = :room')->andWhere('th.date>:dd')->groupBy('th.room')->setParameter('room', $room->getId())->setParameter('dd', $this->getDateInterval());
     return $qb->getQuery()->getArrayResult();
 }