function it_normalizes_metric_when_has_data(AbstractMetric $metric)
 {
     $metric->getData()->willReturn(42.55);
     $metric->getUnit()->willReturn('GRAM');
     $metric->getBaseData()->willReturn(0.04255);
     $metric->getBaseUnit()->willReturn('KILOGRAM');
     $metric->getFamily()->willReturn('Weight');
     $this->normalize($metric, 'mongodb_json', [])->shouldReturn(['data' => 42.55, 'unit' => 'GRAM', 'baseData' => 0.04255, 'baseUnit' => 'KILOGRAM', 'family' => 'Weight']);
 }
 /**
  * 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' => '']);
 }