File size: 15,924 Bytes
f525c5f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4bb196e
f525c5f
 
 
 
 
 
4bb196e
f525c5f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4bb196e
 
f525c5f
 
 
 
 
4bb196e
f525c5f
 
 
 
 
 
 
 
 
 
 
 
4bb196e
f525c5f
 
 
 
4bb196e
f525c5f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4bb196e
 
f525c5f
 
 
4bb196e
f525c5f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4bb196e
f525c5f
 
 
 
 
 
4bb196e
f525c5f
 
 
 
 
 
 
 
 
 
 
 
 
 
4bb196e
 
f525c5f
 
 
 
 
4bb196e
f525c5f
 
 
 
 
 
 
 
 
 
 
 
4bb196e
f525c5f
 
 
 
 
 
4bb196e
f525c5f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4bb196e
 
f525c5f
 
 
 
 
4bb196e
f525c5f
 
 
 
 
 
 
 
 
 
 
 
4bb196e
f525c5f
 
 
 
 
 
 
4bb196e
f525c5f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4bb196e
 
f525c5f
 
 
 
 
 
4bb196e
f525c5f
 
 
 
 
 
 
 
 
 
 
 
4bb196e
f525c5f
 
 
 
 
 
 
4bb196e
f525c5f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4bb196e
 
f525c5f
 
 
 
 
 
4bb196e
f525c5f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
"""Mock data generation for customer contract databases."""

import random
import sqlite3
from datetime import datetime, timedelta
from pathlib import Path
from typing import List, Tuple

from schema_translator.config import get_config


class MockDataGenerator:
    """Generates realistic contract databases for multiple customers."""
    
    # Industry variations across customers
    INDUSTRIES = {
        "customer_a": ["Technology", "Healthcare", "Finance", "Manufacturing", "Retail"],
        "customer_b": ["Tech", "Medical", "Financial Services", "Industrial", "E-commerce"],
        "customer_c": ["Information Technology", "Health Services", "Banking", "Manufacturing", "Retail"],
        "customer_d": ["Technology", "Healthcare", "Finance", "Manufacturing", "Retail"],
        "customer_e": ["Tech", "Healthcare", "Financial", "Manufacturing", "Retail"],
        "customer_f": ["Technology", "Medical", "Finance", "Manufacturing", "E-commerce"],
    }
    
    # Company name prefixes/suffixes
    COMPANY_PREFIXES = ["Global", "Premier", "Advanced", "United", "National", "International"]
    COMPANY_CORES = ["Tech", "Systems", "Solutions", "Industries", "Group", "Corp", "Enterprises"]
    COMPANY_SUFFIXES = ["Inc", "LLC", "Ltd", "Corporation", "Partners", "Holdings"]
    
    # Status values
    STATUSES = ["active", "inactive", "expired", "pending"]
    
    def __init__(self):
        """Initialize the mock data generator."""
        self.config = get_config()
        self.config.database_dir.mkdir(parents=True, exist_ok=True)
    
    def generate_company_name(self) -> str:
        """Generate a realistic company name."""
        if random.random() < 0.3:
            # Simple format: "CoreName Suffix"
            return f"{random.choice(self.COMPANY_CORES)} {random.choice(self.COMPANY_SUFFIXES)}"
        else:
            # Full format: "Prefix CoreName Suffix"
            return f"{random.choice(self.COMPANY_PREFIXES)} {random.choice(self.COMPANY_CORES)} {random.choice(self.COMPANY_SUFFIXES)}"
    
    def generate_contract_name(self, contract_id: int) -> str:
        """Generate a contract name/identifier."""
        prefixes = ["CONTRACT", "AGR", "SVC", "MSA", "SOW"]
        return f"{random.choice(prefixes)}-{contract_id:04d}"
    
    def generate_dates(self) -> Tuple[datetime, datetime]:
        """Generate start and expiry dates for a contract.
        
        Returns:
            Tuple of (start_date, expiry_date)
        """
        # Start dates: 1-3 years ago
        days_ago = random.randint(365, 1095)
        start_date = datetime.now() - timedelta(days=days_ago)
        
        # Contract duration: 1-3 years
        contract_duration_days = random.randint(365, 1095)
        expiry_date = start_date + timedelta(days=contract_duration_days)
        
        # Some contracts should be expired (past), some upcoming (future)
        # Mix: 20% expired, 80% active or future
        if random.random() < 0.2:
            # Make it expired (subtract extra time)
            extra_days = random.randint(1, 60)
            expiry_date = datetime.now() - timedelta(days=extra_days)
        
        return start_date, expiry_date
    
    def generate_contract_value(self, is_annual: bool = False) -> int:
        """Generate contract value.
        
        Args:
            is_annual: If True, generate annual value (ARR), else lifetime value
            
        Returns:
            Contract value in dollars
        """
        if is_annual:
            # Annual: $100K - $2M
            return random.randint(100_000, 2_000_000)
        else:
            # Lifetime: $100K - $5M
            return random.randint(100_000, 5_000_000)
    
    def generate_all_databases(self):
        """Generate all 6 customer databases."""
        print("πŸ—οΈ  Generating mock customer databases...\n")
        
        self.generate_customer_a()
        self.generate_customer_b()
        self.generate_customer_c()
        self.generate_customer_d()
        self.generate_customer_e()
        self.generate_customer_f()
        
        print("\nβœ… All databases generated successfully!")
        print(f"πŸ“ Databases located in: {self.config.database_dir}")
    
    def generate_customer_a(self):
        """Generate Customer A: Single table, DATE expiry, LIFETIME contract_value."""
        db_path = self.config.get_database_path("customer_a")
        conn = sqlite3.connect(db_path)
        cursor = conn.cursor()
        
        # Create table (removed customer_name and industry - not in knowledge graph)
        cursor.execute("""
            CREATE TABLE IF NOT EXISTS contracts (
                contract_id INTEGER PRIMARY KEY,
                contract_value INTEGER NOT NULL,
                status TEXT NOT NULL,
                expiry_date TEXT NOT NULL,
                start_date TEXT NOT NULL
            )
        """)
        
        # Generate data
        for i in range(1, 51):
            start_date, expiry_date = self.generate_dates()
            
            # Determine status based on expiry
            if expiry_date < datetime.now():
                status = "expired"
            else:
                status = random.choice(["active", "active", "active", "inactive"])
            
            cursor.execute("""
                INSERT INTO contracts 
                (contract_id, contract_value, status, expiry_date, start_date)
                VALUES (?, ?, ?, ?, ?)
            """, (
                i,
                self.generate_contract_value(is_annual=False),
                status,
                expiry_date.strftime("%Y-%m-%d"),
                start_date.strftime("%Y-%m-%d")
            ))
        
        conn.commit()
        conn.close()
        print(f"βœ“ Customer A: 50 contracts generated ({db_path})")
    
    def generate_customer_b(self):
        """Generate Customer B: Normalized (3 tables), LIFETIME value."""
        db_path = self.config.get_database_path("customer_b")
        conn = sqlite3.connect(db_path)
        cursor = conn.cursor()
        
        # Create tables (removed client_name and sector)
        cursor.execute("""
            CREATE TABLE IF NOT EXISTS contract_headers (
                id INTEGER PRIMARY KEY,
                contract_value INTEGER NOT NULL,
                start_date TEXT NOT NULL
            )
        """)
        
        cursor.execute("""
            CREATE TABLE IF NOT EXISTS contract_status_history (
                id INTEGER PRIMARY KEY AUTOINCREMENT,
                contract_id INTEGER NOT NULL,
                status TEXT NOT NULL,
                status_date TEXT NOT NULL,
                FOREIGN KEY (contract_id) REFERENCES contract_headers(id)
            )
        """)
        
        cursor.execute("""
            CREATE TABLE IF NOT EXISTS renewal_schedule (
                id INTEGER PRIMARY KEY AUTOINCREMENT,
                contract_id INTEGER NOT NULL,
                renewal_date TEXT NOT NULL,
                FOREIGN KEY (contract_id) REFERENCES contract_headers(id)
            )
        """)
        
        # Generate data
        for i in range(1, 51):
            start_date, expiry_date = self.generate_dates()
            
            # Insert header
            cursor.execute("""
                INSERT INTO contract_headers 
                (id, contract_value, start_date)
                VALUES (?, ?, ?)
            """, (
                i,
                self.generate_contract_value(is_annual=False),
                start_date.strftime("%Y-%m-%d")
            ))
            
            # Insert status history (1-3 status changes)
            num_status_changes = random.randint(1, 3)
            current_date = start_date
            for j in range(num_status_changes):
                if j == num_status_changes - 1 and expiry_date < datetime.now():
                    status = "expired"
                    status_date = expiry_date
                else:
                    status = random.choice(["active", "active", "inactive", "pending"])
                    status_date = current_date
                
                cursor.execute("""
                    INSERT INTO contract_status_history 
                    (contract_id, status, status_date)
                    VALUES (?, ?, ?)
                """, (i, status, status_date.strftime("%Y-%m-%d")))
                
                current_date += timedelta(days=random.randint(30, 180))
            
            # Insert renewal date
            cursor.execute("""
                INSERT INTO renewal_schedule (contract_id, renewal_date)
                VALUES (?, ?)
            """, (i, expiry_date.strftime("%Y-%m-%d")))
        
        conn.commit()
        conn.close()
        print(f"βœ“ Customer B: 50 contracts generated with 3 tables ({db_path})")
    
    def generate_customer_c(self):
        """Generate Customer C: Single table, DATE expiry, LIFETIME value, different column names."""
        db_path = self.config.get_database_path("customer_c")
        conn = sqlite3.connect(db_path)
        cursor = conn.cursor()
        
        # Create table with different column names (removed account and business_sector)
        cursor.execute("""
            CREATE TABLE IF NOT EXISTS contracts (
                id INTEGER PRIMARY KEY,
                total_value INTEGER NOT NULL,
                current_status TEXT NOT NULL,
                expiration_date TEXT NOT NULL,
                inception_date TEXT NOT NULL
            )
        """)
        
        # Generate data
        for i in range(1, 51):
            start_date, expiry_date = self.generate_dates()
            
            if expiry_date < datetime.now():
                status = "expired"
            else:
                status = random.choice(["active", "active", "active", "inactive"])
            
            cursor.execute("""
                INSERT INTO contracts 
                (id, total_value, current_status, expiration_date, inception_date)
                VALUES (?, ?, ?, ?, ?)
            """, (
                i,
                self.generate_contract_value(is_annual=False),
                status,
                expiry_date.strftime("%Y-%m-%d"),
                start_date.strftime("%Y-%m-%d")
            ))
        
        conn.commit()
        conn.close()
        print(f"βœ“ Customer C: 50 contracts generated ({db_path})")
    
    def generate_customer_d(self):
        """Generate Customer D: Single table, INTEGER days_remaining, LIFETIME value."""
        db_path = self.config.get_database_path("customer_d")
        conn = sqlite3.connect(db_path)
        cursor = conn.cursor()
        
        # Create table with days_remaining instead of date (removed customer_org and industry)
        cursor.execute("""
            CREATE TABLE IF NOT EXISTS contracts (
                contract_id INTEGER PRIMARY KEY,
                contract_value INTEGER NOT NULL,
                status TEXT NOT NULL,
                days_remaining INTEGER NOT NULL,
                start_date TEXT NOT NULL
            )
        """)
        
        # Generate data
        for i in range(1, 51):
            start_date, expiry_date = self.generate_dates()
            
            # Calculate days remaining from now
            days_remaining = (expiry_date - datetime.now()).days
            
            if days_remaining < 0:
                status = "expired"
            else:
                status = random.choice(["active", "active", "active", "inactive"])
            
            cursor.execute("""
                INSERT INTO contracts 
                (contract_id, contract_value, status, days_remaining, start_date)
                VALUES (?, ?, ?, ?, ?)
            """, (
                i,
                self.generate_contract_value(is_annual=False),
                status,
                days_remaining,
                start_date.strftime("%Y-%m-%d")
            ))
        
        conn.commit()
        conn.close()
        print(f"βœ“ Customer D: 50 contracts generated (using days_remaining) ({db_path})")
    
    def generate_customer_e(self):
        """Generate Customer E: Single table, DATE expiry, LIFETIME value with explicit duration."""
        db_path = self.config.get_database_path("customer_e")
        conn = sqlite3.connect(db_path)
        cursor = conn.cursor()
        
        # Create table (removed customer_name and industry)
        cursor.execute("""
            CREATE TABLE IF NOT EXISTS contracts (
                contract_id INTEGER PRIMARY KEY,
                contract_value INTEGER NOT NULL,
                term_years REAL NOT NULL,
                status TEXT NOT NULL,
                expiry_date TEXT NOT NULL,
                start_date TEXT NOT NULL
            )
        """)
        
        # Generate data
        for i in range(1, 51):
            start_date, expiry_date = self.generate_dates()
            
            # Calculate term in years
            term_days = (expiry_date - start_date).days
            term_years = round(term_days / 365.0, 1)
            
            if expiry_date < datetime.now():
                status = "expired"
            else:
                status = random.choice(["active", "active", "active", "inactive"])
            
            cursor.execute("""
                INSERT INTO contracts 
                (contract_id, contract_value, term_years, status, expiry_date, start_date)
                VALUES (?, ?, ?, ?, ?, ?)
            """, (
                i,
                self.generate_contract_value(is_annual=False),
                term_years,
                status,
                expiry_date.strftime("%Y-%m-%d"),
                start_date.strftime("%Y-%m-%d")
            ))
        
        conn.commit()
        conn.close()
        print(f"βœ“ Customer E: 50 contracts generated ({db_path})")
    
    def generate_customer_f(self):
        """Generate Customer F: Single table, DATE expiry, ANNUAL contract_value (ARR)."""
        db_path = self.config.get_database_path("customer_f")
        conn = sqlite3.connect(db_path)
        cursor = conn.cursor()
        
        # Create table (removed account and sector)
        cursor.execute("""
            CREATE TABLE IF NOT EXISTS contracts (
                contract_id INTEGER PRIMARY KEY,
                contract_value INTEGER NOT NULL,
                term_years REAL NOT NULL,
                status TEXT NOT NULL,
                expiration_date TEXT NOT NULL,
                start_date TEXT NOT NULL
            )
        """)
        
        # Generate data
        for i in range(1, 51):
            start_date, expiry_date = self.generate_dates()
            
            # Calculate term in years
            term_days = (expiry_date - start_date).days
            term_years = round(term_days / 365.0, 1)
            
            if expiry_date < datetime.now():
                status = "expired"
            else:
                status = random.choice(["active", "active", "active", "inactive"])
            
            cursor.execute("""
                INSERT INTO contracts 
                (contract_id, contract_value, term_years, status, expiration_date, start_date)
                VALUES (?, ?, ?, ?, ?, ?)
            """, (
                i,
                self.generate_contract_value(is_annual=True),  # ANNUAL value
                term_years,
                status,
                expiry_date.strftime("%Y-%m-%d"),
                start_date.strftime("%Y-%m-%d")
            ))
        
        conn.commit()
        conn.close()
        print(f"βœ“ Customer F: 50 contracts generated (ANNUAL values) ({db_path})")


def main():
    """Main entry point for generating mock databases."""
    generator = MockDataGenerator()
    generator.generate_all_databases()


if __name__ == "__main__":
    main()