data-seed-ph 3.2.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data_seed_ph-3.2.1/LICENSE +21 -0
- data_seed_ph-3.2.1/MANIFEST.in +3 -0
- data_seed_ph-3.2.1/PKG-INFO +38 -0
- data_seed_ph-3.2.1/README.md +13 -0
- data_seed_ph-3.2.1/data_seed_ph.egg-info/PKG-INFO +38 -0
- data_seed_ph-3.2.1/data_seed_ph.egg-info/SOURCES.txt +27 -0
- data_seed_ph-3.2.1/data_seed_ph.egg-info/dependency_links.txt +1 -0
- data_seed_ph-3.2.1/data_seed_ph.egg-info/requires.txt +7 -0
- data_seed_ph-3.2.1/data_seed_ph.egg-info/top_level.txt +1 -0
- data_seed_ph-3.2.1/pyproject.toml +46 -0
- data_seed_ph-3.2.1/seed/__init__.py +15 -0
- data_seed_ph-3.2.1/seed/core.py +191 -0
- data_seed_ph-3.2.1/seed/exports/__init__.py +3 -0
- data_seed_ph-3.2.1/seed/exports/exporter.py +117 -0
- data_seed_ph-3.2.1/seed/providers/__init__.py +3 -0
- data_seed_ph-3.2.1/seed/providers/data/domains.json +9 -0
- data_seed_ph-3.2.1/seed/providers/data/educations.json +64 -0
- data_seed_ph-3.2.1/seed/providers/data/first_names.json +35 -0
- data_seed_ph-3.2.1/seed/providers/data/last_names.json +23 -0
- data_seed_ph-3.2.1/seed/providers/data/luzon_locations.json +22080 -0
- data_seed_ph-3.2.1/seed/providers/data/mindanao_locations.json +11999 -0
- data_seed_ph-3.2.1/seed/providers/data/preferences.json +69 -0
- data_seed_ph-3.2.1/seed/providers/data/source.md +12 -0
- data_seed_ph-3.2.1/seed/providers/data/visayas_locations.json +13183 -0
- data_seed_ph-3.2.1/seed/providers/data_provider.py +358 -0
- data_seed_ph-3.2.1/setup.cfg +4 -0
- data_seed_ph-3.2.1/tests/test_core.py +186 -0
- data_seed_ph-3.2.1/tests/test_exporter.py +75 -0
- data_seed_ph-3.2.1/tests/test_providers.py +258 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Christian Garcia
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: data-seed-ph
|
|
3
|
+
Version: 3.2.1
|
|
4
|
+
Summary: A Python library for generating realistic, synthetic Philippine-based datasets.
|
|
5
|
+
Author-email: "Christian G. Garcia" <iyaniyan03112003@gmail.com>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/christiangarcia0311/data-seed-ph
|
|
8
|
+
Project-URL: Repository, https://github.com/christiangarcia0311/data-seed-ph.git
|
|
9
|
+
Keywords: synthetic-data,seeding,testing,philipine-based-data,datasets
|
|
10
|
+
Classifier: Development Status :: 4 - Beta
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
15
|
+
Requires-Python: >=3.9
|
|
16
|
+
Description-Content-Type: text/markdown
|
|
17
|
+
License-File: LICENSE
|
|
18
|
+
Requires-Dist: pandas
|
|
19
|
+
Requires-Dist: numpy
|
|
20
|
+
Requires-Dist: sqlalchemy
|
|
21
|
+
Provides-Extra: dev
|
|
22
|
+
Requires-Dist: pytest>=7.0; extra == "dev"
|
|
23
|
+
Requires-Dist: pytest-cov>=4.0; extra == "dev"
|
|
24
|
+
Dynamic: license-file
|
|
25
|
+
|
|
26
|
+
## Data Seed PH
|
|
27
|
+
|
|
28
|
+
[](https://github.com/christiangarcia0311/data-seed-ph/stargazers)
|
|
29
|
+

|
|
30
|
+

|
|
31
|
+

|
|
32
|
+

|
|
33
|
+
|
|
34
|
+
**A Python library for generating realistic, synthetic Philippine-based datasets.**
|
|
35
|
+
|
|
36
|
+
> Designed for database seeding, API testing, machine learning dataset generation, academic research, and software development prototyping with support for CSV, JSON and SQL export formats.
|
|
37
|
+
|
|
38
|
+
View full documentation: [Github](https://github.com/christiangarcia0311/data-seed-ph)
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
## Data Seed PH
|
|
2
|
+
|
|
3
|
+
[](https://github.com/christiangarcia0311/data-seed-ph/stargazers)
|
|
4
|
+

|
|
5
|
+

|
|
6
|
+

|
|
7
|
+

|
|
8
|
+
|
|
9
|
+
**A Python library for generating realistic, synthetic Philippine-based datasets.**
|
|
10
|
+
|
|
11
|
+
> Designed for database seeding, API testing, machine learning dataset generation, academic research, and software development prototyping with support for CSV, JSON and SQL export formats.
|
|
12
|
+
|
|
13
|
+
View full documentation: [Github](https://github.com/christiangarcia0311/data-seed-ph)
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: data-seed-ph
|
|
3
|
+
Version: 3.2.1
|
|
4
|
+
Summary: A Python library for generating realistic, synthetic Philippine-based datasets.
|
|
5
|
+
Author-email: "Christian G. Garcia" <iyaniyan03112003@gmail.com>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/christiangarcia0311/data-seed-ph
|
|
8
|
+
Project-URL: Repository, https://github.com/christiangarcia0311/data-seed-ph.git
|
|
9
|
+
Keywords: synthetic-data,seeding,testing,philipine-based-data,datasets
|
|
10
|
+
Classifier: Development Status :: 4 - Beta
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
15
|
+
Requires-Python: >=3.9
|
|
16
|
+
Description-Content-Type: text/markdown
|
|
17
|
+
License-File: LICENSE
|
|
18
|
+
Requires-Dist: pandas
|
|
19
|
+
Requires-Dist: numpy
|
|
20
|
+
Requires-Dist: sqlalchemy
|
|
21
|
+
Provides-Extra: dev
|
|
22
|
+
Requires-Dist: pytest>=7.0; extra == "dev"
|
|
23
|
+
Requires-Dist: pytest-cov>=4.0; extra == "dev"
|
|
24
|
+
Dynamic: license-file
|
|
25
|
+
|
|
26
|
+
## Data Seed PH
|
|
27
|
+
|
|
28
|
+
[](https://github.com/christiangarcia0311/data-seed-ph/stargazers)
|
|
29
|
+

|
|
30
|
+

|
|
31
|
+

|
|
32
|
+

|
|
33
|
+
|
|
34
|
+
**A Python library for generating realistic, synthetic Philippine-based datasets.**
|
|
35
|
+
|
|
36
|
+
> Designed for database seeding, API testing, machine learning dataset generation, academic research, and software development prototyping with support for CSV, JSON and SQL export formats.
|
|
37
|
+
|
|
38
|
+
View full documentation: [Github](https://github.com/christiangarcia0311/data-seed-ph)
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
MANIFEST.in
|
|
3
|
+
README.md
|
|
4
|
+
pyproject.toml
|
|
5
|
+
data_seed_ph.egg-info/PKG-INFO
|
|
6
|
+
data_seed_ph.egg-info/SOURCES.txt
|
|
7
|
+
data_seed_ph.egg-info/dependency_links.txt
|
|
8
|
+
data_seed_ph.egg-info/requires.txt
|
|
9
|
+
data_seed_ph.egg-info/top_level.txt
|
|
10
|
+
seed/__init__.py
|
|
11
|
+
seed/core.py
|
|
12
|
+
seed/exports/__init__.py
|
|
13
|
+
seed/exports/exporter.py
|
|
14
|
+
seed/providers/__init__.py
|
|
15
|
+
seed/providers/data_provider.py
|
|
16
|
+
seed/providers/data/domains.json
|
|
17
|
+
seed/providers/data/educations.json
|
|
18
|
+
seed/providers/data/first_names.json
|
|
19
|
+
seed/providers/data/last_names.json
|
|
20
|
+
seed/providers/data/luzon_locations.json
|
|
21
|
+
seed/providers/data/mindanao_locations.json
|
|
22
|
+
seed/providers/data/preferences.json
|
|
23
|
+
seed/providers/data/source.md
|
|
24
|
+
seed/providers/data/visayas_locations.json
|
|
25
|
+
tests/test_core.py
|
|
26
|
+
tests/test_exporter.py
|
|
27
|
+
tests/test_providers.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
seed
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61.0", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "data-seed-ph"
|
|
7
|
+
version = "3.2.1"
|
|
8
|
+
description = "A Python library for generating realistic, synthetic Philippine-based datasets."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.9"
|
|
11
|
+
license = "MIT"
|
|
12
|
+
authors = [{name = "Christian G. Garcia", email = "iyaniyan03112003@gmail.com"}]
|
|
13
|
+
dependencies = [
|
|
14
|
+
"pandas",
|
|
15
|
+
"numpy",
|
|
16
|
+
"sqlalchemy",
|
|
17
|
+
]
|
|
18
|
+
keywords = ["synthetic-data", "seeding", "testing", "philipine-based-data", "datasets"]
|
|
19
|
+
classifiers = [
|
|
20
|
+
"Development Status :: 4 - Beta",
|
|
21
|
+
"Intended Audience :: Developers",
|
|
22
|
+
"Programming Language :: Python :: 3.9",
|
|
23
|
+
"Programming Language :: Python :: 3.10",
|
|
24
|
+
"Programming Language :: Python :: 3.11",
|
|
25
|
+
]
|
|
26
|
+
|
|
27
|
+
[project.optional-dependencies]
|
|
28
|
+
dev = [
|
|
29
|
+
"pytest>=7.0",
|
|
30
|
+
"pytest-cov>=4.0",
|
|
31
|
+
]
|
|
32
|
+
|
|
33
|
+
[project.urls]
|
|
34
|
+
Homepage = "https://github.com/christiangarcia0311/data-seed-ph"
|
|
35
|
+
Repository = "https://github.com/christiangarcia0311/data-seed-ph.git"
|
|
36
|
+
|
|
37
|
+
[tool.pytest.ini_options]
|
|
38
|
+
testpaths = ["tests"]
|
|
39
|
+
python_files = ["test_*.py"]
|
|
40
|
+
python_classes = ["Test*"]
|
|
41
|
+
python_functions = ["test_*"]
|
|
42
|
+
|
|
43
|
+
[tool.setuptools.packages.find]
|
|
44
|
+
where = ["."]
|
|
45
|
+
include = ["seed*"]
|
|
46
|
+
exclude = ["tests*"]
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
'''
|
|
2
|
+
Data Seed PH
|
|
3
|
+
-------------
|
|
4
|
+
A Python library for generating realistic, synthetic Philippine-based datasets
|
|
5
|
+
|
|
6
|
+
Information
|
|
7
|
+
-----------
|
|
8
|
+
@author: Christian Garcia
|
|
9
|
+
@github: github.com/christiangarcia0311/data-seed-ph
|
|
10
|
+
'''
|
|
11
|
+
|
|
12
|
+
from .core import Dataset
|
|
13
|
+
|
|
14
|
+
__version__ = '3.2.1'
|
|
15
|
+
__all__ = ['Dataset']
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
'''
|
|
2
|
+
Core Module
|
|
3
|
+
|
|
4
|
+
This module is responsible for generating synthetic datasets using
|
|
5
|
+
different data providers such as personal information, address data,
|
|
6
|
+
contact details and education information. It acts as the core interface for assembling mock
|
|
7
|
+
datasets and exporting them into different formats.
|
|
8
|
+
|
|
9
|
+
The dataset generator allows developers to define:
|
|
10
|
+
- number of rows to generate
|
|
11
|
+
- data features/fields to include
|
|
12
|
+
- output format (CSV, JSON, SQL)
|
|
13
|
+
|
|
14
|
+
Notes
|
|
15
|
+
-----
|
|
16
|
+
All generated data is synthetic and intended strictly for development,
|
|
17
|
+
testing, research, and educational purposes.
|
|
18
|
+
|
|
19
|
+
Information
|
|
20
|
+
-----------
|
|
21
|
+
@author: Christian Garcia
|
|
22
|
+
@github: github.com/christiangarcia0311/data-seed-ph
|
|
23
|
+
'''
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
from exports.exporter import SaveData
|
|
27
|
+
from providers.data_provider import (
|
|
28
|
+
PersonalDataProvider,
|
|
29
|
+
AddressDataProvider,
|
|
30
|
+
ContactDataProvider,
|
|
31
|
+
EducationDataProvider
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
import pandas as pd
|
|
35
|
+
import numpy as np
|
|
36
|
+
import random as rd
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
class Data:
|
|
41
|
+
|
|
42
|
+
def __init__(self):
|
|
43
|
+
self.personal = PersonalDataProvider()
|
|
44
|
+
self.address = AddressDataProvider()
|
|
45
|
+
self.contact = ContactDataProvider(self.personal)
|
|
46
|
+
self.education = EducationDataProvider()
|
|
47
|
+
|
|
48
|
+
class Dataset:
|
|
49
|
+
|
|
50
|
+
def __init__(self):
|
|
51
|
+
self.export = SaveData()
|
|
52
|
+
self.data = Data()
|
|
53
|
+
self.dump = {}
|
|
54
|
+
|
|
55
|
+
self.data_map = {
|
|
56
|
+
# Personal data
|
|
57
|
+
'firstname': lambda: self.data.personal.firstname(),
|
|
58
|
+
'lastname': lambda: self.data.personal.lastname(),
|
|
59
|
+
'suffixname': lambda: self.data.personal.suffix(),
|
|
60
|
+
'fullname': lambda: self.data.personal.fullname(),
|
|
61
|
+
'malename': lambda: self.data.personal.firstname(gender='male'),
|
|
62
|
+
'femalename': lambda: self.data.personal.firstname(gender='female'),
|
|
63
|
+
'gender': lambda: self.data.personal.gender(),
|
|
64
|
+
'birthdate': lambda: self.data.personal.birthdate(),
|
|
65
|
+
'age': lambda: self.data.personal.age(),
|
|
66
|
+
'civil': lambda: self.data.personal.civil(),
|
|
67
|
+
'religion': lambda: self.data.personal.religion(),
|
|
68
|
+
'bloodtype': lambda: self.data.personal.blood_type(),
|
|
69
|
+
'nationality': lambda: self.data.personal.nationality(),
|
|
70
|
+
|
|
71
|
+
# Address data
|
|
72
|
+
'region': lambda: self.data.address.region(),
|
|
73
|
+
'luzon': lambda: self.data.address.region('luzon'),
|
|
74
|
+
'visayas': lambda: self.data.address.region('visayas'),
|
|
75
|
+
'mindanao': lambda: self.data.address.region('mindanao'),
|
|
76
|
+
'province': lambda: self.data.address.province(),
|
|
77
|
+
'city': lambda: self.data.address.city(),
|
|
78
|
+
'municipality': lambda: self.data.address.municipality(),
|
|
79
|
+
'barangay': lambda: self.data.address.barangay(),
|
|
80
|
+
'fulladdress': lambda: self.data.address.full_address(),
|
|
81
|
+
|
|
82
|
+
# Contact data
|
|
83
|
+
'mobile': lambda: self.data.contact.mobile(),
|
|
84
|
+
'mobile_int': lambda: self.data.contact.mobile('international'),
|
|
85
|
+
'email': lambda: self.data.contact.email(),
|
|
86
|
+
|
|
87
|
+
# Education data
|
|
88
|
+
'course': lambda: self.data.education.course(),
|
|
89
|
+
'strand': lambda: self.data.education.strand()
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
def generate(self, rows: int, features: dict) -> pd.DataFrame:
|
|
93
|
+
self.dump = {feature: [] for feature in features}
|
|
94
|
+
|
|
95
|
+
for _ in range(rows):
|
|
96
|
+
for feature, value in features.items():
|
|
97
|
+
if isinstance(value, str):
|
|
98
|
+
key = value.lower()
|
|
99
|
+
|
|
100
|
+
if ':' in key:
|
|
101
|
+
keyword, param = value.split(':', 1)
|
|
102
|
+
keyword = keyword.strip().lower()
|
|
103
|
+
param = param.strip()
|
|
104
|
+
|
|
105
|
+
if keyword == 'province':
|
|
106
|
+
self.dump[feature].append(self.data.address.province(param))
|
|
107
|
+
elif keyword == 'city':
|
|
108
|
+
self.dump[feature].append(self.data.address.city(param))
|
|
109
|
+
elif keyword == 'municipality':
|
|
110
|
+
self.dump[feature].append(self.data.address.municipality(param))
|
|
111
|
+
else:
|
|
112
|
+
raise ValueError(f'Unknown parameterized keyword: {keyword}')
|
|
113
|
+
|
|
114
|
+
elif key in self.data_map:
|
|
115
|
+
self.dump[feature].append(self.data_map[key]())
|
|
116
|
+
|
|
117
|
+
else:
|
|
118
|
+
raise ValueError(f'Unknown feature keyword: {value}')
|
|
119
|
+
|
|
120
|
+
elif isinstance(value, tuple):
|
|
121
|
+
min_value, max_value = value[0], value[1]
|
|
122
|
+
if len(value) == 3 and value[2] == 'float':
|
|
123
|
+
self.dump[feature].append(round(float(np.random.uniform(min_value, max_value)), 2))
|
|
124
|
+
else:
|
|
125
|
+
self.dump[feature].append(int(np.random.randint(min_value, max_value + 1)))
|
|
126
|
+
|
|
127
|
+
elif isinstance(value, list):
|
|
128
|
+
self.dump[feature].append(rd.choice(value))
|
|
129
|
+
|
|
130
|
+
else:
|
|
131
|
+
raise ValueError('Feature values must be a tuple for numerical ranges or a list for categorical values.')
|
|
132
|
+
|
|
133
|
+
return pd.DataFrame(self.dump)
|
|
134
|
+
|
|
135
|
+
def save(
|
|
136
|
+
self,
|
|
137
|
+
data: dict,
|
|
138
|
+
filename: str,
|
|
139
|
+
format: str,
|
|
140
|
+
table_name: str = 'seeds',
|
|
141
|
+
database_type: str = 'sqlite',
|
|
142
|
+
database_name: str = 'data_seed.db',
|
|
143
|
+
username: str = None,
|
|
144
|
+
password: str = None,
|
|
145
|
+
host: str = 'localhost',
|
|
146
|
+
port: int = None,
|
|
147
|
+
if_exist: str = 'fail',
|
|
148
|
+
primary_key: str = 'id',
|
|
149
|
+
indexes: bool = False
|
|
150
|
+
):
|
|
151
|
+
match (format.lower()):
|
|
152
|
+
case 'csv':
|
|
153
|
+
self.export.to_csv(data=data, filename=f'{filename}.{format}')
|
|
154
|
+
case 'json':
|
|
155
|
+
self.export.to_json(data=data, filename=f'{filename}.{format}')
|
|
156
|
+
case 'sql':
|
|
157
|
+
if database_type.lower() == 'sqlite':
|
|
158
|
+
self.export.to_sql(
|
|
159
|
+
data=data,
|
|
160
|
+
table_name=table_name,
|
|
161
|
+
database_type=database_type,
|
|
162
|
+
database_name=database_name,
|
|
163
|
+
if_exist=if_exist,
|
|
164
|
+
primary_key=primary_key,
|
|
165
|
+
indexes=indexes
|
|
166
|
+
)
|
|
167
|
+
elif database_type.lower() == 'mysql':
|
|
168
|
+
self.export.to_sql(
|
|
169
|
+
data=data,
|
|
170
|
+
table_name=table_name,
|
|
171
|
+
database_type=database_type,
|
|
172
|
+
database_name=database_name,
|
|
173
|
+
username=username,
|
|
174
|
+
password=password,
|
|
175
|
+
host=host,
|
|
176
|
+
port=port,
|
|
177
|
+
if_exist=if_exist,
|
|
178
|
+
primary_key=primary_key,
|
|
179
|
+
indexes=indexes
|
|
180
|
+
)
|
|
181
|
+
else:
|
|
182
|
+
raise ValueError(f'Unsupported database type: {database_type}')
|
|
183
|
+
case _:
|
|
184
|
+
raise ValueError(f'Unsupported format: {format}')
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
'''
|
|
188
|
+
For future implementation
|
|
189
|
+
|
|
190
|
+
@author: Christian G. Garcia
|
|
191
|
+
'''
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
'''
|
|
2
|
+
Exporter Module
|
|
3
|
+
|
|
4
|
+
This module provides utilities for exporting generated datasets
|
|
5
|
+
into different storage formats such as CSV, JSON, and SQL databases.
|
|
6
|
+
|
|
7
|
+
It works together with the dataset generator to allow developers to
|
|
8
|
+
easily persist mock data for testing, analysis, and development.
|
|
9
|
+
|
|
10
|
+
Supported Exports Formats
|
|
11
|
+
-------------------------
|
|
12
|
+
- CSV
|
|
13
|
+
- JSON
|
|
14
|
+
- SQL
|
|
15
|
+
|
|
16
|
+
Notes
|
|
17
|
+
-----
|
|
18
|
+
All exported datasets contain synthetic data generated for development
|
|
19
|
+
and testing purposes only.
|
|
20
|
+
|
|
21
|
+
Author
|
|
22
|
+
------
|
|
23
|
+
Christian Garcia
|
|
24
|
+
https://github.com/christiangarcia0311
|
|
25
|
+
'''
|
|
26
|
+
|
|
27
|
+
from sqlalchemy import create_engine
|
|
28
|
+
from sqlalchemy.types import String, Integer, Float
|
|
29
|
+
|
|
30
|
+
import pandas as pd
|
|
31
|
+
|
|
32
|
+
class SaveData:
|
|
33
|
+
def __init__(self):
|
|
34
|
+
pass
|
|
35
|
+
|
|
36
|
+
def to_csv(self, data: dict, filename: str):
|
|
37
|
+
try:
|
|
38
|
+
if isinstance(data, dict):
|
|
39
|
+
data = pd.DataFrame(data)
|
|
40
|
+
elif isinstance(data, pd.DataFrame):
|
|
41
|
+
data = data
|
|
42
|
+
else:
|
|
43
|
+
raise ValueError('Data must be a dictionary or a pandas DataFrame.')
|
|
44
|
+
|
|
45
|
+
data.to_csv(filename, index=False)
|
|
46
|
+
print(f'Data successfully saved as `{filename}`')
|
|
47
|
+
except Exception as e:
|
|
48
|
+
print(f'Error saving data: {e}')
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def to_json(self, data: dict, filename: str):
|
|
52
|
+
try:
|
|
53
|
+
if isinstance(data, dict):
|
|
54
|
+
data = pd.DataFrame(data)
|
|
55
|
+
elif isinstance(data, pd.DataFrame):
|
|
56
|
+
data = data
|
|
57
|
+
else:
|
|
58
|
+
raise ValueError('Data must be a dictionary or a pandas DataFrame.')
|
|
59
|
+
|
|
60
|
+
data.to_json(filename, orient='records', indent=4)
|
|
61
|
+
print(f'Data successfully saved as `{filename}`')
|
|
62
|
+
except Exception as e:
|
|
63
|
+
print(f'Error saving data: {e}')
|
|
64
|
+
|
|
65
|
+
def to_sql(
|
|
66
|
+
self,
|
|
67
|
+
data: dict,
|
|
68
|
+
table_name: str,
|
|
69
|
+
database_type: str = 'sqlite',
|
|
70
|
+
database_name: str = 'mock_data.db',
|
|
71
|
+
username: str = None,
|
|
72
|
+
password: str = None,
|
|
73
|
+
host: str = 'localhost',
|
|
74
|
+
port: int = None,
|
|
75
|
+
if_exist: str = 'fail',
|
|
76
|
+
primary_key: str = 'id',
|
|
77
|
+
indexes: bool = False
|
|
78
|
+
):
|
|
79
|
+
if isinstance(data, dict):
|
|
80
|
+
data = pd.DataFrame(data)
|
|
81
|
+
elif isinstance(data, pd.DataFrame):
|
|
82
|
+
data = data
|
|
83
|
+
else:
|
|
84
|
+
raise ValueError('Data must be a dictionary or a pandas DataFrame.')
|
|
85
|
+
|
|
86
|
+
match (database_type.lower()):
|
|
87
|
+
case 'sqlite':
|
|
88
|
+
connection = f'sqlite:///{database_name}'
|
|
89
|
+
case 'mysql':
|
|
90
|
+
port = port or 3306
|
|
91
|
+
if not all([username, password]): raise ValueError('MySQL database requires username and password.')
|
|
92
|
+
connection = f'mysql+pymysql://{username}:{password}@{host}:{port}/{database_name}'
|
|
93
|
+
case _:
|
|
94
|
+
raise ValueError('`database_type` must be either sqlite or mysql')
|
|
95
|
+
|
|
96
|
+
if primary_key not in data.columns:
|
|
97
|
+
data.insert(0, primary_key, range(1, len(data) + 1))
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
data_type_map = {}
|
|
101
|
+
|
|
102
|
+
for column, data_type in data.dtypes.items():
|
|
103
|
+
if pd.api.types.is_integer_dtype(data_type):
|
|
104
|
+
data_type_map[column] = Integer()
|
|
105
|
+
elif pd.api.types.is_float_dtype(data_type):
|
|
106
|
+
data_type_map[column] = Float()
|
|
107
|
+
else:
|
|
108
|
+
max_length = data[column].astype(str).str.len().max()
|
|
109
|
+
max_length = max_length if max_length > 0 else 50
|
|
110
|
+
data_type_map[column] = String(length=max_length)
|
|
111
|
+
|
|
112
|
+
try:
|
|
113
|
+
engine = create_engine(connection)
|
|
114
|
+
data.to_sql(name=table_name, con=engine, index=indexes, if_exists=if_exist, dtype=data_type_map)
|
|
115
|
+
print(f'Data successfully saved to `{table_name}` table in `{database_name}` database')
|
|
116
|
+
except Exception as e:
|
|
117
|
+
print(f'Error saving data to SQL: {e}')
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
{
|
|
2
|
+
"strand": [
|
|
3
|
+
"Science Technology Engineering Mathematics",
|
|
4
|
+
"Accountancy Business Management",
|
|
5
|
+
"Humanities and Social Sciences",
|
|
6
|
+
"General Academic Strand"
|
|
7
|
+
],
|
|
8
|
+
"course": [
|
|
9
|
+
"BS in Computer Science",
|
|
10
|
+
"BS in Information Technology",
|
|
11
|
+
"BS in Information System",
|
|
12
|
+
"BS in Computer Engineering",
|
|
13
|
+
"BS in Civil Engineering",
|
|
14
|
+
"BS in Mechanical Engineering",
|
|
15
|
+
"BS in Electrical Engineering",
|
|
16
|
+
"BS in Electronics Engineering",
|
|
17
|
+
"BS in Industrial Engineering",
|
|
18
|
+
"BS in Chemical Engineering",
|
|
19
|
+
"BS in Environmental Engineering",
|
|
20
|
+
"BS in Nursing",
|
|
21
|
+
"BS in Pharmacy",
|
|
22
|
+
"BS in Medical Technology",
|
|
23
|
+
"BS in Physical Therapy",
|
|
24
|
+
"BS in Radiologic Technology",
|
|
25
|
+
"BS in Occupational Therapy",
|
|
26
|
+
"BS in Nutrition and Dietetics",
|
|
27
|
+
"BS in Biology",
|
|
28
|
+
"BS in Microbiology",
|
|
29
|
+
"BS in Chemistry",
|
|
30
|
+
"BS in Physics",
|
|
31
|
+
"BS in Statistics",
|
|
32
|
+
"BS in Mathematics",
|
|
33
|
+
"BS in Actuarial Science",
|
|
34
|
+
"BS in Psychology",
|
|
35
|
+
"BS in Accountancy",
|
|
36
|
+
"BS in Accounting Technology",
|
|
37
|
+
"BS in Management Accounting",
|
|
38
|
+
"BS in Entrepreneurship",
|
|
39
|
+
"BS in Marketing",
|
|
40
|
+
"BS in Business Administration",
|
|
41
|
+
"BS in Hotel Restaurant Management",
|
|
42
|
+
"BS in Tourism Management",
|
|
43
|
+
"BS in Environmental Science",
|
|
44
|
+
"BS in Marine Biology",
|
|
45
|
+
"BS in Agriculture",
|
|
46
|
+
"BS in Forestry",
|
|
47
|
+
"BS in Geology",
|
|
48
|
+
"BS in Architecture",
|
|
49
|
+
"BS in Interior Design",
|
|
50
|
+
"BS in Industrial Design",
|
|
51
|
+
"BS in Animation / Multimedia Arts",
|
|
52
|
+
"BS in Forensic Science",
|
|
53
|
+
"BS in Criminology",
|
|
54
|
+
"BS in Sports Science / Exercise Science",
|
|
55
|
+
"BA in Communication",
|
|
56
|
+
"BA in Journalism",
|
|
57
|
+
"BA in Mass Communication",
|
|
58
|
+
"BA in Media Studies",
|
|
59
|
+
"BA in Political Science",
|
|
60
|
+
"BA in International Relations",
|
|
61
|
+
"BA in Public Administration",
|
|
62
|
+
"BA in Sociology"
|
|
63
|
+
]
|
|
64
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"male": [
|
|
3
|
+
"John", "Jose", "Mark", "Michael", "Joel", "Romeo", "Antonio", "Reynaldo", "Rolando", "Danilo",
|
|
4
|
+
"Joseph", "Richard", "Rogelio", "Eduardo", "Roberto", "Ronald", "Rodolfo", "Ernesto", "Mario",
|
|
5
|
+
"Edwin", "Alfredo", "Noel", "Ricardo", "Jonathan", "Allan", "Francisco", "Arnel", "Marlon",
|
|
6
|
+
"Renato", "Jerry", "Jeffrey", "Manuel", "Ryan", "Alvin", "Fernando", "Christopher", "Dennis",
|
|
7
|
+
"Jesus", "Jayson", "Edgar", "Randy", "Alberto", "Robert", "Jimmy", "Rey", "Marvin", "Pedro",
|
|
8
|
+
"Arnold", "Elmer", "Wilfredo", "Rodrigo", "Roger", "Nestor", "Vicente", "Nelson", "Jessie",
|
|
9
|
+
"Leonardo", "Ricky", "Domingo", "Rodel", "Edgardo", "Ruben", "Benjamin", "Armando", "Felix",
|
|
10
|
+
"Julie", "Ramon", "Virgilio", "Alex", "Albert", "Efren", "Erwin", "Gilbert", "Anthony", "Ronnie",
|
|
11
|
+
"Jay", "Rommel", "Joselito", "Julius", "Victor", "Ruel", "Juanito", "Alexander", "Rene", "Henry",
|
|
12
|
+
"Cesar", "Eric", "Salvador", "Dominador", "Joy", "Ramil", "Carlito", "Francis", "Daniel", "Joey",
|
|
13
|
+
"Dante", "James", "Juan", "Alejandro", "Leo", "Carlos", "Samuel", "William", "Ferdinand", "Emmanuel",
|
|
14
|
+
"Rolly", "Roy", "Ronaldo", "Jomar", "Eddie", "Jumar", "Orlando", "Gregorio", "Christian", "Raul",
|
|
15
|
+
"Jerome", "Bernardo", "Felipe", "Melvin", "Oscar","Rafael", "Angelito", "Bonifacio", "Larry", "Bryan",
|
|
16
|
+
"Raymond", "Arturo", "Romulo", "George", "Melchor", "Paul", "Romel", "Glenn", "Thyronne", "Jason"
|
|
17
|
+
],
|
|
18
|
+
"female": [
|
|
19
|
+
"Mary", "Maria", "Jocelyn", "Teresita", "Maricel", "Evelyn", "Josephine", "Marilyn", "Rowena", "Erlinda",
|
|
20
|
+
"Jennifer", "Marites", "Gina", "Michelle", "Elizabeth", "Marilou", "Gloria", "Virginia", "Rosemarie",
|
|
21
|
+
"Arlene", "Lolita", "Analyn", "Norma", "Alma", "Helen", "Cristina", "Myrna", "Imelda", "Lourdes",
|
|
22
|
+
"Irene", "Corazon", "Rosita", "Ana", "Evangeline", "Marissa", "Joan", "Elena", "Gemma", "Marivic",
|
|
23
|
+
"Lorna", "Grace", "Rosalie", "Julie", "Vilma", "Zenaida", "Catherine", "Edna", "Melanie", "Susan",
|
|
24
|
+
"Rose", "Fe", "Jenny", "Rosalinda", "Cherry", "Maribel", "Emma", "Remedios", "Josefina", "Joy",
|
|
25
|
+
"Lilia", "Milagros", "Lydia", "Rebecca", "Emily", "Daisy", "Sarah", "Anna", "Janice", "Rosario",
|
|
26
|
+
"Carmelita", "Victoria", "Delia", "Julieta", "Editha", "Cecilia", "Christine", "Aida", "Yolanda",
|
|
27
|
+
"Rosalina", "Jessica", "Jean", "Alicia", "Leonora", "Violeta", "Liza", "Elsa", "Raquel", "Aileen",
|
|
28
|
+
"Karen", "Analiza", "Lea", "Wilma", "Marlyn", "Marie", "Judith", "Jovelyn", "Nancy", "April", "Dolores",
|
|
29
|
+
"Nora", "Angelita", "May", "Ruby", "Salvacion", "Jonalyn", "Luzviminda", "Juliet", "Lilibeth", "Mylene",
|
|
30
|
+
"Mylene", "Elvira", "Roselyn", "Margie", "Juanita", "Janet", "Fatima", "Shirley", "Leah", "Geraldine",
|
|
31
|
+
"Mercy", "Lorena", "Jenelyn", "Leonila", "Lucia", "Thelma", "Eva", "Leticia", "Estrella", "Sheila",
|
|
32
|
+
"Sheryl", "Marina", "Angelica", "Elisa", "Elsie", "Marjorie", "Agnes", "Shiela", "Teresa", "Judy",
|
|
33
|
+
"Hazel", "Rhea", "Arlyn", "Marife", "Myra", "Angelina", "Flordeliza", "Jessa", "Diana", "Regina"
|
|
34
|
+
]
|
|
35
|
+
}
|