kardioutils 1.0.23__tar.gz → 1.0.24__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.
- {kardioutils-1.0.23/kardioutils.egg-info → kardioutils-1.0.24}/PKG-INFO +1 -1
- kardioutils-1.0.24/dl2050utils/__version__.py +1 -0
- {kardioutils-1.0.23 → kardioutils-1.0.24}/dl2050utils/fdb.py +56 -0
- {kardioutils-1.0.23 → kardioutils-1.0.24}/dl2050utils/fs.py +24 -22
- {kardioutils-1.0.23 → kardioutils-1.0.24/kardioutils.egg-info}/PKG-INFO +1 -1
- kardioutils-1.0.23/dl2050utils/__version__.py +0 -1
- {kardioutils-1.0.23 → kardioutils-1.0.24}/LICENSE.txt +0 -0
- {kardioutils-1.0.23 → kardioutils-1.0.24}/README.md +0 -0
- {kardioutils-1.0.23 → kardioutils-1.0.24}/dl2050utils/__config__.py +0 -0
- {kardioutils-1.0.23 → kardioutils-1.0.24}/dl2050utils/__init__.py +0 -0
- {kardioutils-1.0.23 → kardioutils-1.0.24}/dl2050utils/api.py +0 -0
- {kardioutils-1.0.23 → kardioutils-1.0.24}/dl2050utils/auth.py +0 -0
- {kardioutils-1.0.23 → kardioutils-1.0.24}/dl2050utils/com.py +0 -0
- {kardioutils-1.0.23 → kardioutils-1.0.24}/dl2050utils/common.py +0 -0
- {kardioutils-1.0.23 → kardioutils-1.0.24}/dl2050utils/core.py +0 -0
- {kardioutils-1.0.23 → kardioutils-1.0.24}/dl2050utils/db copy.py +0 -0
- {kardioutils-1.0.23 → kardioutils-1.0.24}/dl2050utils/db.py +0 -0
- {kardioutils-1.0.23 → kardioutils-1.0.24}/dl2050utils/dbdf.py +0 -0
- {kardioutils-1.0.23 → kardioutils-1.0.24}/dl2050utils/dbutils.py +0 -0
- {kardioutils-1.0.23 → kardioutils-1.0.24}/dl2050utils/df.py +0 -0
- {kardioutils-1.0.23 → kardioutils-1.0.24}/dl2050utils/df_utils.py +0 -0
- {kardioutils-1.0.23 → kardioutils-1.0.24}/dl2050utils/env.py +0 -0
- {kardioutils-1.0.23 → kardioutils-1.0.24}/dl2050utils/etl.py +0 -0
- {kardioutils-1.0.23 → kardioutils-1.0.24}/dl2050utils/graphql.py +0 -0
- {kardioutils-1.0.23 → kardioutils-1.0.24}/dl2050utils/gs.py +0 -0
- {kardioutils-1.0.23 → kardioutils-1.0.24}/dl2050utils/ju.py +0 -0
- {kardioutils-1.0.23 → kardioutils-1.0.24}/dl2050utils/log.py +0 -0
- {kardioutils-1.0.23 → kardioutils-1.0.24}/dl2050utils/mq.py +0 -0
- {kardioutils-1.0.23 → kardioutils-1.0.24}/dl2050utils/rest.py +0 -0
- {kardioutils-1.0.23 → kardioutils-1.0.24}/dl2050utils/restapp.py +0 -0
- {kardioutils-1.0.23 → kardioutils-1.0.24}/dl2050utils/restutils.py +0 -0
- {kardioutils-1.0.23 → kardioutils-1.0.24}/dl2050utils/sqlite.py +0 -0
- {kardioutils-1.0.23 → kardioutils-1.0.24}/dl2050utils/ulists.py +0 -0
- {kardioutils-1.0.23 → kardioutils-1.0.24}/dl2050utils/wsgi.py +0 -0
- {kardioutils-1.0.23 → kardioutils-1.0.24}/kardioutils.egg-info/SOURCES.txt +0 -0
- {kardioutils-1.0.23 → kardioutils-1.0.24}/kardioutils.egg-info/dependency_links.txt +0 -0
- {kardioutils-1.0.23 → kardioutils-1.0.24}/kardioutils.egg-info/top_level.txt +0 -0
- {kardioutils-1.0.23 → kardioutils-1.0.24}/setup.cfg +0 -0
- {kardioutils-1.0.23 → kardioutils-1.0.24}/setup.py +0 -0
- {kardioutils-1.0.23 → kardioutils-1.0.24}/test/test_core.py +0 -0
- {kardioutils-1.0.23 → kardioutils-1.0.24}/test/test_db.py +0 -0
- {kardioutils-1.0.23 → kardioutils-1.0.24}/test/test_env.py +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
version = "1.0.24"
|
|
@@ -3,6 +3,8 @@ import pathlib
|
|
|
3
3
|
from pathlib import Path
|
|
4
4
|
import numpy as np
|
|
5
5
|
from dl2050utils.common import pickle_save, pickle_load
|
|
6
|
+
from dl2050utils.fs import np_load_async, pickle_load_async
|
|
7
|
+
import asyncio
|
|
6
8
|
|
|
7
9
|
class FileDB():
|
|
8
10
|
"""
|
|
@@ -84,6 +86,39 @@ class FileDB():
|
|
|
84
86
|
if show:
|
|
85
87
|
print(f'FileDB save Exception: {exc}')
|
|
86
88
|
return 1
|
|
89
|
+
async def async_save(
|
|
90
|
+
self,
|
|
91
|
+
key,
|
|
92
|
+
data,
|
|
93
|
+
pre='',
|
|
94
|
+
ext='',
|
|
95
|
+
save_f=pickle_save,
|
|
96
|
+
allow_pickle=False,
|
|
97
|
+
show=False
|
|
98
|
+
):
|
|
99
|
+
"""
|
|
100
|
+
Async save: não bloqueia o event loop (corre o save numa thread).
|
|
101
|
+
Returns 0 se OK, 1 se erro.
|
|
102
|
+
"""
|
|
103
|
+
dir_path = Path(self.get_dir(key))
|
|
104
|
+
dir_path.mkdir(parents=True, exist_ok=True)
|
|
105
|
+
file_name = self.get_name(key, pre=pre, ext=ext)
|
|
106
|
+
p = dir_path / file_name
|
|
107
|
+
|
|
108
|
+
def _save_sync():
|
|
109
|
+
if ext == '.npy':
|
|
110
|
+
np.save(p, data, allow_pickle=allow_pickle)
|
|
111
|
+
else:
|
|
112
|
+
save_f(p, data)
|
|
113
|
+
return 0
|
|
114
|
+
|
|
115
|
+
try:
|
|
116
|
+
return await asyncio.to_thread(_save_sync)
|
|
117
|
+
except Exception as exc:
|
|
118
|
+
if show:
|
|
119
|
+
print(f'FileDB async_save Exception: {exc}')
|
|
120
|
+
return 1
|
|
121
|
+
|
|
87
122
|
|
|
88
123
|
def load(self, key, pre='', ext='', load_f=pickle_load, allow_pickle=False,show=False):
|
|
89
124
|
"""
|
|
@@ -106,6 +141,27 @@ class FileDB():
|
|
|
106
141
|
if show:
|
|
107
142
|
print(f'FileDB load Exception: {exc}')
|
|
108
143
|
return None
|
|
144
|
+
async def async_load(self, key, pre='', ext='', load_f=pickle_load_async, allow_pickle=False,show=False):
|
|
145
|
+
"""
|
|
146
|
+
Loads data from a file based on the key, prefix, and extension.
|
|
147
|
+
Args:
|
|
148
|
+
key (int or str): The unique identifier for the file.
|
|
149
|
+
pre (str, optional): A prefix for the file name.
|
|
150
|
+
ext (str, optional): The file extension. Use '.npy' for NumPy arrays.
|
|
151
|
+
load_f (callable, optional): The load function to use (defaults to pickle_load).
|
|
152
|
+
Returns:
|
|
153
|
+
any: The loaded data or None if the load failed.
|
|
154
|
+
"""
|
|
155
|
+
dir_path = Path(self.get_dir(key))
|
|
156
|
+
file_name = self.get_name(key, pre=pre, ext=ext)
|
|
157
|
+
p = dir_path/file_name
|
|
158
|
+
try:
|
|
159
|
+
if ext=='.npy': return await np_load_async(p,allow_pickle=allow_pickle)
|
|
160
|
+
return await load_f(p)
|
|
161
|
+
except Exception as exc:
|
|
162
|
+
if show:
|
|
163
|
+
print(f'FileDB load Exception: {exc}')
|
|
164
|
+
return None
|
|
109
165
|
|
|
110
166
|
def delete(self, key, pre='', ext='',show=False):
|
|
111
167
|
"""
|
|
@@ -74,6 +74,20 @@ def pickle_load(p):
|
|
|
74
74
|
except Exception as exc:
|
|
75
75
|
print(str(exc))
|
|
76
76
|
return 1
|
|
77
|
+
|
|
78
|
+
async def pickle_load_async(p):
|
|
79
|
+
p = Path(p)
|
|
80
|
+
p = p.with_suffix(".pickle")
|
|
81
|
+
if not p.is_file():
|
|
82
|
+
return None
|
|
83
|
+
def _load():
|
|
84
|
+
with open(p,"rb") as f:
|
|
85
|
+
return pickle.load(f)
|
|
86
|
+
try:
|
|
87
|
+
return await asyncio.to_thread(_load)
|
|
88
|
+
except Exception as exc:
|
|
89
|
+
print(str(exc))
|
|
90
|
+
|
|
77
91
|
|
|
78
92
|
|
|
79
93
|
def np_save(p, d, allow_pickle=True):
|
|
@@ -115,31 +129,19 @@ def np_load(p, allow_pickle=True):
|
|
|
115
129
|
return 1
|
|
116
130
|
|
|
117
131
|
|
|
118
|
-
async def np_load_async(p, allow_pickle=False):
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
Args:
|
|
122
|
-
p (str or Path): The file path from where the array will be loaded.
|
|
123
|
-
allow_pickle (bool): If True, allows loading of object arrays.
|
|
124
|
-
|
|
125
|
-
Returns:
|
|
126
|
-
np.ndarray: The loaded array, or None if an error occurred.
|
|
127
|
-
"""
|
|
128
|
-
p = Path(p)
|
|
129
|
-
p = p.with_suffix(".npy")
|
|
132
|
+
async def np_load_async(p, allow_pickle=False, mmap_mode=None):
|
|
133
|
+
p = Path(p).with_suffix(".npy")
|
|
130
134
|
if not p.is_file():
|
|
131
135
|
return None
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
if allow_pickle:
|
|
137
|
-
d = np.load(f, allow_pickle=allow_pickle)
|
|
138
|
-
if d is None:
|
|
139
|
-
return None
|
|
136
|
+
|
|
137
|
+
def _load():
|
|
138
|
+
d = np.load(p, allow_pickle=allow_pickle, mmap_mode=mmap_mode)
|
|
139
|
+
if allow_pickle and isinstance(d, np.ndarray) and d.shape == () and d.dtype == object:
|
|
140
140
|
return d.item()
|
|
141
|
-
|
|
142
|
-
|
|
141
|
+
return d
|
|
142
|
+
|
|
143
|
+
try:
|
|
144
|
+
return await asyncio.to_thread(_load)
|
|
143
145
|
except Exception:
|
|
144
146
|
return None
|
|
145
147
|
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
version = "1.0.23"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|