Ejemplo n.º 1
0
 /**
  * Load metrics from last X days and cache them
  *
  * @param integer $days Number of days you want to load and cache
  *
  * @return EntryInterface[] Array of loaded entries
  */
 public function loadEntriesFromLastDays($days)
 {
     $entries = $this->entryRepository->getEntriesFromLastDays($days);
     foreach ($entries as $entry) {
         $this->metricsBucket->add($entry);
     }
     return $entries;
 }
Ejemplo n.º 2
0
 /**
  * Adds a new entry into database and into metrics bucket.
  *
  * @param string   $token    Event
  * @param string   $event    Token
  * @param string   $uniqueId Unique id
  * @param int      $type     Type
  * @param DateTime $dateTime DateTime
  *
  * @return $this Self Object
  */
 public function addEntry($token, $event, $uniqueId, $type, DateTime $dateTime)
 {
     $entry = $this->entryFactory->create($token, $event, $uniqueId, $type, $dateTime);
     $this->entryObjectManager->persist($entry);
     $this->entryObjectManager->flush($entry);
     $this->metricsBucket->add($entry);
     return $this;
 }
Ejemplo n.º 3
0
 /**
  * Returns a list of functions to add to the existing list.
  *
  * @return Twig_SimpleFunction[] An array of functions
  */
 public function getFunctions()
 {
     return [new Twig_SimpleFunction('metric_beacon_unique', function ($token, $event, $dates) {
         return $this->metricBucket->getBeaconsUnique($token, $event, $dates);
     }), new Twig_SimpleFunction('metric_beacon_total', function ($token, $event, $dates) {
         return $this->metricBucket->getBeaconsTotal($token, $event, $dates);
     }), new Twig_SimpleFunction('metric_accumulation', function ($token, $event, $dates) {
         return $this->metricBucket->getAccumulation($token, $event, $dates);
     }), new Twig_SimpleFunction('metric_distributions', function ($token, $event, $dates) {
         return $this->metricBucket->getDistributions($token, $event, $dates);
     })];
 }
Ejemplo n.º 4
0
 /**
  * Return metric distributions
  *
  * @param string   $token Event
  * @param string   $event Token
  * @param string[] $dates Dates
  *
  * @return array Distribution values
  */
 public function getDistributions($token, $event, $dates)
 {
     return (int) $this->metricBucket->getDistributions($token, $event, $dates);
 }