Skip to content

Commit 4d61be2

Browse files
Update Core.Storage package.
1 parent 9141932 commit 4d61be2

File tree

19 files changed

+223
-182
lines changed

19 files changed

+223
-182
lines changed

docs/src/Core/Storage/database.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ To create this file with a `.db` extension, a call to the ``new`` method is requ
99

1010
.. code-block:: python
1111
12-
from SSD.Core import Database
12+
from SSD.Core.Storage import Database
1313
1414
# Create a new Database object and a new storage file
1515
db = Database(database_dir='my_directory',
@@ -28,7 +28,7 @@ Loading an existing *Database* is pretty similar as creating a new one, except t
2828

2929
.. code-block:: python
3030
31-
from SSD.Core import Database
31+
from SSD.Core.Storage import Database
3232
3333
# Create a new Database object and load an exiting storage file
3434
db = Database(database_dir='my_directory',
@@ -107,7 +107,7 @@ The following *Field* types are available:
107107
+--------------+--------------------------------------+---------------------------------------------------------------------------------------+
108108
| ``bool`` | :guilabel:`bool` | `BooleanField <http://docs.peewee-orm.com/en/latest/peewee/api.html#BooleanField>`_ |
109109
+--------------+--------------------------------------+---------------------------------------------------------------------------------------+
110-
| ``ndarray`` | :guilabel:`import numpy.ndarray` | See ``AdaptiveDB/ExtendedFields.py`` |
110+
| ``ndarray`` | :guilabel:`import numpy.ndarray` | Field class for storing numpy arrays. |
111111
+--------------+--------------------------------------+---------------------------------------------------------------------------------------+
112112
| ``datetime`` | :guilabel:`import datetime.datetime` | `DateTimeField <http://docs.peewee-orm.com/en/latest/peewee/api.html#DateTimeField>`_ |
113113
+--------------+--------------------------------------+---------------------------------------------------------------------------------------+

docs/src/Core/Storage/utils.rst

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ Each *Table* from all *Databases* will be duplicated in the new *Database*; in t
1010

1111
.. code-block:: python
1212
13-
from SSD.Core import merge
13+
from SSD.Core.Storage import merge
1414
15-
merge(database_names=['my_Database1', 'my_Database2'],
16-
new_database_name='my_MergedDatabase',
15+
merge(database_files=['my_Database1', 'my_Database2'],
16+
new_database_file='my_MergedDatabase',
1717
remove_existing=True)
1818
"""
1919
>> DATABASE my_Database1.db
@@ -51,7 +51,9 @@ Each *Table* from all *Databases* will be duplicated in the new *Database*; in t
5151
- _dt_ (DATETIME) (default)
5252
- my_Data (FLOAT)
5353
54-
>> Confirm new Database architecture ? (y/n):
54+
>> Confirm new Database architecture ? (y/n): y
55+
Proceeding...
56+
Merge complete.
5557
"""
5658
5759
@@ -63,9 +65,9 @@ Both methods require tuples defines as :guilabel:`(current_name, new_name)`:
6365

6466
.. code-block:: python
6567
66-
from SSD.Core import rename_tables, rename_fields
68+
from SSD.Core.Storage import rename_tables, rename_fields
6769
68-
rename_tables(database_name='my_Database',
70+
rename_tables(database_file='my_Database',
6971
renamed_tables=[('my_StoringTable', 'my_NewStoringTable'), ('my_ExchangeTable', 'my_NewExchangeTable')])
7072
"""
7173
>> DATABASE my_Database.db
@@ -80,7 +82,7 @@ Both methods require tuples defines as :guilabel:`(current_name, new_name)`:
8082
- my_Data (FLOAT)
8183
"""
8284
83-
rename_fields(database_name='my_Database',
85+
rename_fields(database_file='my_Database',
8486
table_name='my_NewStoringTable',
8587
renamed_fields=('my_Condition', 'my_Test'))
8688
"""
@@ -104,7 +106,7 @@ The ``remove_tables`` and ``remove_fields`` tools allows users to remove *Tables
104106

105107
.. code-block:: python
106108
107-
from SSD.Core import remove_tables, remove_fields
109+
from SSD.Core.Storage import remove_tables, remove_fields
108110
109111
rename_tables(database_name='my_Database',
110112
remove_tables='my_ExchangeTable')
@@ -135,7 +137,7 @@ The ``export`` tool allows users to export a *Database* either in CSV format eit
135137

136138
.. code-block:: python
137139
138-
from SSD.Core import export
140+
from SSD.Core.Storage import export
139141
140142
export(database_name='my_Database',
141143
exporter='csv',

examples/Core/storage/README.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ This repository contains a few examples that give a great overviews of the **sto
44

55
It is recommended to inspect and run the python scripts following this order:
66

7-
* ``writingDB.py``: create a Database, create Tables with Fields, add data.
8-
* ``readingDB.py``: load a Database, read data.
9-
* ``updatingDB.py``: update entries.
10-
* ``signalDB.py``: connect handlers to signals.
7+
* ``write_db.py``: create a Database, create Tables with Fields, add data.
8+
* ``read_db.py``: load a Database, read data.
9+
* ``update_db.py``: update entries.
10+
* ``signal_db.py``: connect handlers to signals.
1111
* ``foreignkeyDB.py``: manage relationship between Tables.
12+
* ``utils_db.py``: illustrate the usage of the utils functions.
1213

13-
Run the examples using ``python3 <example_name>.py``.
14+
Run the examples using ``python3 <example_name>.py``.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from numpy import ndarray, where
22
from numpy.random import uniform
33

4-
from SSD.Core import Database
4+
from SSD.Core.Storage import Database
55

66
# Create a new Database object and a new storage file
77
db = Database(database_dir='my_databases',
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
from os.path import exists, join
22
from os import system
33

4-
from SSD.Core import Database
4+
from SSD.Core.Storage import Database
55

66
# Assert DB existence
77
if not exists(join('my_databases', 'database_1.db')) or not exists(join('my_databases', 'database_2.db')):
8-
system('python3 writingDB.py')
8+
system('python3 write_db.py')
99

1010

1111
# Load an existing Database storage file
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from numpy import ndarray
22
from numpy.random import uniform
33

4-
from SSD.Core import Database
4+
from SSD.Core.Storage import Database
55

66
# Create a new Database object and a new storage file
77
db = Database(database_dir='my_databases',
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
from numpy import where
44
from numpy.random import uniform
55

6-
from SSD.Core import Database
6+
from SSD.Core.Storage import Database
77

88

99
# Assert DB existence
1010
if not exists(join('my_databases', 'database_1.db')) or not exists(join('my_databases', 'database_2.db')):
11-
system('python3 writingDB.py')
11+
system('python3 write_db.py')
1212

1313

1414
# Load an existing Database storage file
@@ -19,7 +19,7 @@
1919
# Updating data
2020
new_array = uniform(low=-1, high=1, size=(10,))
2121
new_mean = new_array.mean()
22-
new_positive = len(where(new_mean > 0)[0])
22+
new_positive = len(where(new_array > 0)[0])
2323
print("\nBEFORE UPDATE:")
2424
print(db.get_line(table_name='RawData', line_id=1))
2525
print(db.get_line(table_name='Stats', line_id=1))

examples/Core/storage/utils_db.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import os
2+
from os import chdir
3+
from numpy.random import uniform
4+
5+
from SSD.Core.Storage import Database, merge, rename_tables, rename_fields, remove_table, remove_field, export
6+
7+
8+
# Create new Databases
9+
for i in [1, 2]:
10+
db = Database(database_dir='my_databases',
11+
database_name=f'database_{i}').new(remove_existing=True)
12+
db.create_table(table_name=f'Table_{i}',
13+
storing_table=True,
14+
fields=[('value', float), ('is_positive', bool)])
15+
new_values = [round(uniform(low=-1, high=1), 2) for _ in range(5)]
16+
db.add_batch(table_name=f'Table_{i}',
17+
batch={'value': new_values,
18+
'is_positive': [x > 0 for x in new_values]})
19+
db.close()
20+
os.chdir('my_databases')
21+
22+
# Merge Databases
23+
merge(database_files=['database_1', 'database_2'],
24+
new_database_file='database_3',
25+
remove_existing=True)
26+
27+
# Renaming Tables and Fields
28+
rename_tables(database_file='database_3',
29+
renamed_tables=('Table_1', 'Table'))
30+
rename_fields(database_file='database_3',
31+
table_name='Table',
32+
renamed_fields=[('value', 'data'), ('is_positive', 'flag')])
33+
34+
# Remove Tables and Fields
35+
remove_field(database_file='database_3',
36+
table_name='Table_2',
37+
fields='is_positive')
38+
remove_table(database_file='database_3',
39+
table_names='Table_2')
40+
41+
# Export to JSON and CSV
42+
export(database_file='database_3',
43+
exporter='json')
44+
export(database_file='database_3',
45+
exporter='csv')
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from numpy import ndarray, where
22
from numpy.random import uniform
33

4-
from SSD.Core import Database
4+
from SSD.Core.Storage import Database
55

66

77
# Create a new Database object and a new storage file

src/Core/Storage/Exporter.py

Lines changed: 0 additions & 54 deletions
This file was deleted.

0 commit comments

Comments
 (0)