Major update spanning pricing, market data, and analytics: - Pricing: Replace single-price service fees with 5-tier pricing for same-day, prime, and emergency deliveries across create/edit/finalize - Market: Add Ticker_Price and CompanyPrice models with endpoints for live commodity prices (HO, CL, RB) and competitor price tracking - Stats: Add daily/weekly/monthly gallons endpoints with multi-year comparison and YoY totals for the stats dashboard - Delivery: Add map and history endpoints, fix finalize null-driver crash - Schema: Change fill_location from INTEGER to VARCHAR(250), add pre_load normalization for customer updates, fix admin auth check Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
29 lines
1.2 KiB
Python
29 lines
1.2 KiB
Python
from datetime import datetime
|
|
from app import db, ma
|
|
|
|
class Ticker_Price(db.Model):
|
|
__tablename__ = 'ticker_prices'
|
|
__table_args__ = {"schema": "public"}
|
|
|
|
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
|
|
symbol = db.Column(db.String(20), nullable=False, index=True)
|
|
price_decimal = db.Column(db.Numeric(10, 4), nullable=False)
|
|
currency = db.Column(db.String(10), nullable=True)
|
|
change_decimal = db.Column(db.Numeric(10, 4), nullable=True)
|
|
percent_change_decimal = db.Column(db.Numeric(10, 4), nullable=True)
|
|
timestamp = db.Column(db.TIMESTAMP(), default=datetime.utcnow, index=True)
|
|
|
|
def to_dict(self):
|
|
return {
|
|
"symbol": self.symbol,
|
|
"price": float(self.price_decimal) if self.price_decimal is not None else None,
|
|
"currency": self.currency,
|
|
"change": float(self.change_decimal) if self.change_decimal is not None else None,
|
|
"percent_change": float(self.percent_change_decimal) if self.percent_change_decimal is not None else None,
|
|
"timestamp": self.timestamp.isoformat() if self.timestamp else None,
|
|
}
|
|
|
|
class Ticker_Price_Schema(ma.SQLAlchemyAutoSchema):
|
|
class Meta:
|
|
model = Ticker_Price
|