Fix issues
This commit is contained in:
31
services/data/app/models/sales.py
Normal file
31
services/data/app/models/sales.py
Normal file
@@ -0,0 +1,31 @@
|
||||
# ================================================================
|
||||
# services/data/app/models/sales.py
|
||||
# ================================================================
|
||||
"""Sales data models"""
|
||||
|
||||
from sqlalchemy import Column, String, DateTime, Float, Integer, Text, Index
|
||||
from sqlalchemy.dialects.postgresql import UUID
|
||||
import uuid
|
||||
from datetime import datetime
|
||||
|
||||
from app.core.database import Base
|
||||
|
||||
class SalesData(Base):
|
||||
__tablename__ = "sales_data"
|
||||
|
||||
id = Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
||||
tenant_id = Column(UUID(as_uuid=True), nullable=False, index=True)
|
||||
date = Column(DateTime, nullable=False, index=True)
|
||||
product_name = Column(String(200), nullable=False)
|
||||
quantity_sold = Column(Integer, nullable=False)
|
||||
revenue = Column(Float, nullable=True)
|
||||
location_id = Column(String(100), nullable=True)
|
||||
source = Column(String(50), nullable=False, default="manual") # manual, pos, csv
|
||||
raw_data = Column(Text, nullable=True) # Store original data for debugging
|
||||
created_at = Column(DateTime, default=datetime.utcnow)
|
||||
updated_at = Column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)
|
||||
|
||||
__table_args__ = (
|
||||
Index('idx_sales_tenant_date', 'tenant_id', 'date'),
|
||||
Index('idx_sales_tenant_product', 'tenant_id', 'product_name'),
|
||||
)
|
||||
29
services/data/app/models/traffic.py
Normal file
29
services/data/app/models/traffic.py
Normal file
@@ -0,0 +1,29 @@
|
||||
# ================================================================
|
||||
# services/data/app/models/traffic.py
|
||||
# ================================================================
|
||||
"""Traffic data models"""
|
||||
|
||||
from sqlalchemy import Column, String, DateTime, Float, Integer, Text, Index
|
||||
from sqlalchemy.dialects.postgresql import UUID
|
||||
import uuid
|
||||
from datetime import datetime
|
||||
|
||||
from app.core.database import Base
|
||||
|
||||
class TrafficData(Base):
|
||||
__tablename__ = "traffic_data"
|
||||
|
||||
id = Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
||||
location_id = Column(String(100), nullable=False, index=True)
|
||||
date = Column(DateTime, nullable=False, index=True)
|
||||
traffic_volume = Column(Integer, nullable=True) # vehicles per hour
|
||||
pedestrian_count = Column(Integer, nullable=True) # pedestrians per hour
|
||||
congestion_level = Column(String(20), nullable=True) # low/medium/high
|
||||
average_speed = Column(Float, nullable=True) # km/h
|
||||
source = Column(String(50), nullable=False, default="madrid_opendata")
|
||||
raw_data = Column(Text, nullable=True)
|
||||
created_at = Column(DateTime, default=datetime.utcnow)
|
||||
|
||||
__table_args__ = (
|
||||
Index('idx_traffic_location_date', 'location_id', 'date'),
|
||||
)
|
||||
50
services/data/app/models/weather.py
Normal file
50
services/data/app/models/weather.py
Normal file
@@ -0,0 +1,50 @@
|
||||
# ================================================================
|
||||
# services/data/app/models/weather.py
|
||||
# ================================================================
|
||||
"""Weather data models"""
|
||||
|
||||
from sqlalchemy import Column, String, DateTime, Float, Integer, Text, Index
|
||||
from sqlalchemy.dialects.postgresql import UUID
|
||||
import uuid
|
||||
from datetime import datetime
|
||||
|
||||
from app.core.database import Base
|
||||
|
||||
class WeatherData(Base):
|
||||
__tablename__ = "weather_data"
|
||||
|
||||
id = Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
||||
location_id = Column(String(100), nullable=False, index=True)
|
||||
date = Column(DateTime, nullable=False, index=True)
|
||||
temperature = Column(Float, nullable=True) # Celsius
|
||||
precipitation = Column(Float, nullable=True) # mm
|
||||
humidity = Column(Float, nullable=True) # percentage
|
||||
wind_speed = Column(Float, nullable=True) # km/h
|
||||
pressure = Column(Float, nullable=True) # hPa
|
||||
description = Column(String(200), nullable=True)
|
||||
source = Column(String(50), nullable=False, default="aemet")
|
||||
raw_data = Column(Text, nullable=True)
|
||||
created_at = Column(DateTime, default=datetime.utcnow)
|
||||
|
||||
__table_args__ = (
|
||||
Index('idx_weather_location_date', 'location_id', 'date'),
|
||||
)
|
||||
|
||||
class WeatherForecast(Base):
|
||||
__tablename__ = "weather_forecasts"
|
||||
|
||||
id = Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
||||
location_id = Column(String(100), nullable=False, index=True)
|
||||
forecast_date = Column(DateTime, nullable=False)
|
||||
generated_at = Column(DateTime, nullable=False, default=datetime.utcnow)
|
||||
temperature = Column(Float, nullable=True)
|
||||
precipitation = Column(Float, nullable=True)
|
||||
humidity = Column(Float, nullable=True)
|
||||
wind_speed = Column(Float, nullable=True)
|
||||
description = Column(String(200), nullable=True)
|
||||
source = Column(String(50), nullable=False, default="aemet")
|
||||
raw_data = Column(Text, nullable=True)
|
||||
|
||||
__table_args__ = (
|
||||
Index('idx_forecast_location_date', 'location_id', 'forecast_date'),
|
||||
)
|
||||
Reference in New Issue
Block a user