-
Notifications
You must be signed in to change notification settings - Fork 0
/
DataCreation.py
77 lines (71 loc) · 3.78 KB
/
DataCreation.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
# Copyright (C) 2021 <FacuFalcone - CaidevOficial>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import FileHandle_Mod.FileHandle as FH
from FileHandle_Mod.FileHandle import DoubleMessage as PMD
from FileHandle_Mod.FileHandle import SingleMessage as PMS
from GetData_Mod import GetData as GD
def CreateData(JSON_ALL_TABLES: dict, jsonRecord:dict, dataSetName:str, sqlStatement:bool) -> bool:
"""[summary]
Creates the data for a file.
Args:
JSON_ALL_TABLES (dict): [Dictionary with all the tables and their columns]
jsonRecord (dict): [Json that contains all the pk and fk of the tables]
dataSetName (str): [Name of the dataset that will be created]
sqlStatement (bool): [Boolean state that indicates if the data will be created for SQL or not]
Returns:
bool: [True if the file was created successfully or False if it wasn't]
"""
success = False
for tableName in JSON_ALL_TABLES:
if (not tableName in jsonRecord.keys()):
PMS(f"Obtaining the amount of registers for table: {tableName}")
amountOfRegisters = GD.GetAmountOfRegisters(JSON_ALL_TABLES, tableName)
PMD(f"Registers for {tableName}: {amountOfRegisters}", f"Generating data for {tableName}")
PMD("This may taking a while, bassed on the", "Amount of registers and amount of columns")
dataMockRecord, actualTableDictionary = GD.CreateRecords(JSON_ALL_TABLES, tableName, amountOfRegisters, jsonRecord, sqlStatement)
jsonRecord = actualTableDictionary
if(sqlStatement):
PMS(f"Creating SQL file for {tableName}")
FH.WriteSQL(dataMockRecord, dataSetName, tableName)
success = True
else:
PMS(f"Creating CSV file for {tableName}")
FH.WriteCSV(dataMockRecord, dataSetName, tableName)
success = True
return success
def CreateRegisterForCSV(JSON_ALL_TABLES: dict, jsonRecord:dict, dataSetName:str, sqlStatement:bool):
"""[summary]
Creates a csv file with the data
Args:
JSON_ALL_TABLES (dict): [Dictionary with all the tables and their columns]
jsonRecord (dict): [Json that contains all the pk and fk of the tables]
dataSetName (str): [Name of the dataset that will be created]
sqlStatement (bool): [Boolean state that indicates if the data will be created for SQL or not]
Returns:
bool: [True if the file was created successfully or False if it wasn't]
"""
return CreateData(JSON_ALL_TABLES, jsonRecord, dataSetName, sqlStatement)
def CreateRegisterForSQL(JSON_ALL_TABLES: dict, jsonRecord:dict, dataSetName:str, sqlStatement:bool):
"""[summary]
Creates a sql file with the data and the tables
Args:
JSON_ALL_TABLES (dict): [Dictionary with all the tables and their columns]
jsonRecord (dict): [Json that contains all the pk and fk of the tables]
dataSetName (str): [Name of the dataset that will be created]
sqlStatement (bool): [Boolean state that indicates if the data will be created for SQL or not]
Returns:
bool: [True if the file was created successfully or False if it wasn't]
"""
return CreateData(JSON_ALL_TABLES, jsonRecord, dataSetName, sqlStatement)