-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfaker_custom_provider.py
85 lines (67 loc) · 1.96 KB
/
faker_custom_provider.py
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
from typing import OrderedDict
from faker.providers import BaseProvider
from faker import Faker
class UniversityProvider(BaseProvider):
university_names = [
"Springfield University",
"Shelbyville Institute of Technology",
"Capitol City College",
"Metropolis University",
"Gotham City Academy"
]
faculty_names = [
"Faculty of Engineering",
"Faculty of Arts and Sciences",
"Faculty of Medicine",
"Faculty of Business Administration",
"Faculty of Law"
]
course_titles = [
"Introduction to Artificial Intelligence",
"Advanced Python Programming",
"Quantum Computing 101",
"History of Modern Art",
"Principles of Microeconomics"
]
building_names = [
"Newton Hall",
"Curie Science Center",
"Einstein Library",
"Turing Auditorium",
"Bohr Research Building"
]
grades_name = OrderedDict(
[
("A", 1),
("B", 2),
("C", 5),
("D", 3),
("F", 5)
])
def university_name(self):
return self.random_element(self.university_names)
def faculty_name(self):
return self.random_element(self.faculty_names)
def course_title(self):
return self.random_element(self.course_titles)
def building_name(self):
return self.random_element(self.building_names)
def grades(self, count):
return self.random_elements(self.grades_name, count, unique=False, use_weighting=True)
fake = Faker()
fake.seed_instance(42)
fake.add_provider(UniversityProvider)
# Generate data
print(fake.university_name())
# Springfield University
print(fake.faculty_name())
# Faculty of Medicine
print(fake.course_title())
# Advanced Python Programming
print(fake.building_name())
# Einstein Library
from collections import Counter
for i in range(10):
fake_grades = fake.grades(100)
counter = Counter(fake_grades)
print(counter)