squirrels 0.3.0__py3-none-any.whl → 0.3.2__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 +1 -1
- squirrels/_api_response_models.py +1 -2
- squirrels/_api_server.py +9 -7
- squirrels/_authenticator.py +2 -2
- squirrels/_connection_set.py +7 -3
- squirrels/_constants.py +2 -1
- squirrels/_environcfg.py +15 -11
- squirrels/_initializer.py +2 -2
- squirrels/_manifest.py +2 -2
- squirrels/_models.py +33 -24
- squirrels/_parameter_configs.py +49 -34
- squirrels/_py_module.py +1 -1
- squirrels/arguments/run_time_args.py +4 -3
- squirrels/data_sources.py +23 -15
- squirrels/package_data/assets/index.css +1 -1
- squirrels/package_data/assets/index.js +13 -13
- squirrels/package_data/base_project/.gitignore +1 -0
- squirrels/package_data/base_project/assets/weather.db +0 -0
- squirrels/package_data/base_project/{environcfg.yml → env.yml} +1 -1
- squirrels/package_data/base_project/models/dbviews/database_view1.sql +4 -5
- squirrels/package_data/base_project/parameters.yml +16 -16
- squirrels/package_data/base_project/pyconfigs/connections.py +1 -1
- squirrels/package_data/base_project/pyconfigs/parameters.py +16 -16
- squirrels/package_data/base_project/squirrels.yml.j2 +1 -1
- squirrels/parameter_options.py +5 -4
- squirrels/parameters.py +179 -62
- {squirrels-0.3.0.dist-info → squirrels-0.3.2.dist-info}/METADATA +3 -3
- {squirrels-0.3.0.dist-info → squirrels-0.3.2.dist-info}/RECORD +32 -32
- squirrels/package_data/base_project/database/weather.db +0 -0
- /squirrels/package_data/base_project/{database → assets}/expenses.db +0 -0
- {squirrels-0.3.0.dist-info → squirrels-0.3.2.dist-info}/LICENSE +0 -0
- {squirrels-0.3.0.dist-info → squirrels-0.3.2.dist-info}/WHEEL +0 -0
- {squirrels-0.3.0.dist-info → squirrels-0.3.2.dist-info}/entry_points.txt +0 -0
|
Binary file
|
|
@@ -11,11 +11,10 @@ transactions_with_masked_id AS (
|
|
|
11
11
|
SELECT {{ ctx.select_dim_cols }}
|
|
12
12
|
, sum(-amount) as total_amount
|
|
13
13
|
FROM transactions_with_masked_id
|
|
14
|
-
WHERE
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
{% if is_placeholder("max_amount") -%} AND -amount <= :max_amount {%- endif %}
|
|
14
|
+
WHERE date >= :start_date
|
|
15
|
+
AND date <= :end_date
|
|
16
|
+
AND -amount >= :min_amount
|
|
17
|
+
AND -amount <= :max_amount
|
|
19
18
|
{% if is_placeholder("desc_pattern") -%} AND description LIKE :desc_pattern {%- endif %}
|
|
20
19
|
{% if ctx.has_categories -%} AND category IN ({{ ctx.categories }}) {%- endif %}
|
|
21
20
|
{% if ctx.has_subcategories -%} AND subcategory IN ({{ ctx.subcategories }}) {%- endif %}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
parameters:
|
|
2
2
|
- type: SingleSelectParameter
|
|
3
|
-
factory:
|
|
3
|
+
factory: CreateWithOptions ## one of 'CreateSimple', 'CreateWithOptions', or 'CreateFromSource'
|
|
4
4
|
arguments: ## arguments to specify depend on values for 'type' and 'factory'
|
|
5
5
|
name: group_by
|
|
6
6
|
label: Group By
|
|
@@ -26,40 +26,40 @@ parameters:
|
|
|
26
26
|
parent_name: null ## optional, default, exists for all parameter types
|
|
27
27
|
|
|
28
28
|
- type: TextParameter
|
|
29
|
-
factory:
|
|
29
|
+
factory: CreateWithOptions
|
|
30
30
|
arguments:
|
|
31
31
|
name: description_filter
|
|
32
32
|
label: Description Contains
|
|
33
|
-
description:
|
|
33
|
+
description: Substring of description to filter transactions by
|
|
34
34
|
parent_name: group_by
|
|
35
35
|
all_options:
|
|
36
36
|
- parent_option_ids: g0
|
|
37
37
|
|
|
38
38
|
- type: DateParameter
|
|
39
|
-
factory:
|
|
39
|
+
factory: CreateWithOptions
|
|
40
40
|
arguments:
|
|
41
41
|
name: start_date
|
|
42
42
|
label: Start Date
|
|
43
|
-
description:
|
|
43
|
+
description: Start date to filter transactions by
|
|
44
44
|
all_options:
|
|
45
45
|
- default_date: 2023-01-01
|
|
46
46
|
date_format: '%Y-%m-%d' ## optional, default, format comes from python datetime, exists for Date and DateRange parameter options
|
|
47
47
|
|
|
48
48
|
- type: DateParameter
|
|
49
|
-
factory:
|
|
49
|
+
factory: CreateWithOptions
|
|
50
50
|
arguments:
|
|
51
51
|
name: end_date
|
|
52
52
|
label: End Date
|
|
53
|
-
description:
|
|
53
|
+
description: End date to filter transactions by
|
|
54
54
|
all_options:
|
|
55
55
|
- default_date: 2023-12-31
|
|
56
56
|
|
|
57
57
|
- type: DateRangeParameter
|
|
58
|
-
factory:
|
|
58
|
+
factory: CreateWithOptions
|
|
59
59
|
arguments:
|
|
60
60
|
name: date_range
|
|
61
61
|
label: Date Range
|
|
62
|
-
description:
|
|
62
|
+
description: Date range to filter transactions by
|
|
63
63
|
all_options:
|
|
64
64
|
- default_start_date: 2023-01-01
|
|
65
65
|
default_end_date: 2023-12-31
|
|
@@ -69,7 +69,7 @@ parameters:
|
|
|
69
69
|
arguments:
|
|
70
70
|
name: category
|
|
71
71
|
label: Category Filter
|
|
72
|
-
description: The expense categories to filter by
|
|
72
|
+
description: The expense categories to filter transactions by
|
|
73
73
|
data_source:
|
|
74
74
|
table_or_query: seed_categories
|
|
75
75
|
id_col: category_id
|
|
@@ -88,7 +88,7 @@ parameters:
|
|
|
88
88
|
arguments:
|
|
89
89
|
name: subcategory
|
|
90
90
|
label: Subcategory Filter
|
|
91
|
-
description: The expense subcategories to filter by (available options based on selected 'Category Filter')
|
|
91
|
+
description: The expense subcategories to filter transactions by (available options are based on selected value(s) of 'Category Filter')
|
|
92
92
|
parent_name: category
|
|
93
93
|
data_source:
|
|
94
94
|
table_or_query: seed_subcategories
|
|
@@ -98,11 +98,11 @@ parameters:
|
|
|
98
98
|
parent_id_col: category_id ## optional, default is null, exists for all parameter types
|
|
99
99
|
|
|
100
100
|
- type: NumberParameter
|
|
101
|
-
factory:
|
|
101
|
+
factory: CreateWithOptions
|
|
102
102
|
arguments:
|
|
103
103
|
name: min_filter
|
|
104
104
|
label: Amounts Greater Than
|
|
105
|
-
description:
|
|
105
|
+
description: Number to filter on transactions with an amount greater than this value
|
|
106
106
|
all_options:
|
|
107
107
|
- min_value: 0
|
|
108
108
|
max_value: 500
|
|
@@ -114,7 +114,7 @@ parameters:
|
|
|
114
114
|
arguments:
|
|
115
115
|
name: max_filter
|
|
116
116
|
label: Amounts Less Than
|
|
117
|
-
description:
|
|
117
|
+
description: Number to filter on transactions with an amount less than this value
|
|
118
118
|
data_source:
|
|
119
119
|
table_or_query: "SELECT 0 as min_value, max(-amount) as max_value, 10 as increment FROM transactions WHERE category <> 'Income'"
|
|
120
120
|
min_value_col: min_value
|
|
@@ -124,11 +124,11 @@ parameters:
|
|
|
124
124
|
id_col: null ## optional, default, required for SingleSelect and MultiSelect, optional for all others
|
|
125
125
|
|
|
126
126
|
- type: NumberRangeParameter
|
|
127
|
-
factory:
|
|
127
|
+
factory: CreateWithOptions
|
|
128
128
|
arguments:
|
|
129
129
|
name: between_filter
|
|
130
130
|
label: Amounts Between
|
|
131
|
-
description:
|
|
131
|
+
description: Number range to filter on transactions with an amount within this range
|
|
132
132
|
all_options:
|
|
133
133
|
- min_value: 0
|
|
134
134
|
max_value: 500
|
|
@@ -8,7 +8,7 @@ def main(connections: dict[str, Engine], sqrl: ConnectionsArgs) -> None:
|
|
|
8
8
|
"""
|
|
9
9
|
|
|
10
10
|
## SQLAlchemy URL for a connection engine
|
|
11
|
-
conn_str = 'sqlite
|
|
11
|
+
conn_str = 'sqlite:///./assets/expenses.db'
|
|
12
12
|
|
|
13
13
|
## Can also leverage environment variables and credentials in the environcfg.yml file for connection details
|
|
14
14
|
# conn_str_raw: str = sqrl.env_vars["sqlite_conn_str"]
|
|
@@ -6,14 +6,14 @@ def main(sqrl: ParametersArgs) -> None:
|
|
|
6
6
|
Create all widget parameters in this file. If two or more datasets use a different set of parameters, define them all
|
|
7
7
|
here, and specify the subset of parameters used for each dataset in the "squirrels.yml" file.
|
|
8
8
|
|
|
9
|
-
Parameters are created by a factory method associated to
|
|
10
|
-
> p.SingleSelectParameter.
|
|
9
|
+
Parameters are created by a factory method associated to the parameter class. For example, "CreateWithOptions" is the factory method used here:
|
|
10
|
+
> p.SingleSelectParameter.CreateWithOptions(...)
|
|
11
11
|
|
|
12
12
|
The parameter classes available are:
|
|
13
13
|
- SingleSelectParameter, MultiSelectParameter, DateParameter, DateRangeParameter, NumberParameter, NumberRangeParameter, TextParameter
|
|
14
14
|
|
|
15
15
|
The factory methods available are:
|
|
16
|
-
-
|
|
16
|
+
- CreateSimple, CreateWithOptions, CreateFromSource
|
|
17
17
|
"""
|
|
18
18
|
|
|
19
19
|
## Example of creating SingleSelectParameter and specifying each option by code
|
|
@@ -23,38 +23,38 @@ def main(sqrl: ParametersArgs) -> None:
|
|
|
23
23
|
po.SelectParameterOption("g2", "Category", columns=["category"]),
|
|
24
24
|
po.SelectParameterOption("g3", "Subcategory", columns=["category", "subcategory"]),
|
|
25
25
|
]
|
|
26
|
-
p.SingleSelectParameter.
|
|
27
|
-
"group_by", "Group By", group_by_options, description="Dimension to aggregate by"
|
|
26
|
+
p.SingleSelectParameter.CreateWithOptions(
|
|
27
|
+
"group_by", "Group By", group_by_options, description="Dimension(s) to aggregate by"
|
|
28
28
|
)
|
|
29
29
|
|
|
30
30
|
## Example of creating a TextParameter
|
|
31
31
|
parent_name = "group_by"
|
|
32
32
|
text_options = [po.TextParameterOption(parent_option_ids="g0")]
|
|
33
|
-
p.TextParameter.
|
|
33
|
+
p.TextParameter.CreateWithOptions(
|
|
34
34
|
"description_filter", "Description Contains", text_options, parent_name=parent_name,
|
|
35
|
-
description="
|
|
35
|
+
description="Substring of description to filter transactions by"
|
|
36
36
|
)
|
|
37
37
|
|
|
38
38
|
## Example of creating DateParameter
|
|
39
39
|
p.DateParameter.CreateSimple(
|
|
40
|
-
"start_date", "Start Date", "2023-01-01", description="
|
|
40
|
+
"start_date", "Start Date", "2023-01-01", description="Start date to filter transactions by"
|
|
41
41
|
)
|
|
42
42
|
|
|
43
43
|
## Example of creating DateParameter from list of DateParameterOption's
|
|
44
44
|
end_date_option = [po.DateParameterOption("2023-12-31")]
|
|
45
|
-
p.DateParameter.
|
|
46
|
-
"end_date", "End Date", end_date_option, description="
|
|
45
|
+
p.DateParameter.CreateWithOptions(
|
|
46
|
+
"end_date", "End Date", end_date_option, description="End date to filter transactions by"
|
|
47
47
|
)
|
|
48
48
|
|
|
49
49
|
## Example of creating DateRangeParameter
|
|
50
50
|
p.DateRangeParameter.CreateSimple(
|
|
51
|
-
"date_range", "Date Range", "2023-01-01", "2023-12-31", description="
|
|
51
|
+
"date_range", "Date Range", "2023-01-01", "2023-12-31", description="Date range to filter transactions by"
|
|
52
52
|
)
|
|
53
53
|
|
|
54
54
|
## Example of creating MultiSelectParameter from lookup query/table
|
|
55
55
|
category_ds = ds.SelectDataSource("seed_categories", "category_id", "category", from_seeds=True)
|
|
56
56
|
p.MultiSelectParameter.CreateFromSource(
|
|
57
|
-
"category", "Category Filter", category_ds, description="The expense categories to filter by"
|
|
57
|
+
"category", "Category Filter", category_ds, description="The expense categories to filter transactions by"
|
|
58
58
|
)
|
|
59
59
|
|
|
60
60
|
## Example of creating MultiSelectParameter with parent from lookup query/table
|
|
@@ -64,24 +64,24 @@ def main(sqrl: ParametersArgs) -> None:
|
|
|
64
64
|
)
|
|
65
65
|
p.MultiSelectParameter.CreateFromSource(
|
|
66
66
|
"subcategory", "Subcategory Filter", subcategory_ds, parent_name=parent_name,
|
|
67
|
-
description="The expense subcategories to filter by (available options based on selected 'Category Filter')"
|
|
67
|
+
description="The expense subcategories to filter transactions by (available options are based on selected value(s) of 'Category Filter')"
|
|
68
68
|
)
|
|
69
69
|
|
|
70
70
|
## Example of creating NumberParameter
|
|
71
71
|
p.NumberParameter.CreateSimple(
|
|
72
72
|
"min_filter", "Amounts Greater Than", min_value=0, max_value=500, increment=10,
|
|
73
|
-
description="
|
|
73
|
+
description="Number to filter on transactions with an amount greater than this value"
|
|
74
74
|
)
|
|
75
75
|
|
|
76
76
|
## Example of creating NumberParameter from lookup query/table
|
|
77
77
|
query = "SELECT 0 as min_value, max(-amount) as max_value, 10 as increment FROM transactions WHERE category <> 'Income'"
|
|
78
78
|
max_amount_ds = ds.NumberDataSource(query, "min_value", "max_value", increment_col="increment", default_value_col="max_value")
|
|
79
79
|
p.NumberParameter.CreateFromSource(
|
|
80
|
-
"max_filter", "Amounts Less Than", max_amount_ds, description="
|
|
80
|
+
"max_filter", "Amounts Less Than", max_amount_ds, description="Number to filter on transactions with an amount less than this value"
|
|
81
81
|
)
|
|
82
82
|
|
|
83
83
|
## Example of creating NumberRangeParameter
|
|
84
84
|
p.NumberRangeParameter.CreateSimple(
|
|
85
85
|
"between_filter", "Amounts Between", 0, 500, default_lower_value=10, default_upper_value=400,
|
|
86
|
-
description="
|
|
86
|
+
description="Number range to filter on transactions with an amount within this range"
|
|
87
87
|
)
|
|
@@ -51,7 +51,7 @@ selection_test_sets:
|
|
|
51
51
|
- name: no_auth_test1
|
|
52
52
|
datasets: ## optional section - if not provided, then test set is applicable for any dataset
|
|
53
53
|
- dataset_example
|
|
54
|
-
parameters: ## optional section -
|
|
54
|
+
parameters: ## optional section - if not provided, then assumes no parameters. For unspecified parameters, default value is used
|
|
55
55
|
start_date: 2023-07-01 ## this parameter only exists for dataset 'dataset_example'
|
|
56
56
|
|
|
57
57
|
- name: auth_test1
|
squirrels/parameter_options.py
CHANGED
|
@@ -3,6 +3,7 @@ from dataclasses import dataclass, field
|
|
|
3
3
|
from decimal import Decimal, InvalidOperation as InvalidDecimalConversion
|
|
4
4
|
from datetime import datetime, date
|
|
5
5
|
from abc import ABCMeta, abstractmethod
|
|
6
|
+
import re
|
|
6
7
|
|
|
7
8
|
from ._utils import ConfigurationError
|
|
8
9
|
|
|
@@ -214,9 +215,9 @@ class _NumericParameterOption(ParameterOption):
|
|
|
214
215
|
) -> None:
|
|
215
216
|
super().__init__(user_groups=user_groups, parent_option_ids=parent_option_ids)
|
|
216
217
|
try:
|
|
217
|
-
self._min_value = Decimal(min_value)
|
|
218
|
-
self._max_value = Decimal(max_value)
|
|
219
|
-
self._increment = Decimal(increment)
|
|
218
|
+
self._min_value = Decimal(str(min_value))
|
|
219
|
+
self._max_value = Decimal(str(max_value))
|
|
220
|
+
self._increment = Decimal(str(increment))
|
|
220
221
|
except InvalidDecimalConversion as e:
|
|
221
222
|
raise ConfigurationError(f'Could not convert either min, max, or increment to number') from e
|
|
222
223
|
|
|
@@ -235,7 +236,7 @@ class _NumericParameterOption(ParameterOption):
|
|
|
235
236
|
|
|
236
237
|
def _validate_value(self, value: Number) -> Decimal:
|
|
237
238
|
try:
|
|
238
|
-
value = Decimal(value)
|
|
239
|
+
value = Decimal(str(value))
|
|
239
240
|
except InvalidDecimalConversion as e:
|
|
240
241
|
raise ConfigurationError(f'Could not convert "{value}" to number', e)
|
|
241
242
|
|