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:
2026-04-21 20:53:55 +08:00
parent c5897e5d0d
commit ef449729d7
3 changed files with 22 additions and 4 deletions

12
assets/sandbox.toml Normal file
View 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

View File

@@ -3,7 +3,7 @@ from collections import defaultdict
from datetime import datetime from datetime import datetime
from pathlib import Path 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( def backup_orders(
@@ -28,7 +28,7 @@ def backup_orders(
if order_time < start or order_time >= end: if order_time < start or order_time >= end:
continue continue
date_key = order_time.strftime("%Y-%m-%d") date_key = order_time.strftime("%Y-%m-%d")
by_date[date_key].append(raw_row) by_date[date_key].append(entity)
total = 0 total = 0
for date_key, rows in sorted(by_date.items()): for date_key, rows in sorted(by_date.items()):
@@ -36,7 +36,7 @@ def backup_orders(
with open(csv_path, "w", newline="") as f: with open(csv_path, "w", newline="") as f:
writer = csv.DictWriter(f, fieldnames=CSV_COLUMNS) writer = csv.DictWriter(f, fieldnames=CSV_COLUMNS)
writer.writeheader() writer.writeheader()
writer.writerows(rows) writer.writerows(entity_to_row(r) for r in rows)
total += len(rows) total += len(rows)
print(f" {date_key}: {len(rows)} orders") print(f" {date_key}: {len(rows)} orders")

View File

@@ -43,8 +43,14 @@ def parse_row(raw: dict[str, str]) -> dict[str, Any]:
result[col] = datetime.fromisoformat(val) result[col] = datetime.fromisoformat(val)
elif col in ("revenue", "prodPrice"): elif col in ("revenue", "prodPrice"):
result[col] = float(val) result[col] = float(val)
elif col in ("prodCount", "state", "ver"): elif col in ("prodCount", "ver"):
result[col] = int(val) 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: else:
result[col] = val result[col] = val
return result return result