Add suite/room/trailer extraction + ID-based class correction
Parser enhancements: - Add SUITE_PATTERNS: extract Suite, Ste, STE (case-insensitive) - Add ROOM_PATTERNS: extract Room, RM, Mailroom, Showroom, etc. - Add TRAILER_PATTERNS: extract Trailer, TRLR, MASH, Safari, etc. - Add _extract_suite(), _extract_room(), _extract_trailer() functions - Update _parse_pattern_a() to extract and strip new fields - Update parse_place() result dict to include suite/room/trailer - Add correct_class_by_machine_id() post-processing: - Bev model in Bev ID range with Snack class → fix to Bev - Unknown class in 9x range → set to Bev - Unknown class in 6x-7x range → set to Snack - Update parse_excel() to include new fields and apply correction DB writer: - Add suite, room, trailer to ALL_COLUMNS and COLUMN_TYPES - Add ALTER TABLE migration for existing databases
This commit is contained in:
+24
-2
@@ -60,7 +60,7 @@ AUTO_FIELDS = {
|
||||
"has_cashless",
|
||||
}
|
||||
|
||||
# All 33 DB columns (Section 11 of the handbook)
|
||||
# All 36 DB columns (Section 11 of the handbook + suite/room/trailer)
|
||||
# machine_id is the primary key — handled separately
|
||||
ALL_COLUMNS = [
|
||||
"machine_id", # preserve — primary key
|
||||
@@ -73,6 +73,9 @@ ALL_COLUMNS = [
|
||||
"company", # auto
|
||||
"place", # auto
|
||||
"building_name", # auto
|
||||
"suite", # auto (new)
|
||||
"room", # auto (new)
|
||||
"trailer", # auto (new)
|
||||
"floor", # auto
|
||||
"zone", # auto
|
||||
"zone_type", # auto
|
||||
@@ -111,6 +114,9 @@ COLUMN_TYPES = {
|
||||
"company": "TEXT",
|
||||
"place": "TEXT",
|
||||
"building_name": "TEXT",
|
||||
"suite": "TEXT",
|
||||
"room": "TEXT",
|
||||
"trailer": "TEXT",
|
||||
"floor": "INTEGER",
|
||||
"zone": "TEXT",
|
||||
"zone_type": "TEXT",
|
||||
@@ -202,7 +208,7 @@ class DatabaseWriter:
|
||||
self.conn.row_factory = sqlite3.Row
|
||||
|
||||
def create_table(self):
|
||||
"""Create the 'assets' table with all columns from Section 11."""
|
||||
"""Create the 'assets' table with all columns from Section 11 + suite/room/trailer."""
|
||||
columns_defs = []
|
||||
for col in ALL_COLUMNS:
|
||||
col_type = COLUMN_TYPES.get(col, "TEXT")
|
||||
@@ -217,6 +223,22 @@ class DatabaseWriter:
|
||||
+ "\n)"
|
||||
)
|
||||
self.conn.execute(create_sql)
|
||||
|
||||
# Migrate existing table: add any missing columns
|
||||
existing_cols = set(
|
||||
r[1] for r in self.conn.execute("PRAGMA table_info(assets)").fetchall()
|
||||
)
|
||||
for col in ALL_COLUMNS + EXTRA_COLUMNS:
|
||||
if col not in existing_cols:
|
||||
col_type = COLUMN_TYPES.get(col, "TEXT")
|
||||
try:
|
||||
self.conn.execute(
|
||||
f'ALTER TABLE assets ADD COLUMN "{col}" {col_type}'
|
||||
)
|
||||
print(f" ➕ Added column: {col} ({col_type})")
|
||||
except Exception as e:
|
||||
print(f" ⚠️ Could not add column {col}: {e}")
|
||||
|
||||
self.conn.commit()
|
||||
|
||||
def _extract_row_values(self, machine):
|
||||
|
||||
Reference in New Issue
Block a user