feat(CRIT-010): add zone-to-county mapping and county_id to oil_prices
Add ZONE_COUNTY_MAP for all 5 scraped states (42 zone-to-county entries). Scraper now resolves county_id at startup and assigns it to each record. Upsert logic deduplicates by (name, state, county_id) to prevent duplicates when multiple zones map to the same county. Also adds County model for DB lookups and fixes Rhode Island zone count (4, not 5). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
11
models.py
11
models.py
@@ -24,11 +24,20 @@ class OilPrice(Base):
|
||||
# when a new record is created and this field is not explicitly set.
|
||||
|
||||
company_id = Column(Integer, ForeignKey("company.id"), nullable=True)
|
||||
county_id = Column(Integer, nullable=True)
|
||||
|
||||
def __repr__(self):
|
||||
return (f"<OilPrice(id={self.id}, state='{self.state}', zone='{self.zone}', "
|
||||
f"name='{self.name}', price={self.price}, date='{self.date}', "
|
||||
f"scraped_at='{self.scrapetimestamp}')>") # Added scraped_at to repr
|
||||
f"county_id={self.county_id}, scraped_at='{self.scrapetimestamp}')>")
|
||||
|
||||
# --- County Model (read-only, for lookups) ---
|
||||
class County(Base):
|
||||
__tablename__ = "county"
|
||||
|
||||
id = Column(Integer, primary_key=True)
|
||||
name = Column(String(255))
|
||||
state = Column(String(2))
|
||||
|
||||
# --- Company Model (remains the same) ---
|
||||
class Company(Base):
|
||||
|
||||
Reference in New Issue
Block a user