File size: 1,819 Bytes
eff8aa5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import sqlite3
import pandas as pd
import random
from datetime import datetime, timedelta

def create_dummy_db():
    conn = sqlite3.connect('test.db')
    cursor = conn.cursor()
    
    # Create Sales Table
    cursor.execute('''
    CREATE TABLE IF NOT EXISTS sales (
        id INTEGER PRIMARY KEY AUTOINCREMENT,
        date DATE,
        product_category TEXT,
        product_name TEXT,
        quantity INTEGER,
        unit_price REAL,
        total_amount REAL,
        region TEXT
    )
    ''')
    
    # Generate sample data
    categories = ['Electronics', 'Clothing', 'Home', 'Books']
    products = {
        'Electronics': ['Laptop', 'Smartphone', 'Headphones', 'Monitor'],
        'Clothing': ['T-Shirt', 'Jeans', 'Jacket', 'Sneakers'],
        'Home': ['Sofa', 'Table', 'Lamp', 'Rug'],
        'Books': ['Fiction', 'Non-Fiction', 'Sci-Fi', 'Biography']
    }
    regions = ['North', 'South', 'East', 'West']
    
    data = []
    start_date = datetime(2023, 1, 1)
    for i in range(100):
        date = start_date + timedelta(days=random.randint(0, 365))
        category = random.choice(categories)
        product = random.choice(products[category])
        quantity = random.randint(1, 5)
        unit_price = round(random.uniform(10.0, 1000.0), 2)
        total_amount = round(quantity * unit_price, 2)
        region = random.choice(regions)
        
        data.append((date.strftime('%Y-%m-%d'), category, product, quantity, unit_price, total_amount, region))
        
    cursor.executemany('''
    INSERT INTO sales (date, product_category, product_name, quantity, unit_price, total_amount, region)
    VALUES (?, ?, ?, ?, ?, ?, ?)
    ''', data)
    
    conn.commit()
    conn.close()
    print("Dummy database created successfully.")

if __name__ == "__main__":
    create_dummy_db()