squirrels 0.2.2__py3-none-any.whl → 0.3.1__py3-none-any.whl
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.
Potentially problematic release.
This version of squirrels might be problematic. Click here for more details.
- squirrels/__init__.py +11 -4
- squirrels/_api_response_models.py +118 -0
- squirrels/_api_server.py +146 -75
- squirrels/_authenticator.py +10 -8
- squirrels/_command_line.py +17 -11
- squirrels/_connection_set.py +4 -3
- squirrels/_constants.py +15 -6
- squirrels/_environcfg.py +15 -11
- squirrels/_initializer.py +25 -15
- squirrels/_manifest.py +22 -12
- squirrels/_models.py +316 -154
- squirrels/_parameter_configs.py +195 -57
- squirrels/_parameter_sets.py +14 -17
- squirrels/_py_module.py +2 -4
- squirrels/_seeds.py +38 -0
- squirrels/_utils.py +41 -33
- squirrels/arguments/run_time_args.py +76 -34
- squirrels/data_sources.py +172 -51
- squirrels/dateutils.py +3 -3
- squirrels/package_data/assets/index.js +14 -14
- squirrels/package_data/base_project/.gitignore +1 -0
- squirrels/package_data/base_project/{database → assets}/expenses.db +0 -0
- squirrels/package_data/base_project/assets/weather.db +0 -0
- squirrels/package_data/base_project/connections.yml +1 -1
- squirrels/package_data/base_project/docker/Dockerfile +1 -1
- squirrels/package_data/base_project/{environcfg.yml → env.yml} +8 -8
- squirrels/package_data/base_project/models/dbviews/database_view1.py +25 -14
- squirrels/package_data/base_project/models/dbviews/database_view1.sql +20 -14
- squirrels/package_data/base_project/models/federates/dataset_example.py +6 -5
- squirrels/package_data/base_project/models/federates/dataset_example.sql +1 -1
- squirrels/package_data/base_project/parameters.yml +57 -28
- squirrels/package_data/base_project/pyconfigs/auth.py +11 -10
- squirrels/package_data/base_project/pyconfigs/connections.py +7 -9
- squirrels/package_data/base_project/pyconfigs/context.py +49 -33
- squirrels/package_data/base_project/pyconfigs/parameters.py +62 -30
- squirrels/package_data/base_project/seeds/seed_categories.csv +6 -0
- squirrels/package_data/base_project/seeds/seed_subcategories.csv +15 -0
- squirrels/package_data/base_project/squirrels.yml.j2 +37 -20
- squirrels/parameter_options.py +30 -10
- squirrels/parameters.py +300 -70
- squirrels/user_base.py +3 -13
- squirrels-0.3.1.dist-info/LICENSE +201 -0
- {squirrels-0.2.2.dist-info → squirrels-0.3.1.dist-info}/METADATA +17 -17
- squirrels-0.3.1.dist-info/RECORD +56 -0
- squirrels/package_data/base_project/database/weather.db +0 -0
- squirrels/package_data/base_project/seeds/mocks/category.csv +0 -3
- squirrels/package_data/base_project/seeds/mocks/max_filter.csv +0 -2
- squirrels/package_data/base_project/seeds/mocks/subcategory.csv +0 -6
- squirrels-0.2.2.dist-info/LICENSE +0 -22
- squirrels-0.2.2.dist-info/RECORD +0 -55
- {squirrels-0.2.2.dist-info → squirrels-0.3.1.dist-info}/WHEEL +0 -0
- {squirrels-0.2.2.dist-info → squirrels-0.3.1.dist-info}/entry_points.txt +0 -0
squirrels/data_sources.py
CHANGED
|
@@ -15,17 +15,19 @@ class DataSource(metaclass=ABCMeta):
|
|
|
15
15
|
"""
|
|
16
16
|
_table_or_query: str
|
|
17
17
|
_id_col: Optional[str]
|
|
18
|
+
_from_seeds: bool
|
|
18
19
|
_user_group_col: Optional[str] # = field(default=None, kw_only=True)
|
|
19
20
|
_parent_id_col: Optional[str] # = field(default=None, kw_only=True)
|
|
20
21
|
_connection_name: Optional[str] # = field(default=None, kw_only=True)
|
|
21
22
|
|
|
22
23
|
@abstractmethod
|
|
23
24
|
def __init__(
|
|
24
|
-
self, table_or_query: str, *, id_col: Optional[str] = None, user_group_col: Optional[str] = None,
|
|
25
|
+
self, table_or_query: str, *, id_col: Optional[str] = None, from_seeds: bool = False, user_group_col: Optional[str] = None,
|
|
25
26
|
parent_id_col: Optional[str] = None, connection_name: Optional[str] = None, **kwargs
|
|
26
27
|
) -> None:
|
|
27
28
|
self._table_or_query = table_or_query
|
|
28
29
|
self._id_col = id_col
|
|
30
|
+
self._from_seeds = from_seeds
|
|
29
31
|
self._user_group_col = user_group_col
|
|
30
32
|
self._parent_id_col = parent_id_col
|
|
31
33
|
self._connection_name = connection_name
|
|
@@ -85,6 +87,9 @@ class DataSource(metaclass=ABCMeta):
|
|
|
85
87
|
def _get_key_from_record_as_list(self, key: Optional[str], record: dict[str, Any]) -> Iterable[str]:
|
|
86
88
|
value = self._get_key_from_record(key, record, list())
|
|
87
89
|
return [str(x) for x in value]
|
|
90
|
+
|
|
91
|
+
def is_from_seed(self) -> bool:
|
|
92
|
+
return self._from_seeds
|
|
88
93
|
|
|
89
94
|
|
|
90
95
|
@dataclass
|
|
@@ -100,11 +105,14 @@ class _SelectionDataSource(DataSource):
|
|
|
100
105
|
@abstractmethod
|
|
101
106
|
def __init__(
|
|
102
107
|
self, table_or_query: str, id_col: str, options_col: str, *, order_by_col: Optional[str] = None,
|
|
103
|
-
is_default_col: Optional[str] = None, custom_cols: dict[str, str] = {},
|
|
104
|
-
parent_id_col: Optional[str] = None, connection_name: Optional[str] = None,
|
|
108
|
+
is_default_col: Optional[str] = None, custom_cols: dict[str, str] = {}, from_seeds: bool = False,
|
|
109
|
+
user_group_col: Optional[str] = None, parent_id_col: Optional[str] = None, connection_name: Optional[str] = None,
|
|
110
|
+
**kwargs
|
|
105
111
|
) -> None:
|
|
106
|
-
super().__init__(
|
|
107
|
-
|
|
112
|
+
super().__init__(
|
|
113
|
+
table_or_query, id_col=id_col, from_seeds=from_seeds, user_group_col=user_group_col, parent_id_col=parent_id_col,
|
|
114
|
+
connection_name=connection_name
|
|
115
|
+
)
|
|
108
116
|
self._options_col = options_col
|
|
109
117
|
self._order_by_col = order_by_col
|
|
110
118
|
self._is_default_col = is_default_col
|
|
@@ -139,9 +147,9 @@ class _SelectionDataSource(DataSource):
|
|
|
139
147
|
|
|
140
148
|
|
|
141
149
|
@dataclass
|
|
142
|
-
class
|
|
150
|
+
class SelectDataSource(_SelectionDataSource):
|
|
143
151
|
"""
|
|
144
|
-
Lookup table for
|
|
152
|
+
Lookup table for select parameter options
|
|
145
153
|
|
|
146
154
|
Attributes:
|
|
147
155
|
table_or_query: Either the name of the table to use, or a query to run
|
|
@@ -150,21 +158,71 @@ class SingleSelectDataSource(_SelectionDataSource):
|
|
|
150
158
|
order_by_col: The column name to order the options by. Orders by the id_col instead if this is None
|
|
151
159
|
is_default_col: The column name that indicates which options are the default
|
|
152
160
|
custom_cols: Dictionary of attribute to column name for custom fields for the SelectParameterOption
|
|
161
|
+
from_seeds: Boolean for whether this datasource is created from seeds
|
|
153
162
|
user_group_col: The column name of the user group that the user is in for this option to be valid
|
|
154
163
|
parent_id_col: The column name of the parent option id that must be selected for this option to be valid
|
|
155
164
|
connection_name: Name of the connection to use defined in connections.py
|
|
156
165
|
"""
|
|
157
166
|
|
|
167
|
+
def __init__(
|
|
168
|
+
self, table_or_query: str, id_col: str, options_col: str, *, order_by_col: Optional[str] = None,
|
|
169
|
+
is_default_col: Optional[str] = None, custom_cols: dict[str, str] = {}, from_seeds: bool = False,
|
|
170
|
+
user_group_col: Optional[str] = None, parent_id_col: Optional[str] = None, connection_name: Optional[str] = None,
|
|
171
|
+
**kwargs
|
|
172
|
+
) -> None:
|
|
173
|
+
"""
|
|
174
|
+
Constructor for SelectDataSource
|
|
175
|
+
|
|
176
|
+
Parameters:
|
|
177
|
+
...see Attributes of SelectDataSource
|
|
178
|
+
"""
|
|
179
|
+
super().__init__(
|
|
180
|
+
table_or_query, id_col, options_col, order_by_col=order_by_col, is_default_col=is_default_col, custom_cols=custom_cols,
|
|
181
|
+
from_seeds=from_seeds, user_group_col=user_group_col, parent_id_col=parent_id_col, connection_name=connection_name
|
|
182
|
+
)
|
|
183
|
+
|
|
184
|
+
def _convert(self, ds_param: pc.DataSourceParameterConfig, df: pd.DataFrame) -> pc.SelectionParameterConfig:
|
|
185
|
+
"""
|
|
186
|
+
Method to convert the associated DataSourceParameter into a SingleSelectParameterConfig or MultiSelectParameterConfig
|
|
187
|
+
|
|
188
|
+
Parameters:
|
|
189
|
+
ds_param: The parameter to convert
|
|
190
|
+
df: The dataframe containing the parameter options data
|
|
191
|
+
|
|
192
|
+
Returns:
|
|
193
|
+
The converted parameter
|
|
194
|
+
"""
|
|
195
|
+
all_options = self._get_all_options(df)
|
|
196
|
+
if ds_param.parameter_type == pc.SingleSelectParameterConfig:
|
|
197
|
+
return pc.SingleSelectParameterConfig(
|
|
198
|
+
ds_param.name, ds_param.label, all_options, description=ds_param.description,
|
|
199
|
+
user_attribute=ds_param.user_attribute, parent_name=ds_param.parent_name
|
|
200
|
+
)
|
|
201
|
+
elif ds_param.parameter_type == pc.MultiSelectParameterConfig:
|
|
202
|
+
return pc.MultiSelectParameterConfig(
|
|
203
|
+
ds_param.name, ds_param.label, all_options, description=ds_param.description,
|
|
204
|
+
user_attribute=ds_param.user_attribute, parent_name=ds_param.parent_name, **ds_param.extra_args
|
|
205
|
+
)
|
|
206
|
+
else:
|
|
207
|
+
raise u.ConfigurationError(f'Invalid widget type "{ds_param.parameter_type}" for SelectDataSource')
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
@dataclass
|
|
211
|
+
class SingleSelectDataSource(_SelectionDataSource):
|
|
212
|
+
"""
|
|
213
|
+
DEPRECATED. Use "SelectDataSource" instead.
|
|
214
|
+
"""
|
|
215
|
+
|
|
158
216
|
def __init__(
|
|
159
217
|
self, table_or_query: str, id_col: str, options_col: str, *, order_by_col: Optional[str] = None,
|
|
160
218
|
is_default_col: Optional[str] = None, custom_cols: dict[str, str] = {}, user_group_col: Optional[str] = None,
|
|
161
219
|
parent_id_col: Optional[str] = None, connection_name: Optional[str] = None, **kwargs
|
|
162
220
|
) -> None:
|
|
163
221
|
"""
|
|
164
|
-
Constructor for
|
|
222
|
+
Constructor for SelectDataSource
|
|
165
223
|
|
|
166
224
|
Parameters:
|
|
167
|
-
...see Attributes of
|
|
225
|
+
...see Attributes of SelectDataSource
|
|
168
226
|
"""
|
|
169
227
|
super().__init__(table_or_query, id_col, options_col, order_by_col=order_by_col, is_default_col=is_default_col,
|
|
170
228
|
custom_cols=custom_cols, user_group_col=user_group_col, parent_id_col=parent_id_col,
|
|
@@ -183,27 +241,13 @@ class SingleSelectDataSource(_SelectionDataSource):
|
|
|
183
241
|
"""
|
|
184
242
|
self._validate_parameter_type(ds_param, pc.SingleSelectParameterConfig)
|
|
185
243
|
all_options = self._get_all_options(df)
|
|
186
|
-
return pc.SingleSelectParameterConfig(ds_param.name, ds_param.label, all_options,
|
|
244
|
+
return pc.SingleSelectParameterConfig(ds_param.name, ds_param.label, all_options, description=ds_param.description,
|
|
187
245
|
user_attribute=ds_param.user_attribute, parent_name=ds_param.parent_name)
|
|
188
246
|
|
|
189
|
-
|
|
190
247
|
@dataclass
|
|
191
248
|
class MultiSelectDataSource(_SelectionDataSource):
|
|
192
249
|
"""
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
Attributes:
|
|
196
|
-
table_or_query: Either the name of the table to use, or a query to run
|
|
197
|
-
id_col: The column name of the id
|
|
198
|
-
options_col: The column name of the options
|
|
199
|
-
order_by_col: The column name to order the options by. Orders by the id_col instead if this is None
|
|
200
|
-
is_default_col: The column name that indicates which options are the default
|
|
201
|
-
custom_cols: Dictionary of attribute to column name for custom fields for the SelectParameterOption
|
|
202
|
-
include_all: Whether applying no selection is equivalent to selecting all. Default is True
|
|
203
|
-
order_matters: Whether the ordering of the selection matters. Default is False
|
|
204
|
-
user_group_col: The column name of the user group that the user is in for this option to be valid
|
|
205
|
-
parent_id_col: The column name of the parent option id that must be selected for this option to be valid
|
|
206
|
-
connection_name: Name of the connection to use defined in connections.py
|
|
250
|
+
DEPRECATED. Use "SelectDataSource" instead.
|
|
207
251
|
"""
|
|
208
252
|
_show_select_all: bool # = field(default=True, kw_only=True)
|
|
209
253
|
_is_dropdown: bool # = field(default=True, kw_only=True)
|
|
@@ -245,7 +289,7 @@ class MultiSelectDataSource(_SelectionDataSource):
|
|
|
245
289
|
all_options = self._get_all_options(df)
|
|
246
290
|
return pc.MultiSelectParameterConfig(
|
|
247
291
|
ds_param.name, ds_param.label, all_options, show_select_all=self._show_select_all, is_dropdown=self._is_dropdown,
|
|
248
|
-
order_matters=self._order_matters, none_is_all=self._none_is_all,
|
|
292
|
+
order_matters=self._order_matters, none_is_all=self._none_is_all, description=ds_param.description,
|
|
249
293
|
user_attribute=ds_param.user_attribute, parent_name=ds_param.parent_name
|
|
250
294
|
)
|
|
251
295
|
|
|
@@ -257,9 +301,10 @@ class DateDataSource(DataSource):
|
|
|
257
301
|
|
|
258
302
|
Attributes:
|
|
259
303
|
table_or_query: Either the name of the table to use, or a query to run
|
|
260
|
-
id_col: The column name of the id
|
|
261
304
|
default_date_col: The column name of the default date
|
|
262
305
|
date_format: The format of the default date(s). Defaults to '%Y-%m-%d'
|
|
306
|
+
id_col: The column name of the id
|
|
307
|
+
from_seeds: Boolean for whether this datasource is created from seeds
|
|
263
308
|
user_group_col: The column name of the user group that the user is in for this option to be valid
|
|
264
309
|
parent_id_col: The column name of the parent option id that the default date belongs to
|
|
265
310
|
connection_name: Name of the connection to use defined in connections.py
|
|
@@ -269,7 +314,8 @@ class DateDataSource(DataSource):
|
|
|
269
314
|
|
|
270
315
|
def __init__(
|
|
271
316
|
self, table_or_query: str, default_date_col: str, *, date_format: str = '%Y-%m-%d', id_col: Optional[str] = None,
|
|
272
|
-
|
|
317
|
+
from_seeds: bool = False, user_group_col: Optional[str] = None, parent_id_col: Optional[str] = None,
|
|
318
|
+
connection_name: Optional[str] = None, **kwargs
|
|
273
319
|
) -> None:
|
|
274
320
|
"""
|
|
275
321
|
Constructor for DateDataSource
|
|
@@ -277,8 +323,10 @@ class DateDataSource(DataSource):
|
|
|
277
323
|
Parameters:
|
|
278
324
|
...see Attributes of DateDataSource
|
|
279
325
|
"""
|
|
280
|
-
super().__init__(
|
|
281
|
-
|
|
326
|
+
super().__init__(
|
|
327
|
+
table_or_query, id_col=id_col, from_seeds=from_seeds, user_group_col=user_group_col, parent_id_col=parent_id_col,
|
|
328
|
+
connection_name=connection_name
|
|
329
|
+
)
|
|
282
330
|
self._default_date_col = default_date_col
|
|
283
331
|
self._date_format = date_format
|
|
284
332
|
|
|
@@ -305,7 +353,7 @@ class DateDataSource(DataSource):
|
|
|
305
353
|
parent_option_ids=self._get_key_from_record_as_list(self._parent_id_col, record))
|
|
306
354
|
for _, record in records.items()
|
|
307
355
|
)
|
|
308
|
-
return pc.DateParameterConfig(ds_param.name, ds_param.label, options,
|
|
356
|
+
return pc.DateParameterConfig(ds_param.name, ds_param.label, options, description=ds_param.description,
|
|
309
357
|
user_attribute=ds_param.user_attribute, parent_name=ds_param.parent_name)
|
|
310
358
|
|
|
311
359
|
|
|
@@ -316,10 +364,11 @@ class DateRangeDataSource(DataSource):
|
|
|
316
364
|
|
|
317
365
|
Attributes:
|
|
318
366
|
table_or_query: Either the name of the table to use, or a query to run
|
|
319
|
-
id_col: The column name of the id
|
|
320
367
|
default_start_date_col: The column name of the default start date
|
|
321
368
|
default_end_date_col: The column name of the default end date
|
|
322
369
|
date_format: The format of the default date(s). Defaults to '%Y-%m-%d'
|
|
370
|
+
id_col: The column name of the id
|
|
371
|
+
from_seeds: Boolean for whether this datasource is created from seeds
|
|
323
372
|
user_group_col: The column name of the user group that the user is in for this option to be valid
|
|
324
373
|
parent_id_col: The column name of the parent option id that the default date belongs to
|
|
325
374
|
connection_name: Name of the connection to use defined in connections.py
|
|
@@ -330,8 +379,8 @@ class DateRangeDataSource(DataSource):
|
|
|
330
379
|
|
|
331
380
|
def __init__(
|
|
332
381
|
self, table_or_query: str, default_start_date_col: str, default_end_date_col: str, *, date_format: str = '%Y-%m-%d',
|
|
333
|
-
id_col: Optional[str] = None,
|
|
334
|
-
connection_name: Optional[str] = None, **kwargs
|
|
382
|
+
id_col: Optional[str] = None, from_seeds: bool = False, user_group_col: Optional[str] = None,
|
|
383
|
+
parent_id_col: Optional[str] = None, connection_name: Optional[str] = None, **kwargs
|
|
335
384
|
) -> None:
|
|
336
385
|
"""
|
|
337
386
|
Constructor for DateRangeDataSource
|
|
@@ -339,8 +388,10 @@ class DateRangeDataSource(DataSource):
|
|
|
339
388
|
Parameters:
|
|
340
389
|
...see Attributes of DateRangeDataSource
|
|
341
390
|
"""
|
|
342
|
-
super().__init__(
|
|
343
|
-
|
|
391
|
+
super().__init__(
|
|
392
|
+
table_or_query, id_col=id_col, from_seeds=from_seeds, user_group_col=user_group_col, parent_id_col=parent_id_col,
|
|
393
|
+
connection_name=connection_name
|
|
394
|
+
)
|
|
344
395
|
self._default_start_date_col = default_start_date_col
|
|
345
396
|
self._default_end_date_col = default_end_date_col
|
|
346
397
|
self._date_format = date_format
|
|
@@ -369,7 +420,7 @@ class DateRangeDataSource(DataSource):
|
|
|
369
420
|
parent_option_ids=self._get_key_from_record_as_list(self._parent_id_col, record))
|
|
370
421
|
for _, record in records.items()
|
|
371
422
|
)
|
|
372
|
-
return pc.DateRangeParameterConfig(ds_param.name, ds_param.label, options,
|
|
423
|
+
return pc.DateRangeParameterConfig(ds_param.name, ds_param.label, options, description=ds_param.description,
|
|
373
424
|
user_attribute=ds_param.user_attribute, parent_name=ds_param.parent_name)
|
|
374
425
|
|
|
375
426
|
|
|
@@ -385,10 +436,13 @@ class _NumericDataSource(DataSource):
|
|
|
385
436
|
@abstractmethod
|
|
386
437
|
def __init__(
|
|
387
438
|
self, table_or_query: str, min_value_col: str, max_value_col: str, *, increment_col: Optional[str] = None,
|
|
388
|
-
id_col: Optional[str] = None,
|
|
389
|
-
connection_name: Optional[str] = None, **kwargs
|
|
439
|
+
id_col: Optional[str] = None, from_seeds: bool = False, user_group_col: Optional[str] = None,
|
|
440
|
+
parent_id_col: Optional[str] = None, connection_name: Optional[str] = None, **kwargs
|
|
390
441
|
) -> None:
|
|
391
|
-
super().__init__(
|
|
442
|
+
super().__init__(
|
|
443
|
+
table_or_query, id_col=id_col, from_seeds=from_seeds, user_group_col=user_group_col, parent_id_col=parent_id_col,
|
|
444
|
+
connection_name=connection_name
|
|
445
|
+
)
|
|
392
446
|
self._min_value_col = min_value_col
|
|
393
447
|
self._max_value_col = max_value_col
|
|
394
448
|
self._increment_col = increment_col
|
|
@@ -401,11 +455,12 @@ class NumberDataSource(_NumericDataSource):
|
|
|
401
455
|
|
|
402
456
|
Attributes:
|
|
403
457
|
table_or_query: Either the name of the table to use, or a query to run
|
|
404
|
-
id_col: The column name of the id
|
|
405
458
|
min_value_col: The column name of the minimum value
|
|
406
459
|
max_value_col: The column name of the maximum value
|
|
407
460
|
increment_col: The column name of the increment value. Defaults to column of 1's if None
|
|
408
461
|
default_value_col: The column name of the default value. Defaults to min_value_col if None
|
|
462
|
+
id_col: The column name of the id
|
|
463
|
+
from_seeds: Boolean for whether this datasource is created from seeds
|
|
409
464
|
user_group_col: The column name of the user group that the user is in for this option to be valid
|
|
410
465
|
parent_id_col: The column name of the parent option id that the default value belongs to
|
|
411
466
|
connection_name: Name of the connection to use defined in connections.py
|
|
@@ -414,8 +469,8 @@ class NumberDataSource(_NumericDataSource):
|
|
|
414
469
|
|
|
415
470
|
def __init__(
|
|
416
471
|
self, table_or_query: str, min_value_col: str, max_value_col: str, *, increment_col: Optional[str] = None,
|
|
417
|
-
default_value_col: Optional[str] = None, id_col: Optional[str] = None,
|
|
418
|
-
parent_id_col: Optional[str] = None, connection_name: Optional[str] = None, **kwargs
|
|
472
|
+
default_value_col: Optional[str] = None, id_col: Optional[str] = None, from_seeds: bool = False,
|
|
473
|
+
user_group_col: Optional[str] = None, parent_id_col: Optional[str] = None, connection_name: Optional[str] = None, **kwargs
|
|
419
474
|
) -> None:
|
|
420
475
|
"""
|
|
421
476
|
Constructor for NumberDataSource
|
|
@@ -423,8 +478,10 @@ class NumberDataSource(_NumericDataSource):
|
|
|
423
478
|
Parameters:
|
|
424
479
|
...see Attributes of NumberDataSource
|
|
425
480
|
"""
|
|
426
|
-
super().__init__(
|
|
427
|
-
|
|
481
|
+
super().__init__(
|
|
482
|
+
table_or_query, min_value_col, max_value_col, increment_col=increment_col, id_col=id_col, from_seeds=from_seeds,
|
|
483
|
+
user_group_col=user_group_col, parent_id_col=parent_id_col, connection_name=connection_name
|
|
484
|
+
)
|
|
428
485
|
self._default_value_col = default_value_col
|
|
429
486
|
|
|
430
487
|
def _convert(self, ds_param: pc.DataSourceParameterConfig, df: pd.DataFrame) -> pc.NumberParameterConfig:
|
|
@@ -452,7 +509,7 @@ class NumberDataSource(_NumericDataSource):
|
|
|
452
509
|
parent_option_ids=self._get_key_from_record_as_list(self._parent_id_col, record))
|
|
453
510
|
for _, record in records.items()
|
|
454
511
|
)
|
|
455
|
-
return pc.NumberParameterConfig(ds_param.name, ds_param.label, options,
|
|
512
|
+
return pc.NumberParameterConfig(ds_param.name, ds_param.label, options, description=ds_param.description,
|
|
456
513
|
user_attribute=ds_param.user_attribute, parent_name=ds_param.parent_name)
|
|
457
514
|
|
|
458
515
|
|
|
@@ -463,12 +520,13 @@ class NumberRangeDataSource(_NumericDataSource):
|
|
|
463
520
|
|
|
464
521
|
Attributes:
|
|
465
522
|
table_or_query: Either the name of the table to use, or a query to
|
|
466
|
-
id_col: The column name of the id
|
|
467
523
|
min_value_col: The column name of the minimum value
|
|
468
524
|
max_value_col: The column name of the maximum value
|
|
469
525
|
increment_col: The column name of the increment value. Defaults to column of 1's if None
|
|
470
526
|
default_lower_value_col: The column name of the default lower value. Defaults to min_value_col if None
|
|
471
527
|
default_upper_value_col: The column name of the default upper value. Defaults to max_value_col if None
|
|
528
|
+
id_col: The column name of the id
|
|
529
|
+
from_seeds: Boolean for whether this datasource is created from seeds
|
|
472
530
|
user_group_col: The column name of the user group that the user is in for this option to be valid
|
|
473
531
|
parent_id_col: The column name of the parent option id that the default value belongs to
|
|
474
532
|
connection_name: Name of the connection to use defined in connections.py
|
|
@@ -479,7 +537,8 @@ class NumberRangeDataSource(_NumericDataSource):
|
|
|
479
537
|
def __init__(
|
|
480
538
|
self, table_or_query: str, min_value_col: str, max_value_col: str, *, increment_col: Optional[str] = None,
|
|
481
539
|
default_lower_value_col: Optional[str] = None, default_upper_value_col: Optional[str] = None, id_col: Optional[str] = None,
|
|
482
|
-
|
|
540
|
+
from_seeds: bool = False, user_group_col: Optional[str] = None, parent_id_col: Optional[str] = None,
|
|
541
|
+
connection_name: Optional[str] = None, **kwargs
|
|
483
542
|
) -> None:
|
|
484
543
|
"""
|
|
485
544
|
Constructor for NumRangeDataSource
|
|
@@ -487,8 +546,10 @@ class NumberRangeDataSource(_NumericDataSource):
|
|
|
487
546
|
Parameters:
|
|
488
547
|
...see Attributes of NumRangeDataSource
|
|
489
548
|
"""
|
|
490
|
-
super().__init__(
|
|
491
|
-
|
|
549
|
+
super().__init__(
|
|
550
|
+
table_or_query, min_value_col, max_value_col, increment_col=increment_col, id_col=id_col, from_seeds=from_seeds,
|
|
551
|
+
user_group_col=user_group_col, parent_id_col=parent_id_col, connection_name=connection_name
|
|
552
|
+
)
|
|
492
553
|
self._default_lower_value_col = default_lower_value_col
|
|
493
554
|
self._default_upper_value_col = default_upper_value_col
|
|
494
555
|
|
|
@@ -518,5 +579,65 @@ class NumberRangeDataSource(_NumericDataSource):
|
|
|
518
579
|
parent_option_ids=self._get_key_from_record_as_list(self._parent_id_col, record))
|
|
519
580
|
for _, record in records.items()
|
|
520
581
|
)
|
|
521
|
-
return pc.NumberRangeParameterConfig(ds_param.name, ds_param.label, options,
|
|
582
|
+
return pc.NumberRangeParameterConfig(ds_param.name, ds_param.label, options, description=ds_param.description,
|
|
522
583
|
user_attribute=ds_param.user_attribute, parent_name=ds_param.parent_name)
|
|
584
|
+
|
|
585
|
+
|
|
586
|
+
@dataclass
|
|
587
|
+
class TextDataSource(DataSource):
|
|
588
|
+
"""
|
|
589
|
+
Lookup table for text parameter default options
|
|
590
|
+
|
|
591
|
+
Attributes:
|
|
592
|
+
table_or_query: Either the name of the table to use, or a query to run
|
|
593
|
+
default_text_col: The column name of the default text
|
|
594
|
+
id_col: The column name of the id
|
|
595
|
+
from_seeds: Boolean for whether this datasource is created from seeds
|
|
596
|
+
user_group_col: The column name of the user group that the user is in for this option to be valid
|
|
597
|
+
parent_id_col: The column name of the parent option id that the default date belongs to
|
|
598
|
+
connection_name: Name of the connection to use defined in connections.py
|
|
599
|
+
"""
|
|
600
|
+
_default_text_col: str
|
|
601
|
+
|
|
602
|
+
def __init__(
|
|
603
|
+
self, table_or_query: str, default_text_col: str, *, id_col: Optional[str] = None, from_seeds: bool = False,
|
|
604
|
+
user_group_col: Optional[str] = None, parent_id_col: Optional[str] = None, connection_name: Optional[str] = None,
|
|
605
|
+
**kwargs
|
|
606
|
+
) -> None:
|
|
607
|
+
"""
|
|
608
|
+
Constructor for DateDataSource
|
|
609
|
+
|
|
610
|
+
Parameters:
|
|
611
|
+
...see Attributes of DateDataSource
|
|
612
|
+
"""
|
|
613
|
+
super().__init__(
|
|
614
|
+
table_or_query, id_col=id_col, from_seeds=from_seeds, user_group_col=user_group_col, parent_id_col=parent_id_col,
|
|
615
|
+
connection_name=connection_name
|
|
616
|
+
)
|
|
617
|
+
self._default_text_col = default_text_col
|
|
618
|
+
|
|
619
|
+
def _convert(self, ds_param: pc.DataSourceParameterConfig, df: pd.DataFrame) -> pc.TextParameterConfig:
|
|
620
|
+
"""
|
|
621
|
+
Method to convert the associated DataSourceParameter into a TextParameterConfig
|
|
622
|
+
|
|
623
|
+
Parameters:
|
|
624
|
+
ds_param: The parameter to convert
|
|
625
|
+
df: The dataframe containing the parameter options data
|
|
626
|
+
|
|
627
|
+
Returns:
|
|
628
|
+
The converted parameter
|
|
629
|
+
"""
|
|
630
|
+
self._validate_parameter_type(ds_param, pc.TextParameterConfig)
|
|
631
|
+
|
|
632
|
+
columns = [self._default_text_col]
|
|
633
|
+
df_agg = self._get_aggregated_df(df, columns)
|
|
634
|
+
|
|
635
|
+
records: dict[str, dict[str, Any]] = df_agg.to_dict("index")
|
|
636
|
+
options = tuple(
|
|
637
|
+
po.TextParameterOption(default_text=str(record[self._default_text_col]),
|
|
638
|
+
user_groups=self._get_key_from_record_as_list(self._user_group_col, record),
|
|
639
|
+
parent_option_ids=self._get_key_from_record_as_list(self._parent_id_col, record))
|
|
640
|
+
for _, record in records.items()
|
|
641
|
+
)
|
|
642
|
+
return pc.TextParameterConfig(ds_param.name, ds_param.label, options, description=ds_param.description,
|
|
643
|
+
user_attribute=ds_param.user_attribute, parent_name=ds_param.parent_name)
|
squirrels/dateutils.py
CHANGED
|
@@ -289,7 +289,7 @@ class DateModPipeline(DateModifier):
|
|
|
289
289
|
incremented by a DateModifier step.
|
|
290
290
|
|
|
291
291
|
If the step is positive and start date is less than end date, then it'll return an increasing list of
|
|
292
|
-
dates starting from the start date. If the step is
|
|
292
|
+
dates starting from the start date. If the step is negative and start date is greater than end date,
|
|
293
293
|
then it'll return a decreasing list of dates starting from the start date. Otherwise, an empty list
|
|
294
294
|
is returned.
|
|
295
295
|
|
|
@@ -379,7 +379,7 @@ class DateStringModifier(_DateRepresentationModifier):
|
|
|
379
379
|
to the modified date, incremented by a DateModifier step.
|
|
380
380
|
|
|
381
381
|
If the step is positive and start date is less than end date, then it'll return an increasing list of
|
|
382
|
-
dates starting from the start date. If the step is
|
|
382
|
+
dates starting from the start date. If the step is negative and start date is greater than end date,
|
|
383
383
|
then it'll return a decreasing list of dates starting from the start date. Otherwise, an empty list
|
|
384
384
|
is returned.
|
|
385
385
|
|
|
@@ -443,7 +443,7 @@ class TimestampModifier(_DateRepresentationModifier):
|
|
|
443
443
|
to the modified date, incremented by a DateModifier step.
|
|
444
444
|
|
|
445
445
|
If the step is positive and start date is less than end date, then it'll return an increasing list of
|
|
446
|
-
dates starting from the start date. If the step is
|
|
446
|
+
dates starting from the start date. If the step is negative and start date is greater than end date,
|
|
447
447
|
then it'll return a decreasing list of dates starting from the start date. Otherwise, an empty list
|
|
448
448
|
is returned.
|
|
449
449
|
|