mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-20 17:15:51 +02:00
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:
parent
301ecf6c95
commit
d9f58b935a
2 changed files with 30 additions and 7 deletions
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -173,20 +173,20 @@ class PKPartImporter
|
|||
$entity->setName($name);
|
||||
|
||||
$entity->setValueText($partparameter['stringValue'] ?? '');
|
||||
if ($partparameter['unit_id'] === null) {
|
||||
if ($partparameter['unit_id'] !== null && (int) $partparameter['unit_id'] !== 0) {
|
||||
$entity->setUnit($this->getUnitSymbol($data, (int)$partparameter['unit_id']));
|
||||
} else {
|
||||
$entity->setUnit("");
|
||||
}
|
||||
|
||||
if ($partparameter['normalizedMinValue'] !== null) {
|
||||
$entity->setValueMin((float) $partparameter['normalizedMinValue']);
|
||||
if ($partparameter['value'] !== null) {
|
||||
$entity->setValueTypical((float) $partparameter['value'] * $this->getSIPrefixFactor($data, (int) $partparameter['siPrefix_id']));
|
||||
}
|
||||
if ($partparameter['normalizedValue'] !== null) {
|
||||
$entity->setValueTypical((float) $partparameter['normalizedValue']);
|
||||
if ($partparameter['minimumValue'] !== null) {
|
||||
$entity->setValueMin((float) $partparameter['minimumValue'] * $this->getSIPrefixFactor($data, (int) $partparameter['minSiPrefix_id']));
|
||||
}
|
||||
if ($partparameter['normalizedMaxValue'] !== null) {
|
||||
$entity->setValueMax((float) $partparameter['normalizedMaxValue']);
|
||||
if ($partparameter['maximumValue'] !== null) {
|
||||
$entity->setValueMax((float) $partparameter['maximumValue'] * $this->getSIPrefixFactor($data, (int) $partparameter['maxSiPrefix_id']));
|
||||
}
|
||||
|
||||
$part = $this->em->find(Part::class, (int) $partparameter['part_id']);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue