/**
  * Allow to create convert data in standard unit for metrics
  *
  * @param AbstractMetric $metric
  */
 protected function createMetricBaseValues(AbstractMetric $metric)
 {
     $baseUnit = $this->manager->getStandardUnitForFamily($metric->getFamily());
     if (is_numeric($metric->getData())) {
         $baseData = $this->converter->setFamily($metric->getFamily())->convertBaseToStandard($metric->getUnit(), $metric->getData());
     } else {
         $baseData = null;
     }
     $metric->setBaseData($baseData)->setBaseUnit($baseUnit);
 }
 /**
  * Get the data stored in the metric
  *
  * @param AbstractMetric $metric
  * @param boolean        $withUnit
  *
  * @return string
  */
 public function getMetricData(AbstractMetric $metric, $withUnit)
 {
     $data = $metric->getData();
     if (null === $data || '' === $data) {
         return '';
     }
     if ($withUnit) {
         $data = sprintf('%.4F %s', $metric->getData(), $metric->getUnit());
     } else {
         $data = sprintf('%.4F', $metric->getData());
     }
     return $data;
 }
 function it_normalizes_empty_metric_in_one_fields(AbstractMetric $metric)
 {
     $metric->getData()->willReturn('');
     $metric->getUnit()->willReturn('KILOGRAM');
     $this->normalize($metric, null, ['field_name' => 'weight', 'metric_format' => 'single_field'])->shouldReturn(['weight' => '']);
 }
 function it_normalizes_metric_when_has_no_data(AbstractMetric $metric)
 {
     $metric->getData()->willReturn(null);
     $this->normalize($metric, 'mongodb_json', [])->shouldReturn(null);
 }