sapiopycommons 2024.11.22a371__py3-none-any.whl → 2024.12.4a375__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 sapiopycommons might be problematic. Click here for more details.
- sapiopycommons/eln/experiment_handler.py +1 -1
- sapiopycommons/general/time_util.py +83 -5
- {sapiopycommons-2024.11.22a371.dist-info → sapiopycommons-2024.12.4a375.dist-info}/METADATA +1 -1
- {sapiopycommons-2024.11.22a371.dist-info → sapiopycommons-2024.12.4a375.dist-info}/RECORD +6 -6
- {sapiopycommons-2024.11.22a371.dist-info → sapiopycommons-2024.12.4a375.dist-info}/WHEEL +0 -0
- {sapiopycommons-2024.11.22a371.dist-info → sapiopycommons-2024.12.4a375.dist-info}/licenses/LICENSE +0 -0
|
@@ -824,7 +824,7 @@ class ExperimentHandler:
|
|
|
824
824
|
The record to remove from the given step.
|
|
825
825
|
The record may be provided as either a DataRecord, PyRecordModel, or WrappedRecordModel.
|
|
826
826
|
"""
|
|
827
|
-
self.
|
|
827
|
+
self.remove_eln_rows(step, [record])
|
|
828
828
|
|
|
829
829
|
def add_sample_details(self, step: Step, samples: list[RecordModel], wrapper_type: type[WrappedType]) \
|
|
830
830
|
-> list[PyRecordModel | WrappedType]:
|
|
@@ -2,9 +2,12 @@ from __future__ import annotations
|
|
|
2
2
|
|
|
3
3
|
import time
|
|
4
4
|
from datetime import datetime
|
|
5
|
+
from typing import Any
|
|
5
6
|
|
|
6
7
|
import pytz
|
|
7
8
|
|
|
9
|
+
from sapiopycommons.general.exceptions import SapioException
|
|
10
|
+
|
|
8
11
|
__timezone = None
|
|
9
12
|
"""The default timezone. Use TimeUtil.set_default_timezone in a global context before making use of TimeUtil."""
|
|
10
13
|
|
|
@@ -26,7 +29,7 @@ class TimeUtil:
|
|
|
26
29
|
with static date fields, use "UTC" as your input timezone.
|
|
27
30
|
"""
|
|
28
31
|
@staticmethod
|
|
29
|
-
def get_default_timezone():
|
|
32
|
+
def get_default_timezone() -> Any:
|
|
30
33
|
"""
|
|
31
34
|
Returns the timezone that TimeUtil is currently using as its default.
|
|
32
35
|
"""
|
|
@@ -45,7 +48,7 @@ class TimeUtil:
|
|
|
45
48
|
__timezone = TimeUtil.__to_tz(new_timezone)
|
|
46
49
|
|
|
47
50
|
@staticmethod
|
|
48
|
-
def __to_tz(timezone: str | int = None):
|
|
51
|
+
def __to_tz(timezone: str | int = None) -> Any:
|
|
49
52
|
"""
|
|
50
53
|
:param timezone: Either the name of a timezone, a UTC offset in seconds, or None if the default should be used.
|
|
51
54
|
:return: The timezone object to use for the given input. If the input is None, uses the default timezone.
|
|
@@ -55,11 +58,28 @@ class TimeUtil:
|
|
|
55
58
|
# because pytz may return timezones from strings in Local Mean Time instead of a timezone with a UTC offset.
|
|
56
59
|
# LMT may be a few minutes off of the actual time in that timezone right now.
|
|
57
60
|
# https://stackoverflow.com/questions/35462876
|
|
58
|
-
offset: int =
|
|
59
|
-
|
|
61
|
+
offset: int = TimeUtil.__get_timezone_offset(timezone)
|
|
62
|
+
# This function takes an offset in minutes, so divide the provided offset seconds by 60.
|
|
63
|
+
return pytz.FixedOffset(offset // 60)
|
|
60
64
|
if isinstance(timezone, int):
|
|
61
65
|
return pytz.FixedOffset(timezone // 60)
|
|
62
|
-
|
|
66
|
+
if timezone is None:
|
|
67
|
+
return TimeUtil.get_default_timezone()
|
|
68
|
+
raise SapioException(f"Unhandled timezone object of type {type(timezone)}: {timezone}")
|
|
69
|
+
|
|
70
|
+
@staticmethod
|
|
71
|
+
def __get_timezone_offset(timezone: str | int | None) -> int:
|
|
72
|
+
"""
|
|
73
|
+
:param timezone: Either the name of a timezone, a UTC offset in seconds, or None if the default should be used.
|
|
74
|
+
:return: The UTC offset in seconds of the provided timezone.
|
|
75
|
+
"""
|
|
76
|
+
if isinstance(timezone, int):
|
|
77
|
+
return timezone
|
|
78
|
+
if isinstance(timezone, str):
|
|
79
|
+
timezone = pytz.timezone(timezone)
|
|
80
|
+
if timezone is None:
|
|
81
|
+
timezone = TimeUtil.get_default_timezone()
|
|
82
|
+
return int(datetime.now(timezone).utcoffset().total_seconds())
|
|
63
83
|
|
|
64
84
|
@staticmethod
|
|
65
85
|
def current_time(timezone: str | int = None) -> datetime:
|
|
@@ -127,6 +147,64 @@ class TimeUtil:
|
|
|
127
147
|
tz = TimeUtil.__to_tz(timezone)
|
|
128
148
|
return int(datetime.strptime(time_point, time_format).replace(tzinfo=tz).timestamp() * 1000)
|
|
129
149
|
|
|
150
|
+
# FR-47296: Provide functions for shifting between timezones.
|
|
151
|
+
@staticmethod
|
|
152
|
+
def shift_now(to_timezone: str = "UTC", from_timezone: str | None = None) -> int:
|
|
153
|
+
"""
|
|
154
|
+
Take the current time in from_timezone and output the epoch timestamp that would display that same time in
|
|
155
|
+
to_timezone. A use case for this is when dealing with static date fields to convert a provided timestamp to the
|
|
156
|
+
value necessary to display that timestamp in the same way when viewed in the static date field.
|
|
157
|
+
|
|
158
|
+
:param to_timezone: The timezone to shift to. If not provided, uses UTC.
|
|
159
|
+
:param from_timezone: The timezone to shift from. If no timezone is provided, uses the global
|
|
160
|
+
timezone variable set by the TimeUtil. A list of valid timezones can be found at
|
|
161
|
+
https://en.wikipedia.org/wiki/List_of_tz_database_time_zones. May also accept a UTC offset in seconds.
|
|
162
|
+
:return: The epoch timestamp that would display as the same time in to_timezone as the current time in
|
|
163
|
+
from_timezone.
|
|
164
|
+
"""
|
|
165
|
+
millis: int = TimeUtil.now_in_millis()
|
|
166
|
+
return TimeUtil.shift_millis(millis, to_timezone, from_timezone)
|
|
167
|
+
|
|
168
|
+
@staticmethod
|
|
169
|
+
def shift_millis(millis: int, to_timezone: str = "UTC", from_timezone: str | None = None) -> int:
|
|
170
|
+
"""
|
|
171
|
+
Take a number of milliseconds for a time in from_timezone and output the epoch timestamp that would display that
|
|
172
|
+
same time in to_timezone. A use case for this is when dealing with static date fields to convert a provided
|
|
173
|
+
timestamp to the value necessary to display that timestamp in the same way when viewed in the static date field.
|
|
174
|
+
|
|
175
|
+
:param millis: The time in milliseconds to convert from.
|
|
176
|
+
:param to_timezone: The timezone to shift to. If not provided, uses UTC.
|
|
177
|
+
:param from_timezone: The timezone to shift from. If no timezone is provided, uses the global
|
|
178
|
+
timezone variable set by the TimeUtil. A list of valid timezones can be found at
|
|
179
|
+
https://en.wikipedia.org/wiki/List_of_tz_database_time_zones. May also accept a UTC offset in seconds.
|
|
180
|
+
:return: The epoch timestamp that would display as the same time in to_timezone as the given time in
|
|
181
|
+
from_timezone.
|
|
182
|
+
"""
|
|
183
|
+
to_offset: int = TimeUtil.__get_timezone_offset(to_timezone) * 1000
|
|
184
|
+
from_offset: int = TimeUtil.__get_timezone_offset(from_timezone) * 1000
|
|
185
|
+
return millis + from_offset - to_offset
|
|
186
|
+
|
|
187
|
+
@staticmethod
|
|
188
|
+
def shift_format(time_point: str, time_format: str, to_timezone: str = "UTC", from_timezone: str | None = None) \
|
|
189
|
+
-> int:
|
|
190
|
+
"""
|
|
191
|
+
Take a timestamp for a time in from_timezone and output the epoch timestamp that would display that same time
|
|
192
|
+
in to_timezone. A use case for this is when dealing with static date fields to convert a provided timestamp to
|
|
193
|
+
the value necessary to display that timestamp in the same way when viewed in the static date field.
|
|
194
|
+
|
|
195
|
+
:param time_point: The time in some date/time format to convert from.
|
|
196
|
+
:param time_format: The format that the time_point is in. Documentation for how the time formatting works
|
|
197
|
+
can be found at https://docs.python.org/3.10/library/datetime.html#strftime-and-strptime-behavior
|
|
198
|
+
:param to_timezone: The timezone to shift to. If not provided, uses UTC.
|
|
199
|
+
:param from_timezone: The timezone to shift from. If no timezone is provided, uses the global
|
|
200
|
+
timezone variable set by the TimeUtil. A list of valid timezones can be found at
|
|
201
|
+
https://en.wikipedia.org/wiki/List_of_tz_database_time_zones. May also accept a UTC offset in seconds.
|
|
202
|
+
:return: The epoch timestamp that would display as the same time in to_timezone as the given time in
|
|
203
|
+
from_timezone.
|
|
204
|
+
"""
|
|
205
|
+
millis: int = TimeUtil.format_to_millis(time_point, time_format, from_timezone)
|
|
206
|
+
return TimeUtil.shift_millis(millis, to_timezone, from_timezone)
|
|
207
|
+
|
|
130
208
|
# FR-46154: Create a function that determines if a string matches a time format.
|
|
131
209
|
@staticmethod
|
|
132
210
|
def str_matches_format(time_point: str, time_format: str) -> bool:
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.3
|
|
2
2
|
Name: sapiopycommons
|
|
3
|
-
Version: 2024.
|
|
3
|
+
Version: 2024.12.4a375
|
|
4
4
|
Summary: Official Sapio Python API Utilities Package
|
|
5
5
|
Project-URL: Homepage, https://github.com/sapiosciences
|
|
6
6
|
Author-email: Jonathan Steck <jsteck@sapiosciences.com>, Yechen Qiao <yqiao@sapiosciences.com>
|
|
@@ -14,7 +14,7 @@ sapiopycommons/datatype/attachment_util.py,sha256=_l2swuP8noIGAl4bwzBUEhr6YlN_OV
|
|
|
14
14
|
sapiopycommons/datatype/data_fields.py,sha256=g8Ib6LH8ikNu9AzeVJs8Z2qS8A-cplACeFU7vYguNEY,4063
|
|
15
15
|
sapiopycommons/datatype/pseudo_data_types.py,sha256=Fe75Rnq5evyeJM1nC0sLkLGKAC74g2-GEeTdMeId80o,27649
|
|
16
16
|
sapiopycommons/eln/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
17
|
-
sapiopycommons/eln/experiment_handler.py,sha256=
|
|
17
|
+
sapiopycommons/eln/experiment_handler.py,sha256=ZSx0uZy-2OtH_ArHy2OVwoNI3BYQLXSHGBmjviZl1Fw,69283
|
|
18
18
|
sapiopycommons/eln/experiment_report_util.py,sha256=9wWV6oEdKtfn2rI5V0BtmuW9OJlGFd9U07FIf889Gjw,37679
|
|
19
19
|
sapiopycommons/eln/plate_designer.py,sha256=FYJfhhNq8hdfuXgDYOYHy6g0m2zNwQXZWF_MTPzElDg,7184
|
|
20
20
|
sapiopycommons/files/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
@@ -36,7 +36,7 @@ sapiopycommons/general/exceptions.py,sha256=GY7fe0qOgoy4kQVn_Pn3tdzHsJZyNIpa6VCC
|
|
|
36
36
|
sapiopycommons/general/popup_util.py,sha256=L-4qpTemSZdlD6_6oEsDYIzLOCiZgDK6wC6DqUwzOYA,31925
|
|
37
37
|
sapiopycommons/general/sapio_links.py,sha256=o9Z-8y2rz6AI0Cy6tq58ElPge9RBnisGc9NyccbaJxs,2610
|
|
38
38
|
sapiopycommons/general/storage_util.py,sha256=ovmK_jN7v09BoX07XxwShpBUC5WYQOM7dbKV_VeLXJU,8892
|
|
39
|
-
sapiopycommons/general/time_util.py,sha256=
|
|
39
|
+
sapiopycommons/general/time_util.py,sha256=jU1urPoZRv6evNucR0-288EyT4PrsDpCr-H1-7BKq9A,12363
|
|
40
40
|
sapiopycommons/multimodal/multimodal.py,sha256=A1QsC8QTPmgZyPr7KtMbPRedn2Ie4WIErodUvQ9otgU,6724
|
|
41
41
|
sapiopycommons/multimodal/multimodal_data.py,sha256=0BeVPr9HaC0hNTF1v1phTIKGruvNnwerHsD994qJKBg,15099
|
|
42
42
|
sapiopycommons/processtracking/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
@@ -53,7 +53,7 @@ sapiopycommons/webhook/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3
|
|
|
53
53
|
sapiopycommons/webhook/webhook_context.py,sha256=D793uLsb1691SalaPnBUk3rOSxn_hYLhdvkaIxjNXss,1909
|
|
54
54
|
sapiopycommons/webhook/webhook_handlers.py,sha256=MdsVK4bHffkMNmNWl0_qvu-5Lz8-qGu4Ryi7lZO1BZs,18586
|
|
55
55
|
sapiopycommons/webhook/webservice_handlers.py,sha256=AFM2Va9Fpb2BvlFycIUUOdghtGiEv1Ab5jf44yjHSgU,17218
|
|
56
|
-
sapiopycommons-2024.
|
|
57
|
-
sapiopycommons-2024.
|
|
58
|
-
sapiopycommons-2024.
|
|
59
|
-
sapiopycommons-2024.
|
|
56
|
+
sapiopycommons-2024.12.4a375.dist-info/METADATA,sha256=K76hHDwZ7i68OAHXdFl42xXA49M50LxMhGimBZV1PaM,3143
|
|
57
|
+
sapiopycommons-2024.12.4a375.dist-info/WHEEL,sha256=C2FUgwZgiLbznR-k0b_5k3Ai_1aASOXDss3lzCUsUug,87
|
|
58
|
+
sapiopycommons-2024.12.4a375.dist-info/licenses/LICENSE,sha256=HyVuytGSiAUQ6ErWBHTqt1iSGHhLmlC8fO7jTCuR8dU,16725
|
|
59
|
+
sapiopycommons-2024.12.4a375.dist-info/RECORD,,
|
|
File without changes
|
{sapiopycommons-2024.11.22a371.dist-info → sapiopycommons-2024.12.4a375.dist-info}/licenses/LICENSE
RENAMED
|
File without changes
|