afgutils 1.2.0__tar.gz → 1.3.0__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.
- {afgutils-1.2.0 → afgutils-1.3.0}/PKG-INFO +1 -1
- {afgutils-1.2.0 → afgutils-1.3.0}/afgutils/s3.py +13 -0
- {afgutils-1.2.0 → afgutils-1.3.0}/afgutils/utils.py +23 -10
- {afgutils-1.2.0 → afgutils-1.3.0}/afgutils.egg-info/PKG-INFO +1 -1
- {afgutils-1.2.0 → afgutils-1.3.0}/setup.py +1 -1
- {afgutils-1.2.0 → afgutils-1.3.0}/afgutils/__init__.py +0 -0
- {afgutils-1.2.0 → afgutils-1.3.0}/afgutils/advanceai_util.py +0 -0
- {afgutils-1.2.0 → afgutils-1.3.0}/afgutils/cgi.py +0 -0
- {afgutils-1.2.0 → afgutils-1.3.0}/afgutils/credolab.py +0 -0
- {afgutils-1.2.0 → afgutils-1.3.0}/afgutils/db.py +0 -0
- {afgutils-1.2.0 → afgutils-1.3.0}/afgutils/email.py +0 -0
- {afgutils-1.2.0 → afgutils-1.3.0}/afgutils/trandata.py +0 -0
- {afgutils-1.2.0 → afgutils-1.3.0}/afgutils.egg-info/SOURCES.txt +0 -0
- {afgutils-1.2.0 → afgutils-1.3.0}/afgutils.egg-info/dependency_links.txt +0 -0
- {afgutils-1.2.0 → afgutils-1.3.0}/afgutils.egg-info/requires.txt +0 -0
- {afgutils-1.2.0 → afgutils-1.3.0}/afgutils.egg-info/top_level.txt +0 -0
- {afgutils-1.2.0 → afgutils-1.3.0}/setup.cfg +0 -0
|
@@ -16,6 +16,19 @@ def save_to_s3(s3_key: str, content_body: str, aws_access_key_id=None,
|
|
|
16
16
|
|
|
17
17
|
def get_from_s3(s3_key, filename: str = None, aws_access_key_id=None,
|
|
18
18
|
aws_secret_access_key=None, aws_region=None, s3_bucket=None, as_bytes: bool = False):
|
|
19
|
+
"""
|
|
20
|
+
Downloads file from S3
|
|
21
|
+
|
|
22
|
+
Only s3_key is obligatory.
|
|
23
|
+
|
|
24
|
+
If AWS bucket, creds are ommited then LMS production bucket, creds are assumed.
|
|
25
|
+
|
|
26
|
+
as_bytes
|
|
27
|
+
False saves file from S3 to filename, returns None
|
|
28
|
+
|
|
29
|
+
True returns byte array instead of saving the file, filename is ignored
|
|
30
|
+
"""
|
|
31
|
+
|
|
19
32
|
s3_client = _get_s3_client(aws_access_key_id, aws_secret_access_key, aws_region)
|
|
20
33
|
s3_bucket = s3_bucket or _getenv('s3_bucket_lms')
|
|
21
34
|
|
|
@@ -24,6 +24,7 @@ from pandas import DataFrame
|
|
|
24
24
|
import pyodbc
|
|
25
25
|
from typing import Any
|
|
26
26
|
from afgutils.db import DB
|
|
27
|
+
from numpy import bool_
|
|
27
28
|
|
|
28
29
|
|
|
29
30
|
# session_token_cookie_name = "uwtool_session_token"
|
|
@@ -109,7 +110,7 @@ def clear_mfv(mfv: dict) -> dict:
|
|
|
109
110
|
|
|
110
111
|
|
|
111
112
|
def data_vector_to_sql_insert(data_vector: dict | DataFrame, insert_sql_tpl: str = None,
|
|
112
|
-
existing_values: list = None) ->
|
|
113
|
+
existing_values: list = None) -> tuple[tuple, str]:
|
|
113
114
|
"""
|
|
114
115
|
Returns data tuple and an SQL INSERT statement to be used in conjunction with DB.execute() function.
|
|
115
116
|
|
|
@@ -133,20 +134,26 @@ def data_vector_to_sql_insert(data_vector: dict | DataFrame, insert_sql_tpl: str
|
|
|
133
134
|
to the number of keys in the data_vector
|
|
134
135
|
"""
|
|
135
136
|
|
|
136
|
-
column_names_insert_text = ""
|
|
137
|
+
# column_names_insert_text = ""
|
|
138
|
+
column_names_list=[]
|
|
137
139
|
item_values = []
|
|
138
140
|
|
|
139
141
|
# convert data vector into a list
|
|
140
142
|
if isinstance(data_vector, DataFrame):
|
|
141
143
|
for column_name in data_vector.columns.tolist():
|
|
142
|
-
column_names_insert_text = (column_names_insert_text + "," + column_name + "\
|
|
143
|
-
|
|
144
|
-
|
|
144
|
+
# column_names_insert_text = (column_names_insert_text + "," + column_name + "\n").replace(".",
|
|
145
|
+
# "_")
|
|
146
|
+
column_names_list.append(column_name.replace(".", "_"))
|
|
147
|
+
curr_item_value=data_vector.loc[0, column_name]
|
|
148
|
+
curr_item_value=bool(curr_item_value) if type(curr_item_value) is bool_ else curr_item_value
|
|
149
|
+
item_values.append(curr_item_value)
|
|
145
150
|
|
|
146
151
|
elif type(data_vector) is dict:
|
|
147
|
-
#
|
|
148
|
-
|
|
149
|
-
|
|
152
|
+
# raise NotImplementedError("data_vector_to_sql_insert: dictionary data_vector is not implemented yet")
|
|
153
|
+
for column_name in data_vector:
|
|
154
|
+
# column_names_insert_text = (column_names_insert_text + "," + column_name + "\n").replace(".", "_")
|
|
155
|
+
column_names_list.append(column_name)
|
|
156
|
+
item_values.append(data_vector[column_name])
|
|
150
157
|
else:
|
|
151
158
|
raise TypeError("data_vector_to_sql_insert: data_vector must be a pandas.DataFrame or a dictionary")
|
|
152
159
|
|
|
@@ -162,9 +169,15 @@ def data_vector_to_sql_insert(data_vector: dict | DataFrame, insert_sql_tpl: str
|
|
|
162
169
|
else:
|
|
163
170
|
raise TypeError("data_vector_to_sql_insert: existing_values must be a list or None")
|
|
164
171
|
|
|
172
|
+
# prep strings
|
|
173
|
+
column_names_insert_text=", ".join(column_names_list)
|
|
174
|
+
|
|
175
|
+
placeholders_string= ', ?' * len(item_values)
|
|
176
|
+
placeholders_string = placeholders_string[1:]
|
|
177
|
+
|
|
165
178
|
# generate SQL
|
|
166
179
|
if type(insert_sql_tpl) is str:
|
|
167
|
-
result_sql = insert_sql_tpl.format(column_names_insert_text,
|
|
180
|
+
result_sql = insert_sql_tpl.format(column_names_insert_text, placeholders_string)
|
|
168
181
|
elif insert_sql_tpl is None:
|
|
169
182
|
result_sql = column_names_insert_text
|
|
170
183
|
else:
|
|
@@ -208,7 +221,7 @@ parse_row_into_object = parse_dict_into_object # added for legacy compatibility
|
|
|
208
221
|
|
|
209
222
|
class AfgBaseMixin:
|
|
210
223
|
"""
|
|
211
|
-
Base
|
|
224
|
+
Base extension for all AFG objects; restricts operations on private and callabe attributes.
|
|
212
225
|
|
|
213
226
|
__str__ ommits private and callable attributes
|
|
214
227
|
|
|
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
|