mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-29 05:00:08 +02:00
Get specifications, mass, footprint and manufacturer status from Octopart
This commit is contained in:
parent
0f336b6f89
commit
d969f49ecc
2 changed files with 73 additions and 8 deletions
|
@ -76,6 +76,8 @@ final class PartInfoRetriever
|
|||
//Generate key and escape reserved characters from the provider id
|
||||
$escaped_keyword = urlencode($keyword) . uniqid();
|
||||
|
||||
dump("Remove the uniqid() from the escaped_part_id variable to use the cache");
|
||||
|
||||
return $this->partInfoCache->get("search_{$provider->getProviderKey()}_{$escaped_keyword}", function (ItemInterface $item) use ($provider, $keyword) {
|
||||
//Set the expiration time
|
||||
$item->expiresAfter(self::CACHE_RESULT_EXPIRATION);
|
||||
|
@ -96,8 +98,9 @@ final class PartInfoRetriever
|
|||
$provider = $this->provider_registry->getProviderByKey($provider_key);
|
||||
|
||||
//Generate key and escape reserved characters from the provider id
|
||||
$escaped_part_id = urlencode($part_id);
|
||||
$escaped_part_id = urlencode($part_id) .uniqid();
|
||||
|
||||
dump("Remove the uniqid() from the escaped_part_id variable to use the cache");
|
||||
|
||||
return $this->partInfoCache->get("details_{$provider_key}_{$escaped_part_id}", function (ItemInterface $item) use ($provider, $part_id) {
|
||||
//Set the expiration time
|
||||
|
|
|
@ -25,6 +25,7 @@ namespace App\Services\InfoProviderSystem\Providers;
|
|||
|
||||
use App\Entity\Parts\ManufacturingStatus;
|
||||
use App\Services\InfoProviderSystem\DTOs\FileDTO;
|
||||
use App\Services\InfoProviderSystem\DTOs\ParameterDTO;
|
||||
use App\Services\InfoProviderSystem\DTOs\PartDetailDTO;
|
||||
use App\Services\OAuth\OAuthTokenManager;
|
||||
use Symfony\Component\HttpClient\HttpOptions;
|
||||
|
@ -58,9 +59,6 @@ class OctopartProvider implements InfoProviderInterface
|
|||
url
|
||||
name
|
||||
}
|
||||
extras {
|
||||
lifeCycle
|
||||
}
|
||||
manufacturerUrl
|
||||
medianPrice1000 {
|
||||
price
|
||||
|
@ -79,6 +77,21 @@ class OctopartProvider implements InfoProviderInterface
|
|||
moq
|
||||
packaging
|
||||
}
|
||||
},
|
||||
specs {
|
||||
attribute {
|
||||
name
|
||||
shortname
|
||||
group
|
||||
id
|
||||
}
|
||||
displayValue
|
||||
value
|
||||
siValue
|
||||
units
|
||||
unitsName
|
||||
unitsSymbol
|
||||
valueType
|
||||
}
|
||||
}
|
||||
GRAPHQL;
|
||||
|
@ -155,8 +168,56 @@ class OctopartProvider implements InfoProviderInterface
|
|||
return true;
|
||||
}
|
||||
|
||||
private function mapLifeCycleStatus(?string $value): ?ManufacturingStatus
|
||||
{
|
||||
return match ($value) {
|
||||
'Production', 'New' => ManufacturingStatus::ACTIVE,
|
||||
'Obsolete' => ManufacturingStatus::DISCONTINUED,
|
||||
'NRND' => ManufacturingStatus::NRFND,
|
||||
'EOL' => ManufacturingStatus::EOL,
|
||||
default => null,
|
||||
};
|
||||
}
|
||||
|
||||
private function partResultToDTO(array $part): PartDetailDTO
|
||||
{
|
||||
//Parse the specifications
|
||||
$parameters = [];
|
||||
$mass = null;
|
||||
$package = null;
|
||||
$pinCount = null;
|
||||
$mStatus = null;
|
||||
foreach ($part['specs'] as $spec) {
|
||||
|
||||
//If we encounter the mass spec, we save it for later
|
||||
if ($spec['attribute']['shortname'] === "weight") {
|
||||
$mass = (float) $spec['siValue'];
|
||||
} else if ($spec['attribute']['shortname'] === "case_package") { //Package
|
||||
$package = $spec['value'];
|
||||
} else if ($spec['attribute']['shortname'] === "numberofpins") { //Pin Count
|
||||
$pinCount = $spec['value'];
|
||||
} else if ($spec['attribute']['shortname'] === "lifecyclestatus") { //LifeCycleStatus
|
||||
$mStatus = $this->mapLifeCycleStatus($spec['value']);
|
||||
}
|
||||
|
||||
$parameters[] = new ParameterDTO(
|
||||
name: $spec['attribute']['name'],
|
||||
value_text: $spec['valueType'] === 'text' ? $spec['value'] : null,
|
||||
value_typ: in_array($spec['valueType'], ['float', 'integer'], true) ? (float) $spec['value'] : null,
|
||||
unit: $spec['valueType'] === 'text' ? null : $spec['units'],
|
||||
group: $spec['attribute']['group'],
|
||||
);
|
||||
}
|
||||
|
||||
//Generate a footprint name from the package and pin count
|
||||
$footprint = null;
|
||||
if ($package !== null) {
|
||||
$footprint = $package;
|
||||
if ($pinCount !== null) { //Add pin count if available
|
||||
$footprint .= '-' . $pinCount;
|
||||
}
|
||||
}
|
||||
|
||||
return new PartDetailDTO(
|
||||
provider_key: $this->getProviderKey(),
|
||||
provider_id: $part['id'],
|
||||
|
@ -166,10 +227,13 @@ class OctopartProvider implements InfoProviderInterface
|
|||
manufacturer: $part['manufacturer']['name'],
|
||||
mpn: $part['mpn'],
|
||||
preview_image_url: $part['bestImage']['url'],
|
||||
manufacturing_status: ManufacturingStatus::NOT_SET, //TODO
|
||||
manufacturing_status: $mStatus,
|
||||
provider_url: $part['octopartUrl'],
|
||||
footprint: $footprint,
|
||||
datasheets: [new FileDTO($part['bestDatasheet']['url'], $part['bestDatasheet']['name'])],
|
||||
manufacturer_product_url: $part['manufacturerUrl'], //TODO
|
||||
parameters: $parameters,
|
||||
mass: $mass,
|
||||
manufacturer_product_url: $part['manufacturerUrl'],
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -217,8 +281,6 @@ class OctopartProvider implements InfoProviderInterface
|
|||
}
|
||||
GRAPHQL, self::GRAPHQL_PART_SECTION);
|
||||
|
||||
dump($graphql);
|
||||
|
||||
$result = $this->makeGraphQLCall($graphql, [
|
||||
'ids' => [$id],
|
||||
]);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue