Fixed some issues when importing parameters from partkeepr

Before values were not properly imported, if there was not a normalized version yet and units were not correctly imported
This commit is contained in:
Jan Böhmer 2024-01-11 00:02:32 +01:00
parent 301ecf6c95
commit d9f58b935a
2 changed files with 30 additions and 7 deletions

View file

@ -235,4 +235,27 @@ trait PKImportHelperTrait
$property->setAccessible(true);
$property->setValue($entity, $date);
}
/**
* Gets the SI prefix factor for the given prefix ID.
* Used to convert a value from the PartKeepr database to the PartDB database.
* @param array $data
* @param int $prefix_id
* @return float
*/
protected function getSIPrefixFactor(array $data, int $prefix_id): float
{
if ($prefix_id === 0) {
return 1.0;
}
$prefixes = $data['siprefix'];
foreach ($prefixes as $prefix) {
if ((int) $prefix['id'] === $prefix_id) {
return pow((int) $prefix['base'], (int) $prefix['exponent']);
}
}
throw new \RuntimeException(sprintf('Could not find SI prefix with ID %s', $prefix_id));
}
}