/**
  * @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
 public function testSampleStandardDeviationWithLessThanTwoElementsIsNull()
 {
     $this->assertNull(Stats::standardDeviation(array(), true));
     $this->assertNull(Stats::standardDeviation(array(1), true));
 }