-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsample_data.py
More file actions
224 lines (194 loc) · 8.03 KB
/
Copy pathsample_data.py
File metadata and controls
224 lines (194 loc) · 8.03 KB
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
"""
Sample Data Generator for MultiAgent Platform
Run this script to populate your database with sample transactions and tasks
"""
from app import app, db, User, UserProfile, Transaction, Task
from datetime import datetime, timedelta
import random
def create_sample_user():
"""Create a sample user for testing"""
with app.app_context():
# Check if sample user exists
user = User.query.filter_by(email='demo@multiagent.com').first()
if user:
print("Sample user already exists!")
return user
# Create new sample user
user = User(
email='demo@multiagent.com',
password='demo123', # In production, hash this!
name='Demo User'
)
db.session.add(user)
db.session.commit()
# Create user profile
profile = UserProfile(
user_id=user.id,
employment_type='gig',
monthly_income_range='3000-5000',
financial_goals='Save for emergency fund, reduce debt, invest for retirement',
risk_tolerance='moderate'
)
db.session.add(profile)
db.session.commit()
print(f"✓ Created sample user: {user.email}")
print(f" Password: demo123")
return user
def create_sample_transactions(user_id):
"""Create sample transactions for the past 3 months"""
with app.app_context():
# Check if transactions already exist
existing = Transaction.query.filter_by(user_id=user_id).count()
if existing > 0:
print(f"User already has {existing} transactions!")
return
categories = {
'income': ['Salary', 'Freelance', 'Side Gig', 'Bonus'],
'expense': [
'Food & Dining', 'Transportation', 'Housing', 'Utilities',
'Entertainment', 'Healthcare', 'Shopping', 'Insurance',
'Debt Payment', 'Groceries'
]
}
transactions = []
start_date = datetime.now() - timedelta(days=90)
# Generate income transactions (2-4 per month)
for month in range(3):
month_start = start_date + timedelta(days=month * 30)
income_count = random.randint(2, 4)
for _ in range(income_count):
transaction = Transaction(
user_id=user_id,
amount=random.uniform(800, 2500),
category=random.choice(categories['income']),
description=f"Income payment",
transaction_type='income',
date=month_start + timedelta(days=random.randint(0, 28))
)
transactions.append(transaction)
# Generate expense transactions (30-50 per month)
for month in range(3):
month_start = start_date + timedelta(days=month * 30)
expense_count = random.randint(30, 50)
for _ in range(expense_count):
category = random.choice(categories['expense'])
# Different amount ranges for different categories
if category == 'Housing':
amount = random.uniform(800, 1200)
elif category in ['Utilities', 'Insurance']:
amount = random.uniform(50, 200)
elif category == 'Groceries':
amount = random.uniform(30, 150)
elif category == 'Food & Dining':
amount = random.uniform(10, 80)
elif category == 'Transportation':
amount = random.uniform(20, 100)
else:
amount = random.uniform(15, 200)
transaction = Transaction(
user_id=user_id,
amount=amount,
category=category,
description=f"{category} expense",
transaction_type='expense',
date=month_start + timedelta(days=random.randint(0, 28))
)
transactions.append(transaction)
# Add all transactions
db.session.bulk_save_objects(transactions)
db.session.commit()
print(f"✓ Created {len(transactions)} sample transactions")
print(f" Income transactions: {sum(1 for t in transactions if t.transaction_type == 'income')}")
print(f" Expense transactions: {sum(1 for t in transactions if t.transaction_type == 'expense')}")
def create_sample_tasks(user_id):
"""Create sample tasks"""
with app.app_context():
# Check if tasks already exist
existing = Task.query.filter_by(user_id=user_id).count()
if existing > 0:
print(f"User already has {existing} tasks!")
return
sample_tasks = [
{
'title': 'Analyze my spending patterns',
'description': 'Review my expenses and identify areas where I can save money',
'agent_type': 'financial',
'task_type': 'spending_analysis',
'priority': 'high'
},
{
'title': 'Create a monthly budget',
'description': 'Help me create a realistic budget based on my income and expenses',
'agent_type': 'financial',
'task_type': 'budget_planning',
'priority': 'high'
},
{
'title': 'Research investment options',
'description': 'Find suitable investment opportunities for my risk tolerance',
'agent_type': 'research',
'task_type': 'market_research',
'priority': 'medium'
},
{
'title': 'Optimize my daily schedule',
'description': 'Help me manage my time more effectively',
'agent_type': 'productivity',
'task_type': 'schedule_optimization',
'priority': 'medium'
},
{
'title': 'Learn about personal finance',
'description': 'Create a learning path for improving my financial literacy',
'agent_type': 'learning',
'task_type': 'learning_path',
'priority': 'low'
}
]
tasks = []
for task_data in sample_tasks:
task = Task(
user_id=user_id,
title=task_data['title'],
description=task_data['description'],
agent_type=task_data['agent_type'],
task_type=task_data['task_type'],
priority=task_data['priority'],
status='pending'
)
tasks.append(task)
db.session.bulk_save_objects(tasks)
db.session.commit()
print(f"✓ Created {len(tasks)} sample tasks")
def main():
"""Main function to generate all sample data"""
print("\n" + "="*50)
print(" MultiAgent Sample Data Generator")
print("="*50 + "\n")
try:
# Create database tables if they don't exist
with app.app_context():
db.create_all()
print("✓ Database tables ready\n")
# Create sample user
user = create_sample_user()
print()
# Create sample transactions
create_sample_transactions(user.id)
print()
# Create sample tasks
create_sample_tasks(user.id)
print()
print("="*50)
print(" Sample Data Created Successfully!")
print("="*50)
print("\nYou can now login with:")
print(" Email: demo@multiagent.com")
print(" Password: demo123")
print("\nStart the application with: python app.py")
print()
except Exception as e:
print(f"\n❌ Error: {e}")
print("Make sure the database is properly configured.")
if __name__ == '__main__':
main()