in agora/cerebral_simulator/src/store_simulator.py [0:0]
def __init__(self):
# Set up logging
logging.basicConfig(level=logging.INFO)
self.logger = logging.getLogger(__name__)
# DEV_MODE
# Load environment variables from .env file
#load_dotenv()
# Load configuration from environment variables
self.EVENTHUB_CONNECTION_STRING = os.getenv('EVENTHUB_CONNECTION_STRING')
self.ORDERS_EVENTHUB_NAME = os.getenv('ORDERS_EVENTHUB_NAME')
self.INVENTORY_EVENTHUB_NAME = os.getenv('INVENTORY_EVENTHUB_NAME')
self.HISTORICAL_DATA_DAYS = (0-int(os.getenv('HISTORICAL_DATA_DAYS', 1)))
self.ORDER_FREQUENCY = int(os.getenv('ORDER_FREQUENCY', 5))
self.PRODUCTS_FILE = os.getenv('PRODUCTS_FILE', 'products.json')
self.SQL_SERVER = os.getenv("SQL_SERVER", "localhost")
self.SQL_DATABASE = os.getenv("SQL_DATABASE", "RetailStore")
self.SQL_USERNAME = os.getenv("SQL_USERNAME", "sa")
self.SQL_PASSWORD = os.getenv("SQL_PASSWORD", "ArcPassword123!!")
self.ENABLE_SQL = os.getenv("ENABLE_SQL", "True").lower() == "true"
self.ENABLE_HISTORICAL = os.getenv("ENABLE_HISTORICAL", "True").lower() == "true"
# MQTT Settings
self.MQTT_BROKER = os.getenv("MQTT_BROKER", "localhost")
self.MQTT_PORT = int(os.getenv("MQTT_PORT", 1883))
# Initialize connections with error handling
self.sql_conn = None
self.mqtt_client = None
self.orders_producer = None
self.inventory_producer = None
# Try to initialize SQL if enabled
if self.ENABLE_SQL:
try:
self.init_database()
except Exception as e:
self.logger.error(f"Failed to initialize SQL connection: {str(e)}")
self.ENABLE_SQL = False
# Try to initialize MQTT
try:
self.init_mqtt()
except Exception as e:
self.logger.error(f"Failed to initialize MQTT connection: {str(e)}")
self.mqtt_client = None
# Try to initialize Event Hub if historical data is enabled
if self.ENABLE_HISTORICAL:
try:
self.init_event_hub()
except Exception as e:
self.logger.error(f"Failed to initialize Event Hub: {str(e)}")
self.ENABLE_HISTORICAL = False
# Initialize store details data structures
self.store_details = [
{ "store_id": "CHI", "city": "Chicago", "state": "IL", "country": "United States" },
{ "store_id": "SEA", "city": "Seattle", "state": "WA", "country": "United States" },
{ "store_id": "NYC", "city": "New York City", "state": "NY", "country": "United States" },
{ "store_id": "DAL", "city": "Dallas", "state": "TX", "country": "United States" },
{ "store_id": "ATL", "city": "Atlanta", "state": "GA", "country": "United States" },
{ "store_id": "LAS", "city": "Las Vegas", "state": "NV", "country": "United States" },
{ "store_id": "MIA", "city": "Miami", "state": "FL", "country": "United States" },
{ "store_id": "LAX", "city": "Los Angeles", "state": "CA", "country": "United States" }
]
self.store_registers = ["R-001", "R-002", "R-003", "R-004", "R-005"]
self.payment_methods = ["credit_card", "cash", "debit_card", "check"]
self.product_discount = [0, 5, 10, 15, 20]
self.products_list = []
self.current_inventory = {}
# Add orders storage
self.recent_orders = []
self.max_orders_history = 100