@@ -563,10 +563,22 @@ def insert_inventory(session: Session):
563563 raise
564564
565565
566- def insert_orders_and_items (session : Session , num_orders : int = 100000 ):
566+ def insert_orders_and_items (
567+ session : Session ,
568+ num_orders : int = 100000 ,
569+ start_date : str = "2023-01-01" ,
570+ end_date : str = "2026-12-31" ,
571+ ):
567572 """Insert order and order item data (NO seasonal variations)"""
568573 try :
569- logging .info (f"Generating { num_orders :,} orders..." )
574+ from datetime import datetime
575+
576+ logging .info (f"Generating { num_orders :,} orders from { start_date } to { end_date } ..." )
577+
578+ # Parse date strings
579+ start = datetime .strptime (start_date , "%Y-%m-%d" ).date ()
580+ end = datetime .strptime (end_date , "%Y-%m-%d" ).date ()
581+ date_range_days = (end - start ).days
570582
571583 # Get customers
572584 customer_ids = [c .customer_id for c in session .query (Customer .customer_id ).all ()]
@@ -588,8 +600,9 @@ def insert_orders_and_items(session: Session, num_orders: int = 100000):
588600 for i in range (num_orders ):
589601 customer_id = random .choice (customer_ids )
590602 store_id = random .choice (store_ids )
591- # Random date in last 2 years (NO seasonal variation)
592- order_date = date .today () - timedelta (days = random .randint (0 , 730 ))
603+ # Random date within specified date range
604+ days_offset = random .randint (0 , date_range_days )
605+ order_date = start + timedelta (days = days_offset )
593606
594607 order = Order (customer_id = customer_id , store_id = store_id , order_date = order_date )
595608 order_objects .append (order )
@@ -755,6 +768,8 @@ def main():
755768 parser .add_argument ("--show-stats" , action = "store_true" , help = "Show database statistics" )
756769 parser .add_argument ("--num-customers" , type = int , default = 10000 , help = "Number of customers (default: 10000)" )
757770 parser .add_argument ("--num-orders" , type = int , default = 100000 , help = "Number of orders (default: 100000)" )
771+ parser .add_argument ("--start-date" , type = str , default = "2023-01-01" , help = "Start date for orders (YYYY-MM-DD, default: 2023-01-01)" )
772+ parser .add_argument ("--end-date" , type = str , default = "2026-12-31" , help = "End date for orders (YYYY-MM-DD, default: 2026-12-31)" )
758773
759774 args = parser .parse_args ()
760775
@@ -797,7 +812,7 @@ def main():
797812 # Insert transactional data
798813 insert_customers (session , num_customers = args .num_customers )
799814 insert_inventory (session )
800- insert_orders_and_items (session , num_orders = args .num_orders )
815+ insert_orders_and_items (session , num_orders = args .num_orders , start_date = args . start_date , end_date = args . end_date )
801816
802817 # Insert agent support data
803818 insert_agent_support_data (session )
@@ -807,7 +822,7 @@ def main():
807822
808823 logging .info ("\n ✅ Zava DIY database generation completed successfully!" )
809824 logging .info (f"Database location: { SQLITE_DB_FILE } " )
810- logging .info (f "\n To view statistics: uv run python -m zava_shop_datagenerator --show-stats" )
825+ logging .info ("\n To view statistics: uv run python -m zava_shop_datagenerator --show-stats" )
811826
812827 finally :
813828 session .close ()
0 commit comments