-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatabase_initialise.py
More file actions
79 lines (57 loc) · 2.76 KB
/
database_initialise.py
File metadata and controls
79 lines (57 loc) · 2.76 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
# MODULE: database_initialise.py
# VERSION: 0.4
# DIRECTORY: <masked>
# DATE: 2023-06-04
# AUTHOR: RandomCollection
# DESCRIPTION: See https://github.com/RandomCollection/Vocabulary-Trainer.
# LIBRARIES ############################################################################################################
import os
import pandas as pd
import sqlite3
from projects.vocabulary_trainer import cfg, vocabulary_process
# FUNCTIONS ############################################################################################################
def initialise_database_settings() -> pd.DataFrame:
return pd.DataFrame(
data={
"SETTING_COUNTER_ON": [cfg.SETTING_COUNTER_ON],
"SETTING_SENSITIVITY": [cfg.SETTING_SENSITIVITY],
"SETTING_SLEEPER": [cfg.SETTING_SLEEPER],
},
index=["VALUE"]
)
def initialise_database_statistics() -> pd.DataFrame:
return pd.DataFrame(
data={
"STATISTIC_LAST_DATE": [cfg.STATISTIC_LAST_DATE],
"STATISTIC_STREAK_BEST": [cfg.STATISTIC_STREAK_BEST],
"STATISTIC_WORDS_TOTAL": [cfg.STATISTIC_WORDS_TOTAL],
},
index=["VALUE"]
)
# MAIN FUNCTION ########################################################################################################
def database_initialise():
# SETTINGS ---------------------------------------------------------------------------------------------------------
settings = initialise_database_settings()
# STATISTICS -------------------------------------------------------------------------------------------------------
statistics = initialise_database_statistics()
# VOCABULARY -------------------------------------------------------------------------------------------------------
vocabulary = (
pd.read_excel(
io=os.path.join(cfg.PATH_ROOT, cfg.NAME_VOCABULARY_DIRTY),
engine="openpyxl",
keep_default_na=False
)
.pipe(vocabulary_process.unstack_vocabulary_singular_plural)
.pipe(vocabulary_process.unstack_vocabulary_languages)
)
# CREATE SQLITE3 DATABASE ------------------------------------------------------------------------------------------
con = sqlite3.connect(database=os.path.join(cfg.PATH_ROOT, cfg.NAME_DATABASE))
settings.to_sql(name="SETTINGS", con=con, if_exists="replace", index=False)
statistics.to_sql(name="STATISTICS", con=con, if_exists="replace", index=False)
vocabulary.to_sql(name="VOCABULARY", con=con, if_exists="replace", index=False)
con.commit()
con.close()
# MAIN #################################################################################################################
if __name__ == "__main__":
database_initialise()
# END ##################################################################################################################