示例#1
0
 /**
  * @param int $yAxisMin
  */
 public function setYAxisMin($yAxisMin)
 {
     Assertion::nullOrInteger($yAxisMin);
     $this->yAxisMin = $yAxisMin;
 }
示例#2
0
 /**
  * Initialize a data sample using a value and the current time
  *
  * @param   float $value
  *
  * @return Data
  */
 public static function fromValue($value)
 {
     Assertion::float($value);
     return static::fromCarbon(new Carbon(), $value);
 }
示例#3
0
 /**
  * Persist changes to a metric's sample
  *
  * @param Data $data
  */
 public function persist(Data $data)
 {
     Assertion::lessOrEqualThan($data->getDatetime()->diffInDays(), static::BACKFILL_LIMIT_DAYS, sprintf('Data samples can only be backfilled as far back as %d days', static::BACKFILL_LIMIT_DAYS));
     $this->driver->post('pages/{page}/metrics/{metric}/data.json', ['metric' => $this->metricId], ['data' => ['timestamp' => $data->getDatetime()->getTimestamp(), 'value' => $data->getValue()]]);
 }
示例#4
0
 /**
  * Set the component's status (see Component::STATUS_* constants)
  *
  * @param string $status
  */
 public function setStatus($status)
 {
     Assertion::choice($status, array_keys(self::$statuses), 'The component status is invalid');
     $this->status = $status;
 }
示例#5
0
 /**
  * Combine and submit the total of the samples to the metric
  *
  * @param int $resolution   Resolution (defaults to 30 seconds)
  */
 public function submitTotals($resolution = self::SAMPLES_INTERVAL)
 {
     Assertion::greaterOrEqualThan($resolution, self::SAMPLES_INTERVAL, sprintf('The minimum resolution is %d seconds', self::SAMPLES_INTERVAL));
     if (sizeof($this->samples) == 0) {
         return;
     }
     $totals = [];
     ksort($this->samples);
     foreach ($this->samples as $timestamp => $samples) {
         foreach ($samples as $sample) {
             $key = $timestamp - $timestamp % $resolution;
             if (!isset($totals[$key])) {
                 $totals[$key] = 0;
             }
             $totals[$key] += $sample;
         }
     }
     // Submit resulting samples to the metric
     foreach ($totals as $timestamp => $value) {
         $this->endpoint->persist(Data::fromUnixTimestamp($timestamp, $value));
     }
     $this->reset();
 }