fix: use entity_to_row for backup CSV output and handle non-numeric state values
Switch backup to write converted entities instead of raw table rows via entity_to_row, and map string state values like "Payed"/"Recived" to their integer equivalents during CSV parsing. Add sandbox.toml config. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
12
assets/sandbox.toml
Normal file
12
assets/sandbox.toml
Normal file
@@ -0,0 +1,12 @@
|
||||
|
||||
[azure]
|
||||
connection_string = "DefaultEndpointsProtocol=https;AccountName=n3ordersmokestorage;AccountKey=aETnv18XBLUDVg7W1fu9ilnKchdLRy2sI2pJJyzqG6R/fqwcnIoSm7eM8ObyXFQAsvZrddZZTBN0+AStnOK/wg==;EndpointSuffix=core.windows.net;"
|
||||
|
||||
[scan]
|
||||
page_size = 500
|
||||
delay_ms = 200
|
||||
scan_dir = "./scan"
|
||||
|
||||
[delete]
|
||||
batch_size = 100
|
||||
delay_ms = 300
|
||||
@@ -3,7 +3,7 @@ from collections import defaultdict
|
||||
from datetime import datetime
|
||||
from pathlib import Path
|
||||
|
||||
from order_bak.csv_utils import CSV_COLUMNS, parse_row
|
||||
from order_bak.csv_utils import CSV_COLUMNS, entity_to_row, parse_row
|
||||
|
||||
|
||||
def backup_orders(
|
||||
@@ -28,7 +28,7 @@ def backup_orders(
|
||||
if order_time < start or order_time >= end:
|
||||
continue
|
||||
date_key = order_time.strftime("%Y-%m-%d")
|
||||
by_date[date_key].append(raw_row)
|
||||
by_date[date_key].append(entity)
|
||||
|
||||
total = 0
|
||||
for date_key, rows in sorted(by_date.items()):
|
||||
@@ -36,7 +36,7 @@ def backup_orders(
|
||||
with open(csv_path, "w", newline="") as f:
|
||||
writer = csv.DictWriter(f, fieldnames=CSV_COLUMNS)
|
||||
writer.writeheader()
|
||||
writer.writerows(rows)
|
||||
writer.writerows(entity_to_row(r) for r in rows)
|
||||
total += len(rows)
|
||||
print(f" {date_key}: {len(rows)} orders")
|
||||
|
||||
|
||||
@@ -43,8 +43,14 @@ def parse_row(raw: dict[str, str]) -> dict[str, Any]:
|
||||
result[col] = datetime.fromisoformat(val)
|
||||
elif col in ("revenue", "prodPrice"):
|
||||
result[col] = float(val)
|
||||
elif col in ("prodCount", "state", "ver"):
|
||||
elif col in ("prodCount", "ver"):
|
||||
result[col] = int(val)
|
||||
elif col == "state":
|
||||
try:
|
||||
result[col] = int(val)
|
||||
except ValueError:
|
||||
_STATE_MAP = {"Payed": 0, "Recived": 1}
|
||||
result[col] = _STATE_MAP.get(val, val)
|
||||
else:
|
||||
result[col] = val
|
||||
return result
|
||||
|
||||
Reference in New Issue
Block a user