/**
  * @Route("/log", name="listLog")
  * @Security("is_granted('IS_AUTHENTICATED_REMEMBERED')")
  */
 public function listAction(Request $request)
 {
     $filter = array();
     $options = array('orderBy' => 'localtime', 'orderDir' => 'desc');
     if ($request->query->has('options')) {
         $options = (array) $request->query->get('options') + $options;
     }
     /** @var FormInterface $form */
     $form = $this->get('form.factory')->createNamed('filter', FilterStressLogsForm::class, null, array('csrf_protection' => false));
     $form->handleRequest($request);
     if ($form->isValid()) {
         $filter = $form->getData();
     }
     /** @var StressLogRepository $repo */
     $repo = $this->getDoctrine()->getRepository('AppBundle:StressLog');
     $logs = $repo->findFiltered($this->getUser(), $filter, $options);
     $count = $repo->countFiltered($this->getUser(), $filter);
     $logData = $repo->findFilteredData($this->getUser(), $filter);
     $levels = array_column($logData, 'level');
     return $this->render('stresslog/list.html.twig', array('logs' => $logs, 'form' => $form->createView(), 'expandForm' => $form->isSubmitted(), 'count' => $count, 'filter' => $filter, 'options' => $options, 'stats' => array('mean' => Stats::mean($levels), 'median' => Stats::median($levels), 'range' => Stats::range($levels), 'variance' => Stats::variance($levels), 'stdev' => Stats::standardDeviation($levels))));
 }
Example #2
0
 /**
  * @param $vals
  * @param $median
  *
  * @dataProvider getMedianData
  */
 public function testMedian($vals, $median)
 {
     $this->assertSame($median, Stats::median($vals));
 }