squirrels 0.5.0b2__py3-none-any.whl → 0.5.0b4__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.
- dateutils/__init__.py +6 -460
- dateutils/_enums.py +25 -0
- dateutils/_implementation.py +409 -0
- dateutils/types.py +6 -0
- squirrels/__init__.py +9 -13
- squirrels/_api_routes/__init__.py +5 -0
- squirrels/_api_routes/auth.py +262 -0
- squirrels/_api_routes/base.py +154 -0
- squirrels/_api_routes/dashboards.py +142 -0
- squirrels/_api_routes/data_management.py +103 -0
- squirrels/_api_routes/datasets.py +242 -0
- squirrels/_api_routes/oauth2.py +300 -0
- squirrels/_api_routes/project.py +214 -0
- squirrels/_api_server.py +145 -748
- squirrels/_arguments/__init__.py +0 -0
- squirrels/{arguments → _arguments}/init_time_args.py +7 -2
- squirrels/{arguments → _arguments}/run_time_args.py +4 -26
- squirrels/_auth.py +646 -93
- squirrels/_connection_set.py +5 -5
- squirrels/_constants.py +7 -1
- squirrels/{_dashboards_io.py → _dashboards.py} +87 -6
- squirrels/_data_sources.py +564 -0
- squirrels/_exceptions.py +9 -37
- squirrels/_initializer.py +31 -26
- squirrels/_manifest.py +5 -5
- squirrels/_model_builder.py +1 -1
- squirrels/_model_configs.py +2 -2
- squirrels/_model_queries.py +1 -1
- squirrels/_models.py +40 -27
- squirrels/{package_data → _package_data}/base_project/.env +1 -0
- squirrels/{package_data → _package_data}/base_project/.env.example +1 -0
- squirrels/{package_data → _package_data}/base_project/dashboards/dashboard_example.py +4 -4
- squirrels/{package_data → _package_data}/base_project/dashboards/dashboard_example.yml +2 -2
- squirrels/_package_data/base_project/macros/macros_example.sql +17 -0
- squirrels/{package_data → _package_data}/base_project/models/builds/build_example.py +2 -2
- squirrels/{package_data → _package_data}/base_project/models/builds/build_example.sql +1 -1
- squirrels/{package_data → _package_data}/base_project/models/dbviews/dbview_example.sql +1 -1
- squirrels/_package_data/base_project/models/federates/federate_example.py +41 -0
- squirrels/_package_data/base_project/models/federates/federate_example.sql +25 -0
- squirrels/{package_data → _package_data}/base_project/models/federates/federate_example.yml +6 -6
- squirrels/{package_data → _package_data}/base_project/parameters.yml +9 -8
- squirrels/_package_data/base_project/pyconfigs/connections.py +14 -0
- squirrels/{package_data → _package_data}/base_project/pyconfigs/context.py +14 -16
- squirrels/_package_data/base_project/pyconfigs/parameters.py +106 -0
- squirrels/_package_data/base_project/pyconfigs/user.py +51 -0
- squirrels/_package_data/templates/dataset_results.html +112 -0
- squirrels/_package_data/templates/oauth_login.html +271 -0
- squirrels/_parameter_configs.py +35 -35
- squirrels/_parameter_options.py +348 -0
- squirrels/_parameter_sets.py +47 -37
- squirrels/_parameters.py +1664 -0
- squirrels/_project.py +76 -32
- squirrels/_py_module.py +3 -2
- squirrels/_schemas/__init__.py +0 -0
- squirrels/_schemas/auth_models.py +144 -0
- squirrels/_schemas/query_param_models.py +67 -0
- squirrels/{_api_response_models.py → _schemas/response_models.py} +12 -8
- squirrels/_utils.py +38 -4
- squirrels/arguments.py +2 -0
- squirrels/auth.py +1 -0
- squirrels/connections.py +1 -0
- squirrels/dashboards.py +1 -82
- squirrels/data_sources.py +8 -563
- squirrels/parameter_options.py +8 -348
- squirrels/parameters.py +9 -1266
- squirrels/types.py +11 -0
- {squirrels-0.5.0b2.dist-info → squirrels-0.5.0b4.dist-info}/METADATA +4 -1
- squirrels-0.5.0b4.dist-info/RECORD +94 -0
- squirrels/package_data/base_project/macros/macros_example.sql +0 -15
- squirrels/package_data/base_project/models/federates/federate_example.py +0 -44
- squirrels/package_data/base_project/models/federates/federate_example.sql +0 -17
- squirrels/package_data/base_project/pyconfigs/connections.py +0 -14
- squirrels/package_data/base_project/pyconfigs/parameters.py +0 -93
- squirrels/package_data/base_project/pyconfigs/user.py +0 -23
- squirrels-0.5.0b2.dist-info/RECORD +0 -70
- /squirrels/{dataset_result.py → _dataset_types.py} +0 -0
- /squirrels/{package_data → _package_data}/base_project/assets/expenses.db +0 -0
- /squirrels/{package_data → _package_data}/base_project/assets/weather.db +0 -0
- /squirrels/{package_data → _package_data}/base_project/connections.yml +0 -0
- /squirrels/{package_data → _package_data}/base_project/docker/.dockerignore +0 -0
- /squirrels/{package_data → _package_data}/base_project/docker/Dockerfile +0 -0
- /squirrels/{package_data → _package_data}/base_project/docker/compose.yml +0 -0
- /squirrels/{package_data → _package_data}/base_project/duckdb_init.sql +0 -0
- /squirrels/{package_data/base_project/.gitignore → _package_data/base_project/gitignore} +0 -0
- /squirrels/{package_data → _package_data}/base_project/models/builds/build_example.yml +0 -0
- /squirrels/{package_data → _package_data}/base_project/models/dbviews/dbview_example.yml +0 -0
- /squirrels/{package_data → _package_data}/base_project/models/sources.yml +0 -0
- /squirrels/{package_data → _package_data}/base_project/seeds/seed_categories.csv +0 -0
- /squirrels/{package_data → _package_data}/base_project/seeds/seed_categories.yml +0 -0
- /squirrels/{package_data → _package_data}/base_project/seeds/seed_subcategories.csv +0 -0
- /squirrels/{package_data → _package_data}/base_project/seeds/seed_subcategories.yml +0 -0
- /squirrels/{package_data → _package_data}/base_project/squirrels.yml.j2 +0 -0
- /squirrels/{package_data → _package_data}/base_project/tmp/.gitignore +0 -0
- {squirrels-0.5.0b2.dist-info → squirrels-0.5.0b4.dist-info}/WHEEL +0 -0
- {squirrels-0.5.0b2.dist-info → squirrels-0.5.0b4.dist-info}/entry_points.txt +0 -0
- {squirrels-0.5.0b2.dist-info → squirrels-0.5.0b4.dist-info}/licenses/LICENSE +0 -0
|
@@ -0,0 +1,409 @@
|
|
|
1
|
+
from typing import Sequence, Type
|
|
2
|
+
from dataclasses import dataclass
|
|
3
|
+
from datetime import date as Date, datetime
|
|
4
|
+
from dateutil.relativedelta import relativedelta
|
|
5
|
+
from abc import ABCMeta, abstractmethod
|
|
6
|
+
|
|
7
|
+
from ._enums import DayOfWeekEnum, MonthEnum
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class DateModifier(metaclass=ABCMeta):
|
|
11
|
+
"""
|
|
12
|
+
Interface for all Date modification classes, and declares a "modify" method
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
@abstractmethod
|
|
16
|
+
def modify(self, date: Date) -> Date:
|
|
17
|
+
"""
|
|
18
|
+
Method to be overwritten, modifies the input date
|
|
19
|
+
|
|
20
|
+
Arguments:
|
|
21
|
+
date: The input date to modify.
|
|
22
|
+
|
|
23
|
+
Returns:
|
|
24
|
+
The modified date.
|
|
25
|
+
"""
|
|
26
|
+
pass
|
|
27
|
+
|
|
28
|
+
def _get_date(self, datetype: Type, year: int, month: int, day: int) -> Date:
|
|
29
|
+
return datetype(year, month, day)
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
@dataclass
|
|
33
|
+
class DayIdxOfCalendarUnit(DateModifier):
|
|
34
|
+
"""
|
|
35
|
+
Interface for adjusting a date to some day of calendar unit
|
|
36
|
+
"""
|
|
37
|
+
idx: int
|
|
38
|
+
|
|
39
|
+
def __post_init__(self) -> None:
|
|
40
|
+
if self.idx == 0:
|
|
41
|
+
raise ValueError(f"For constructors of class names that start with DayIdxOf_, idx cannot be zero")
|
|
42
|
+
self.incr = self.idx - 1 if self.idx > 0 else self.idx
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
@dataclass
|
|
46
|
+
class DayIdxOfMonthsCycle(DayIdxOfCalendarUnit):
|
|
47
|
+
"""
|
|
48
|
+
DateModifier class to get the idx-th day of a cycle of months for an input date
|
|
49
|
+
|
|
50
|
+
Attributes:
|
|
51
|
+
idx: 1 for first, 2 for second, etc. Or, -1 for last, -2 for second last, etc. Must not be 0
|
|
52
|
+
num_months_in_cycle: 2 for one 6th of year, 3 for Quarter, 4 for one 3rd of year, 6 for half year, 12 for full year. Must fit evenly in 12
|
|
53
|
+
first_month_of_cycle: The first month of months cycle of year. Default is January
|
|
54
|
+
"""
|
|
55
|
+
num_months_in_cycle: int
|
|
56
|
+
first_month_of_cycle: MonthEnum = MonthEnum.January
|
|
57
|
+
|
|
58
|
+
def __post_init__(self) -> None:
|
|
59
|
+
super().__post_init__()
|
|
60
|
+
if 12 % self.num_months_in_cycle != 0:
|
|
61
|
+
raise ValueError(f"Argument 'num_months_in_cycle' must fit evenly in 12")
|
|
62
|
+
self.first_month_of_first_cycle = (self.first_month_of_cycle.value - 1) % self.num_months_in_cycle + 1
|
|
63
|
+
|
|
64
|
+
def modify(self, date: Date) -> Date:
|
|
65
|
+
current_cycle = (date.month - self.first_month_of_first_cycle) % 12 // self.num_months_in_cycle
|
|
66
|
+
first_month_of_curr_cycle = current_cycle * self.num_months_in_cycle + self.first_month_of_first_cycle
|
|
67
|
+
year = date.year if date.month >= first_month_of_curr_cycle else date.year - 1
|
|
68
|
+
first_day = self._get_date(type(date), year, first_month_of_curr_cycle, 1)
|
|
69
|
+
ref_date = first_day if self.idx > 0 else first_day + relativedelta(months=self.num_months_in_cycle)
|
|
70
|
+
return ref_date + relativedelta(days=self.incr)
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
@dataclass
|
|
74
|
+
class DayIdxOfYear(DayIdxOfMonthsCycle):
|
|
75
|
+
"""
|
|
76
|
+
DateModifier class to get the idx-th day of year of an input date
|
|
77
|
+
|
|
78
|
+
Attributes:
|
|
79
|
+
idx: 1 for first, 2 for second, etc. Or, -1 for last, -2 for second last, etc. Must not be 0
|
|
80
|
+
first_month_of_year: The first month of year. Default is January
|
|
81
|
+
"""
|
|
82
|
+
|
|
83
|
+
def __init__(self, idx: int, first_month_of_year: MonthEnum = MonthEnum.January):
|
|
84
|
+
super().__init__(idx, num_months_in_cycle=12, first_month_of_cycle=first_month_of_year)
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
@dataclass
|
|
88
|
+
class DayIdxOfQuarter(DayIdxOfMonthsCycle):
|
|
89
|
+
"""
|
|
90
|
+
DateModifier class to get the idx-th day of quarter of an input date
|
|
91
|
+
|
|
92
|
+
Attributes:
|
|
93
|
+
idx: 1 for first, 2 for second, etc. Or, -1 for last, -2 for second last, etc. Must not be 0
|
|
94
|
+
first_month_of_quarter: The first month of first quarter. Default is January
|
|
95
|
+
"""
|
|
96
|
+
|
|
97
|
+
def __init__(self, idx: int, first_month_of_quarter: MonthEnum = MonthEnum.January):
|
|
98
|
+
super().__init__(idx, num_months_in_cycle=3, first_month_of_cycle=first_month_of_quarter)
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
@dataclass
|
|
102
|
+
class DayIdxOfMonth(DayIdxOfCalendarUnit):
|
|
103
|
+
"""
|
|
104
|
+
DateModifier class to get the idx-th day of month of an input date
|
|
105
|
+
|
|
106
|
+
Attributes:
|
|
107
|
+
idx: 1 for first, 2 for second, etc. Or, -1 for last, -2 for second last, etc. Must not be 0
|
|
108
|
+
"""
|
|
109
|
+
|
|
110
|
+
def modify(self, date: Date) -> Date:
|
|
111
|
+
first_day = self._get_date(type(date), date.year, date.month, 1)
|
|
112
|
+
ref_date = first_day if self.idx > 0 else first_day + relativedelta(months=1)
|
|
113
|
+
return ref_date + relativedelta(days=self.incr)
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
@dataclass
|
|
117
|
+
class DayIdxOfWeek(DayIdxOfCalendarUnit):
|
|
118
|
+
"""
|
|
119
|
+
DateModifier class to get the idx-th day of week of an input date
|
|
120
|
+
|
|
121
|
+
Attributes:
|
|
122
|
+
idx: 1 for first, 2 for second, etc. Or, -1 for last, -2 for second last, etc. Must not be 0
|
|
123
|
+
first_day_of_week: The day of week identified as the "first". Default is Monday
|
|
124
|
+
"""
|
|
125
|
+
first_day_of_week: DayOfWeekEnum = DayOfWeekEnum.Monday
|
|
126
|
+
|
|
127
|
+
def __post_init__(self) -> None:
|
|
128
|
+
super().__post_init__()
|
|
129
|
+
self.first_dow_num = self.first_day_of_week.value
|
|
130
|
+
|
|
131
|
+
def modify(self, date: Date) -> Date:
|
|
132
|
+
distance_from_first_day = (1 + date.weekday() - self.first_dow_num) % 7
|
|
133
|
+
total_incr = -distance_from_first_day + (7 if self.idx < 0 else 0) + self.incr
|
|
134
|
+
return date + relativedelta(days=total_incr)
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
@dataclass
|
|
138
|
+
class OffsetUnits(DateModifier):
|
|
139
|
+
"""
|
|
140
|
+
Abstract DateModifier class to offset an input date by some number of some calendar unit
|
|
141
|
+
"""
|
|
142
|
+
offset: int
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
@dataclass
|
|
146
|
+
class OffsetYears(OffsetUnits):
|
|
147
|
+
"""
|
|
148
|
+
DateModifier class to offset an input date by some number of years
|
|
149
|
+
|
|
150
|
+
Attributes:
|
|
151
|
+
offset: The number of years to offset the input date.
|
|
152
|
+
"""
|
|
153
|
+
|
|
154
|
+
def modify(self, date: Date) -> Date:
|
|
155
|
+
return date + relativedelta(years=self.offset)
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
@dataclass
|
|
159
|
+
class OffsetMonths(OffsetUnits):
|
|
160
|
+
"""
|
|
161
|
+
DateModifier class to offset an input date by some number of months
|
|
162
|
+
|
|
163
|
+
Attributes:
|
|
164
|
+
offset: The number of months to offset the input date.
|
|
165
|
+
"""
|
|
166
|
+
|
|
167
|
+
def modify(self, date: Date) -> Date:
|
|
168
|
+
return date + relativedelta(months=self.offset)
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
@dataclass
|
|
172
|
+
class OffsetWeeks(OffsetUnits):
|
|
173
|
+
"""
|
|
174
|
+
DateModifier class to offset an input date by some number of weeks
|
|
175
|
+
|
|
176
|
+
Attributes:
|
|
177
|
+
offset: The number of weeks to offset the input date.
|
|
178
|
+
"""
|
|
179
|
+
|
|
180
|
+
def modify(self, date: Date) -> Date:
|
|
181
|
+
return date + relativedelta(weeks=self.offset)
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
@dataclass
|
|
185
|
+
class OffsetDays(OffsetUnits):
|
|
186
|
+
"""
|
|
187
|
+
DateModifier class to offset an input date by some number of days
|
|
188
|
+
|
|
189
|
+
Attributes:
|
|
190
|
+
offset: The number of days to offset the input date.
|
|
191
|
+
"""
|
|
192
|
+
|
|
193
|
+
def modify(self, date: Date) -> Date:
|
|
194
|
+
return date + relativedelta(days=self.offset)
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
@dataclass
|
|
198
|
+
class DateModPipeline(DateModifier):
|
|
199
|
+
"""
|
|
200
|
+
DateModifier class to apply a list of date modifiers to an input date
|
|
201
|
+
|
|
202
|
+
Attributes:
|
|
203
|
+
modifiers: The list of DateModifier's to apply in sequence.
|
|
204
|
+
"""
|
|
205
|
+
date_modifiers: Sequence[DateModifier]
|
|
206
|
+
|
|
207
|
+
def modify(self, date: Date) -> Date:
|
|
208
|
+
for modifier in self.date_modifiers:
|
|
209
|
+
date = modifier.modify(date)
|
|
210
|
+
return date
|
|
211
|
+
|
|
212
|
+
def get_joined_modifiers(self, date_modifiers: Sequence[DateModifier]) -> Sequence[DateModifier]:
|
|
213
|
+
"""
|
|
214
|
+
Create a new sequence of DateModifier by joining the date modifiers in this class
|
|
215
|
+
with the input date_modifiers
|
|
216
|
+
|
|
217
|
+
Arguments:
|
|
218
|
+
date_modifiers: The new date modifier sequence to join
|
|
219
|
+
|
|
220
|
+
Returns:
|
|
221
|
+
A new sequence of DateModifier
|
|
222
|
+
"""
|
|
223
|
+
joined_modifiers = tuple(self.date_modifiers) + tuple(date_modifiers)
|
|
224
|
+
return joined_modifiers
|
|
225
|
+
|
|
226
|
+
def with_more_modifiers(self, date_modifiers: Sequence[DateModifier]):
|
|
227
|
+
"""
|
|
228
|
+
Create a new DateModPipeline with more date modifiers
|
|
229
|
+
|
|
230
|
+
Arguments:
|
|
231
|
+
date_modifiers: The additional date modifiers to add
|
|
232
|
+
|
|
233
|
+
Returns:
|
|
234
|
+
A new DateModPipeline
|
|
235
|
+
"""
|
|
236
|
+
joined_modifiers = self.get_joined_modifiers(date_modifiers)
|
|
237
|
+
return DateModPipeline(joined_modifiers)
|
|
238
|
+
|
|
239
|
+
def get_date_list(self, start_date: Date, step: DateModifier) -> Sequence[Date]:
|
|
240
|
+
"""
|
|
241
|
+
This method modifies the input date, and returns all dates from the input date to the modified date,
|
|
242
|
+
incremented by a DateModifier step.
|
|
243
|
+
|
|
244
|
+
If the step is positive and start date is less than end date, then it'll return an increasing list of
|
|
245
|
+
dates starting from the start date. If the step is negative and start date is greater than end date,
|
|
246
|
+
then it'll return a decreasing list of dates starting from the start date. Otherwise, an empty list
|
|
247
|
+
is returned.
|
|
248
|
+
|
|
249
|
+
Arguments:
|
|
250
|
+
start_date: The input date (it's the first date in the output list if step moves towards end date)
|
|
251
|
+
step: The increment to take (specified as an offset DateModifier). Offset cannot be zero
|
|
252
|
+
|
|
253
|
+
Returns:
|
|
254
|
+
A list of datetime objects
|
|
255
|
+
"""
|
|
256
|
+
assert isinstance(step, OffsetUnits)
|
|
257
|
+
if step.offset == 0:
|
|
258
|
+
raise ValueError(f"The length of 'step' must not be zero")
|
|
259
|
+
|
|
260
|
+
output: Sequence[Date] = []
|
|
261
|
+
end_date = self.modify(start_date)
|
|
262
|
+
curr_date = start_date
|
|
263
|
+
is_not_done_positive_step = lambda: curr_date <= end_date and step.offset > 0
|
|
264
|
+
is_not_done_negative_step = lambda: curr_date >= end_date and step.offset < 0
|
|
265
|
+
while is_not_done_positive_step() or is_not_done_negative_step():
|
|
266
|
+
output.append(curr_date)
|
|
267
|
+
curr_date = step.modify(curr_date)
|
|
268
|
+
return output
|
|
269
|
+
|
|
270
|
+
|
|
271
|
+
@dataclass
|
|
272
|
+
class DateRepresentationModifier(metaclass=ABCMeta):
|
|
273
|
+
"""
|
|
274
|
+
Abstract class for modifying other representations of dates (such as string or unix timestemp)
|
|
275
|
+
"""
|
|
276
|
+
date_modifiers: Sequence[DateModifier]
|
|
277
|
+
|
|
278
|
+
def __post_init__(self) -> None:
|
|
279
|
+
self.date_mod_pipeline = DateModPipeline(self.date_modifiers)
|
|
280
|
+
|
|
281
|
+
@abstractmethod
|
|
282
|
+
def with_more_modifiers(self, date_modifiers: Sequence[DateModifier]):
|
|
283
|
+
pass
|
|
284
|
+
|
|
285
|
+
|
|
286
|
+
@dataclass
|
|
287
|
+
class DateStringModifier(DateRepresentationModifier):
|
|
288
|
+
"""
|
|
289
|
+
Class to modify a string representation of a date given a DateModifier
|
|
290
|
+
|
|
291
|
+
Attributes:
|
|
292
|
+
date_modifier: The DateModifier to apply on datetime objects
|
|
293
|
+
date_format: Format of the output date string. Default is '%Y-%m-%d'
|
|
294
|
+
"""
|
|
295
|
+
date_format: str = '%Y-%m-%d'
|
|
296
|
+
|
|
297
|
+
def with_more_modifiers(self, date_modifiers: Sequence[DateModifier]):
|
|
298
|
+
"""
|
|
299
|
+
Create a new DateStringModifier with more date modifiers
|
|
300
|
+
|
|
301
|
+
Arguments:
|
|
302
|
+
date_modifiers: The additional date modifiers to add
|
|
303
|
+
|
|
304
|
+
Returns:
|
|
305
|
+
A new DateStringModifier
|
|
306
|
+
"""
|
|
307
|
+
joined_modifiers = self.date_mod_pipeline.get_joined_modifiers(date_modifiers)
|
|
308
|
+
return DateStringModifier(joined_modifiers, self.date_format)
|
|
309
|
+
|
|
310
|
+
def _get_input_date_obj(self, date_str: str, input_format: str | None = None) -> Date:
|
|
311
|
+
input_format = self.date_format if input_format is None else input_format
|
|
312
|
+
return datetime.strptime(date_str, input_format).date()
|
|
313
|
+
|
|
314
|
+
def modify(self, date_str: str, input_format: str | None = None) -> str:
|
|
315
|
+
"""
|
|
316
|
+
Modifies the input date string with the date modifiers
|
|
317
|
+
|
|
318
|
+
Arguments:
|
|
319
|
+
date_str: The input date string
|
|
320
|
+
input_format: The input date format. Defaults to the same as output date format
|
|
321
|
+
|
|
322
|
+
Returns:
|
|
323
|
+
The resulting date string
|
|
324
|
+
"""
|
|
325
|
+
date_obj = self._get_input_date_obj(date_str, input_format)
|
|
326
|
+
return self.date_mod_pipeline.modify(date_obj).strftime(self.date_format)
|
|
327
|
+
|
|
328
|
+
def get_date_list(self, start_date_str: str, step: DateModifier, input_format: str | None = None) -> Sequence[str]:
|
|
329
|
+
"""
|
|
330
|
+
This method modifies the input date string, and returns all dates as strings from the input date
|
|
331
|
+
to the modified date, incremented by a DateModifier step.
|
|
332
|
+
|
|
333
|
+
If the step is positive and start date is less than end date, then it'll return an increasing list of
|
|
334
|
+
dates starting from the start date. If the step is negative and start date is greater than end date,
|
|
335
|
+
then it'll return a decreasing list of dates starting from the start date. Otherwise, an empty list
|
|
336
|
+
is returned.
|
|
337
|
+
|
|
338
|
+
Arguments:
|
|
339
|
+
start_date_str: The input date string (it's the first date in the output list if step moves towards end date)
|
|
340
|
+
step: The increment to take (specified as an offset DateModifier). Offset cannot be zero
|
|
341
|
+
input_format: The input date format. Defaults to the same as output date format
|
|
342
|
+
|
|
343
|
+
Returns:
|
|
344
|
+
A list of date strings
|
|
345
|
+
"""
|
|
346
|
+
assert isinstance(step, OffsetUnits)
|
|
347
|
+
curr_date = self._get_input_date_obj(start_date_str, input_format)
|
|
348
|
+
output = self.date_mod_pipeline.get_date_list(curr_date, step)
|
|
349
|
+
return [x.strftime(self.date_format) for x in output]
|
|
350
|
+
|
|
351
|
+
|
|
352
|
+
@dataclass
|
|
353
|
+
class TimestampModifier(DateRepresentationModifier):
|
|
354
|
+
"""
|
|
355
|
+
Class to modify a numeric representation of a date (as Unix/Epoch/POSIX timestamp) given a DateModifier
|
|
356
|
+
|
|
357
|
+
Attributes:
|
|
358
|
+
date_modifier: The DateModifier to apply on datetime objects
|
|
359
|
+
date_format: Format of the date string. Default is '%Y-%m-%d'
|
|
360
|
+
"""
|
|
361
|
+
|
|
362
|
+
def with_more_modifiers(self, date_modifiers: Sequence[DateModifier]):
|
|
363
|
+
"""
|
|
364
|
+
Create a new TimestampModifier with more date modifiers
|
|
365
|
+
|
|
366
|
+
Arguments:
|
|
367
|
+
date_modifiers: The additional date modifiers to add
|
|
368
|
+
|
|
369
|
+
Returns:
|
|
370
|
+
A new TimestampModifier
|
|
371
|
+
"""
|
|
372
|
+
joined_modifiers = self.date_mod_pipeline.get_joined_modifiers(date_modifiers)
|
|
373
|
+
return TimestampModifier(joined_modifiers)
|
|
374
|
+
|
|
375
|
+
def modify(self, timestamp: float) -> float:
|
|
376
|
+
"""
|
|
377
|
+
Modifies the input timestamp with the date modifiers
|
|
378
|
+
|
|
379
|
+
Arguments:
|
|
380
|
+
timestamp: The input timestamp as float
|
|
381
|
+
|
|
382
|
+
Returns:
|
|
383
|
+
The resulting timestamp
|
|
384
|
+
"""
|
|
385
|
+
date_obj = datetime.fromtimestamp(timestamp).date()
|
|
386
|
+
modified_date = self.date_mod_pipeline.modify(date_obj)
|
|
387
|
+
modified_datetime = datetime.combine(modified_date, datetime.min.time())
|
|
388
|
+
return modified_datetime.timestamp()
|
|
389
|
+
|
|
390
|
+
def get_date_list(self, start_timestamp: float, step: DateModifier) -> Sequence[float]:
|
|
391
|
+
"""
|
|
392
|
+
This method modifies the input timestamp, and returns all dates as timestampes/floats from the input date
|
|
393
|
+
to the modified date, incremented by a DateModifier step.
|
|
394
|
+
|
|
395
|
+
If the step is positive and start date is less than end date, then it'll return an increasing list of
|
|
396
|
+
dates starting from the start date. If the step is negative and start date is greater than end date,
|
|
397
|
+
then it'll return a decreasing list of dates starting from the start date. Otherwise, an empty list
|
|
398
|
+
is returned.
|
|
399
|
+
|
|
400
|
+
Arguments:
|
|
401
|
+
start_timestamp: The input timestamp as float (it's the first date in the output list if step moves towards end date)
|
|
402
|
+
step: The increment to take (specified as an offset DateModifier). Offset cannot be zero
|
|
403
|
+
|
|
404
|
+
Returns:
|
|
405
|
+
A list of timestamp as floats
|
|
406
|
+
"""
|
|
407
|
+
curr_date = datetime.fromtimestamp(start_timestamp).date()
|
|
408
|
+
output = self.date_mod_pipeline.get_date_list(curr_date, step)
|
|
409
|
+
return [datetime.combine(x, datetime.min.time()).timestamp() for x in output]
|
dateutils/types.py
ADDED
squirrels/__init__.py
CHANGED
|
@@ -1,23 +1,19 @@
|
|
|
1
1
|
from ._version import __version__
|
|
2
2
|
|
|
3
|
-
from .arguments
|
|
4
|
-
from .arguments.run_time_args import AuthLoginArgs, AuthTokenArgs, ContextArgs, ModelArgs, DashboardArgs
|
|
3
|
+
from .arguments import *
|
|
5
4
|
|
|
6
|
-
from .
|
|
7
|
-
from .parameter_options import NumberParameterOption, NumberRangeParameterOption, TextParameterOption
|
|
5
|
+
from .auth import *
|
|
8
6
|
|
|
9
|
-
from .
|
|
10
|
-
from .parameters import NumberParameter, NumberRangeParameter, TextParameter, TextValue
|
|
7
|
+
from .connections import *
|
|
11
8
|
|
|
12
|
-
from .
|
|
13
|
-
from .data_sources import NumberDataSource, NumberRangeDataSource, TextDataSource
|
|
9
|
+
from .parameter_options import *
|
|
14
10
|
|
|
15
|
-
from .
|
|
11
|
+
from .parameters import *
|
|
16
12
|
|
|
17
|
-
from .
|
|
13
|
+
from .data_sources import *
|
|
18
14
|
|
|
19
|
-
from .
|
|
15
|
+
from .dashboards import *
|
|
20
16
|
|
|
21
|
-
from .
|
|
17
|
+
from .types import *
|
|
22
18
|
|
|
23
|
-
from .
|
|
19
|
+
from ._project import SquirrelsProject
|