feat: implemented incremental model for scored products
parent
73df832a6c
commit
c479a66405
|
@ -77,8 +77,8 @@ class UpsertProductsToPg(WriteToPostgreSQL):
|
|||
colnames = ",".join(row.keys())
|
||||
values = ",".join(["%s"] * len(row))
|
||||
sql = f"""
|
||||
INSERT INTO { self.table } ({ colnames })
|
||||
VALUES ({ values })
|
||||
INSERT INTO { self.table } ({ colnames }, ingestion_time)
|
||||
VALUES ({ values }, NOW()::TIMESTAMP)
|
||||
ON CONFLICT ({ self.table_key }) DO UPDATE
|
||||
SET
|
||||
gtin13 = EXCLUDED.gtin13,
|
||||
|
@ -86,7 +86,8 @@ class UpsertProductsToPg(WriteToPostgreSQL):
|
|||
materials = EXCLUDED.materials,
|
||||
packaging = EXCLUDED.packaging,
|
||||
origin = EXCLUDED.origin,
|
||||
weight = EXCLUDED.weight
|
||||
weight = EXCLUDED.weight,
|
||||
ingestion_time = NOW()::TIMESTAMP
|
||||
WHERE
|
||||
{ self.table }.primary_category != EXCLUDED.primary_category OR
|
||||
{ self.table }.materials != EXCLUDED.materials OR
|
||||
|
|
|
@ -21,6 +21,9 @@ class CleanRow(TypedDict):
|
|||
packaging: int
|
||||
origin: str
|
||||
weight: Optional[float]
|
||||
height: Optional[float]
|
||||
width: Optional[float]
|
||||
depth: Optional[float]
|
||||
|
||||
|
||||
def parse_row(element: Dict[str, str]) -> Optional[CleanRow]:
|
||||
|
@ -67,11 +70,13 @@ def parse_row(element: Dict[str, str]) -> Optional[CleanRow]:
|
|||
origin = clean_origin_name(specifications.get("origin"))
|
||||
|
||||
weight = parse_weight(specifications.get("weight"))
|
||||
|
||||
dimensions = parse_dimensions(specifications.get("dimensions"))
|
||||
height = dimensions["height"]
|
||||
width = dimensions["width"]
|
||||
depth = dimensions["depth"]
|
||||
|
||||
if weight is None:
|
||||
dimensions = parse_dimensions(specifications.get("dimensions"))
|
||||
height = dimensions["height"]
|
||||
width = dimensions["width"]
|
||||
depth = dimensions["depth"]
|
||||
weight = dimensional_weight(height=height, width=width, depth=depth)
|
||||
|
||||
return {
|
||||
|
@ -82,4 +87,7 @@ def parse_row(element: Dict[str, str]) -> Optional[CleanRow]:
|
|||
"packaging": packaging,
|
||||
"origin": origin,
|
||||
"weight": weight,
|
||||
"height": height,
|
||||
"width": width,
|
||||
"depth": depth,
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue