-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdummy_data.py
More file actions
56 lines (49 loc) · 2.71 KB
/
dummy_data.py
File metadata and controls
56 lines (49 loc) · 2.71 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
# ------------ dummy_data.py ------------
from singleton_db import Database
from factory import UserFactory, LibraryItemFactory
def generate_dummy_data():
db = Database()
# Create dummy users
users = [
{"name": "John Doe", "role": "student", "id": "s101"},
{"name": "Jane Smith", "role": "faculty", "id": "f201"},
{"name": "Bob Wilson", "role": "researcher", "id": "r301"},
{"name": "Guest User", "role": "guest", "id": "g401"},
{"name": "Alice Brown", "role": "professor", "id": "p501"}
]
for user in users:
new_user = UserFactory.create_user(
role=user["role"],
user_id=user["id"],
name=user["name"]
)
db.add_user(new_user)
# Create dummy items
items = [
{"type": "ebook","item_id": "001", "title": "Python Programming", "author": "Eric Matthes", "format": "PDF", "genre": "Software Engineering"},
{"type": "printed","item_id": "002", "title": "Clean Code", "author": "Robert Martin", "pages": 464, "genre": "Software Engineering"},
{"type": "researchpaper","item_id": "003", "title": "AI Ethics", "author": "AI Research Team"},
{"type": "audiobook", "item_id": "004","title": "Sapiens", "author": "Yuval Harari", "duration": 90},
{"type": "printed","item_id": "005", "title": "The Pragmatic Programmer", "author": "Andrew Hunt", "pages": 352, "genre": "Software Engineering"},
{"type": "printed","item_id": "006", "title": "Thinking, Fast and Slow", "author": "Daniel Kahneman", "pages": 512, "genre": "Psychology"},
{"type": "printed","item_id": "007", "title": "Sapiens: A Brief History of Humankind", "author": "Yuval Noah Harari", "pages": 498, "genre": "History"},
{"type": "printed","item_id": "008", "title": "A Brief History of Time", "author": "Stephen Hawking", "pages": 256, "genre": "Science"},
{"type": "printed","item_id": "009", "title": "To Kill a Mockingbird", "author": "Harper Lee", "pages": 336, "genre": "Literature"}
]
for idx, item in enumerate(items, 1):
try:
new_item = LibraryItemFactory.create_item(
item_type=item["type"],
item_id=item["item_id"],
title=item["title"],
author=item["author"],
**{k:v for k,v in item.items() if k not in ["type","item_id", "title", "author"]}
)
db.add_item(new_item)
except Exception as e:
print(f"Fatal error creating item: {str(e)}")
print("Generated:")
print(f"- {len(users)} users")
print(f"- {len(items)} items")
if __name__ == "__main__":
generate_dummy_data()