sapiopycommons 2025.5.6a512__py3-none-any.whl → 2025.5.7a514__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/callbacks/callback_util.py +116 -64
- sapiopycommons/callbacks/field_builder.py +2 -0
- sapiopycommons/customreport/auto_pagers.py +2 -1
- sapiopycommons/customreport/term_builder.py +1 -1
- sapiopycommons/datatype/pseudo_data_types.py +349 -326
- sapiopycommons/eln/experiment_cache.py +188 -0
- sapiopycommons/eln/experiment_handler.py +336 -719
- sapiopycommons/eln/experiment_step_factory.py +476 -0
- sapiopycommons/eln/plate_designer.py +7 -2
- sapiopycommons/eln/step_creation.py +236 -0
- sapiopycommons/files/file_util.py +4 -4
- sapiopycommons/general/accession_service.py +2 -2
- sapiopycommons/general/aliases.py +4 -1
- sapiopycommons/general/data_structure_util.py +115 -0
- sapiopycommons/general/sapio_links.py +4 -12
- sapiopycommons/processtracking/custom_workflow_handler.py +2 -1
- sapiopycommons/recordmodel/record_handler.py +357 -27
- sapiopycommons/rules/eln_rule_handler.py +8 -1
- sapiopycommons/rules/on_save_rule_handler.py +8 -1
- sapiopycommons/webhook/webhook_handlers.py +3 -0
- sapiopycommons/webhook/webservice_handlers.py +2 -2
- {sapiopycommons-2025.5.6a512.dist-info → sapiopycommons-2025.5.7a514.dist-info}/METADATA +2 -2
- sapiopycommons-2025.5.7a514.dist-info/RECORD +67 -0
- sapiopycommons/ai/__init__.py +0 -0
- sapiopycommons/ai/api/fielddefinitions/proto/fields_pb2.py +0 -43
- sapiopycommons/ai/api/fielddefinitions/proto/fields_pb2.pyi +0 -31
- sapiopycommons/ai/api/fielddefinitions/proto/fields_pb2_grpc.py +0 -24
- sapiopycommons/ai/api/fielddefinitions/proto/velox_field_def_pb2.py +0 -123
- sapiopycommons/ai/api/fielddefinitions/proto/velox_field_def_pb2.pyi +0 -598
- sapiopycommons/ai/api/fielddefinitions/proto/velox_field_def_pb2_grpc.py +0 -24
- sapiopycommons/ai/api/plan/proto/step_output_pb2.py +0 -45
- sapiopycommons/ai/api/plan/proto/step_output_pb2.pyi +0 -42
- sapiopycommons/ai/api/plan/proto/step_output_pb2_grpc.py +0 -24
- sapiopycommons/ai/api/plan/proto/step_pb2.py +0 -43
- sapiopycommons/ai/api/plan/proto/step_pb2.pyi +0 -43
- sapiopycommons/ai/api/plan/proto/step_pb2_grpc.py +0 -24
- sapiopycommons/ai/api/plan/script/proto/script_pb2.py +0 -53
- sapiopycommons/ai/api/plan/script/proto/script_pb2.pyi +0 -99
- sapiopycommons/ai/api/plan/script/proto/script_pb2_grpc.py +0 -153
- sapiopycommons/ai/api/plan/tool/proto/entry_pb2.py +0 -57
- sapiopycommons/ai/api/plan/tool/proto/entry_pb2.pyi +0 -96
- sapiopycommons/ai/api/plan/tool/proto/entry_pb2_grpc.py +0 -24
- sapiopycommons/ai/api/plan/tool/proto/tool_pb2.py +0 -67
- sapiopycommons/ai/api/plan/tool/proto/tool_pb2.pyi +0 -220
- sapiopycommons/ai/api/plan/tool/proto/tool_pb2_grpc.py +0 -154
- sapiopycommons/ai/api/session/proto/sapio_conn_info_pb2.py +0 -39
- sapiopycommons/ai/api/session/proto/sapio_conn_info_pb2.pyi +0 -32
- sapiopycommons/ai/api/session/proto/sapio_conn_info_pb2_grpc.py +0 -24
- sapiopycommons/ai/protobuf_utils.py +0 -454
- sapiopycommons/ai/tool_service_base.py +0 -708
- sapiopycommons/general/html_formatter.py +0 -456
- sapiopycommons-2025.5.6a512.dist-info/RECORD +0 -91
- {sapiopycommons-2025.5.6a512.dist-info → sapiopycommons-2025.5.7a514.dist-info}/WHEEL +0 -0
- {sapiopycommons-2025.5.6a512.dist-info → sapiopycommons-2025.5.7a514.dist-info}/licenses/LICENSE +0 -0
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
from typing import Iterable
|
|
2
|
+
|
|
3
|
+
from sapiopycommons.general.aliases import DataTypeIdentifier, FieldIdentifier, ExperimentEntryIdentifier
|
|
4
|
+
from sapiopylib.rest.pojo.TableColumn import TableColumn
|
|
5
|
+
from sapiopylib.rest.pojo.datatype.FieldDefinition import AbstractVeloxFieldDefinition
|
|
6
|
+
from sapiopylib.rest.pojo.eln.SapioELNEnums import ExperimentEntryStatus, ElnEntryType
|
|
7
|
+
from sapiopylib.rest.pojo.eln.field_set import ElnFieldSetInfo
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
# CR-47564: Created these classes to streamline entry creation using the ExperimentEntryFactory.
|
|
11
|
+
class StepCreation:
|
|
12
|
+
"""
|
|
13
|
+
An object that contains the criteria for creating a new entry in the experiment.
|
|
14
|
+
"""
|
|
15
|
+
_entry_type: ElnEntryType
|
|
16
|
+
"""The type of the entry to be created."""
|
|
17
|
+
is_shown_in_template: bool | None
|
|
18
|
+
"""Whether the entry will appear in the template if the experiment this entry is in is saved to a new template."""
|
|
19
|
+
is_removable: bool | None
|
|
20
|
+
"""Whether the entry can be removed by users."""
|
|
21
|
+
is_renamable: bool | None
|
|
22
|
+
"""Whether the entry can be renamed by users."""
|
|
23
|
+
is_static_view: bool | None
|
|
24
|
+
"""Whether the entry's attachment is static. For attachment entries only. Static attachment entries will store
|
|
25
|
+
their attachment data in the template."""
|
|
26
|
+
related_entry_set: Iterable[ExperimentEntryIdentifier | str] | None
|
|
27
|
+
"""The IDs of the entries this entry is implicitly dependent on. If any of the entries are deleted then this entry
|
|
28
|
+
is also deleted."""
|
|
29
|
+
dependency_set: Iterable[ExperimentEntryIdentifier | str] | None
|
|
30
|
+
"""The IDs of the entries this entry is dependent on. Requires the entries to be completed before this entry will
|
|
31
|
+
be enabled."""
|
|
32
|
+
requires_grabber_plugin: bool
|
|
33
|
+
"""Whether to run a grabber plugin when this entry is initialized."""
|
|
34
|
+
entry_singleton_id: str | None
|
|
35
|
+
"""When this field is present (i.e. not null or blank) it will enforce that only one entry with this singleton
|
|
36
|
+
value is present in the experiment. If you attempt to create an entry with the singletonId of an entry already
|
|
37
|
+
present in the experiment it will return the existing entry instead of creating a new one. If an entry isn't
|
|
38
|
+
present in the Notebook Experiment with a matching singletonId it will create a new entry like normal."""
|
|
39
|
+
is_hidden: bool | None
|
|
40
|
+
"""Whether the user is able to visibly see this entry within the experiment."""
|
|
41
|
+
entry_height: int | None
|
|
42
|
+
"""The height of this entry in pixels. Setting the height to 0 will cause the entry to auto-size to its contents."""
|
|
43
|
+
description: str | None
|
|
44
|
+
"""The description of the entry."""
|
|
45
|
+
is_initialization_required: bool | None
|
|
46
|
+
"""Whether the user must manually initialize this entry by clicking on it."""
|
|
47
|
+
collapse_entry: bool | None
|
|
48
|
+
"""Whether the entry should be collapsed by default."""
|
|
49
|
+
entry_status: ExperimentEntryStatus | None
|
|
50
|
+
"""The current status of the entry."""
|
|
51
|
+
template_item_fulfilled_timestamp: int | None
|
|
52
|
+
"""The time in milliseconds since the epoch that this entry became initialized."""
|
|
53
|
+
entry_options: dict[str, str] | None
|
|
54
|
+
"""The entry options of the entry."""
|
|
55
|
+
|
|
56
|
+
def __init__(self, entry_type: ElnEntryType):
|
|
57
|
+
self._entry_type = entry_type
|
|
58
|
+
self.is_shown_in_template = None
|
|
59
|
+
self.is_removable = None
|
|
60
|
+
self.is_renamable = None
|
|
61
|
+
self.is_static_view = None
|
|
62
|
+
self.related_entry_set = None
|
|
63
|
+
self.dependency_set = None
|
|
64
|
+
self.requires_grabber_plugin = False
|
|
65
|
+
self.entry_singleton_id = None
|
|
66
|
+
self.is_hidden = None
|
|
67
|
+
self.entry_height = None
|
|
68
|
+
self.description = None
|
|
69
|
+
self.is_initialization_required = None
|
|
70
|
+
self.collapse_entry = None
|
|
71
|
+
self.entry_status = None
|
|
72
|
+
self.template_item_fulfilled_timestamp = None
|
|
73
|
+
self.entry_options = None
|
|
74
|
+
|
|
75
|
+
@property
|
|
76
|
+
def entry_type(self) -> ElnEntryType:
|
|
77
|
+
return self._entry_type
|
|
78
|
+
|
|
79
|
+
class AttachmentStepCreation(StepCreation):
|
|
80
|
+
"""
|
|
81
|
+
An object that contains criteria for creating a new attachment entry in an experiment.
|
|
82
|
+
"""
|
|
83
|
+
def __init__(self):
|
|
84
|
+
super().__init__(ElnEntryType.Attachment)
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
class DashboardStepCreation(StepCreation):
|
|
88
|
+
"""
|
|
89
|
+
An object that contains criteria for creating a new dashboard entry in an experiment.
|
|
90
|
+
"""
|
|
91
|
+
source_entry: ExperimentEntryIdentifier | str | None
|
|
92
|
+
"""The entry that contains the source data for this entry's dashboard(s)."""
|
|
93
|
+
dashboard_guids: Iterable[str] | None
|
|
94
|
+
"""The GUIDs of the dashboards to display in this entry."""
|
|
95
|
+
|
|
96
|
+
def __init__(self):
|
|
97
|
+
super().__init__(ElnEntryType.Dashboard)
|
|
98
|
+
self.source_entry = None
|
|
99
|
+
self.dashboard_guids = None
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
class GlobalDtFormStepCreation(StepCreation):
|
|
103
|
+
"""
|
|
104
|
+
An object that contains criteria for creating a new global data type form entry in an experiment.
|
|
105
|
+
"""
|
|
106
|
+
layout_name: str | None
|
|
107
|
+
"""The name of the data type layout to be displayed in this form. The layout must be for the data type for this
|
|
108
|
+
entry."""
|
|
109
|
+
form_names: Iterable[str] | None
|
|
110
|
+
"""The names of the components in the chosen data type layout to display in this form."""
|
|
111
|
+
extension_types: Iterable[DataTypeIdentifier] | None
|
|
112
|
+
"""The names of the extension data types to display fields from within the form."""
|
|
113
|
+
field_names: Iterable[FieldIdentifier] | None
|
|
114
|
+
"""A list of data field names for the fields to be displayed in the form."""
|
|
115
|
+
|
|
116
|
+
def __init__(self):
|
|
117
|
+
super().__init__(ElnEntryType.Form)
|
|
118
|
+
self.form_names = None
|
|
119
|
+
self.layout_name = None
|
|
120
|
+
self.extension_types = None
|
|
121
|
+
self.field_names = None
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
class ELnDtFormStepCreation(StepCreation):
|
|
125
|
+
"""
|
|
126
|
+
An object that contains criteria for creating a new ELN data type form entry in an experiment.
|
|
127
|
+
"""
|
|
128
|
+
is_field_addable: bool | None
|
|
129
|
+
"""Whether new fields can be added to the entry by users."""
|
|
130
|
+
is_existing_field_removable: bool | None
|
|
131
|
+
"""Whether existing fields on the entry can be removed by users."""
|
|
132
|
+
field_sets: Iterable[int | str | ElnFieldSetInfo] | None
|
|
133
|
+
"""The predefined field sets to display in this form."""
|
|
134
|
+
field_definitions: Iterable[AbstractVeloxFieldDefinition] | None
|
|
135
|
+
"""New field definitions to be created for this entry."""
|
|
136
|
+
predefined_field_names: Iterable[str] | None
|
|
137
|
+
"""The names of the predefined fields to display in this form."""
|
|
138
|
+
|
|
139
|
+
def __init__(self):
|
|
140
|
+
super().__init__(ElnEntryType.Form)
|
|
141
|
+
self.is_field_addable = None
|
|
142
|
+
self.is_existing_field_removable = None
|
|
143
|
+
self.field_sets = None
|
|
144
|
+
self.field_definitions = None
|
|
145
|
+
self.predefined_field_names = None
|
|
146
|
+
self.table_columns = None
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
class PluginStepCreation(StepCreation):
|
|
150
|
+
"""
|
|
151
|
+
An object that contains criteria for creating a new plugin entry in an experiment.
|
|
152
|
+
"""
|
|
153
|
+
plugin_name: str | None
|
|
154
|
+
"""The client side plugin name to render this entry with."""
|
|
155
|
+
using_template_data: bool | None
|
|
156
|
+
"""Whether this entry will use the data from the template."""
|
|
157
|
+
provides_template_data: bool | None
|
|
158
|
+
"""Whether this entry can provide data to copy into a new template."""
|
|
159
|
+
|
|
160
|
+
def __init__(self):
|
|
161
|
+
super().__init__(ElnEntryType.Plugin)
|
|
162
|
+
self.plugin_name = None
|
|
163
|
+
self.using_template_data = None
|
|
164
|
+
self.provides_template_data = None
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
class GlobalDtTableStepCreation(StepCreation):
|
|
168
|
+
"""
|
|
169
|
+
An object that contains criteria for creating a new global data type table entry in an experiment.
|
|
170
|
+
"""
|
|
171
|
+
layout_name: str | None
|
|
172
|
+
"""The name of the data type layout to display in this table."""
|
|
173
|
+
extension_types: Iterable[str] | None
|
|
174
|
+
"""The names of the extension data types to display fields from within the table."""
|
|
175
|
+
table_columns: Iterable[TableColumn] | None
|
|
176
|
+
"""The columns to display in the table. This can be used to change the sort order and direction of columns."""
|
|
177
|
+
field_names: Iterable[FieldIdentifier] | None
|
|
178
|
+
"""A list of data field names for the fields to be displayed in the table. These will be added as TableColumns and
|
|
179
|
+
placed after any of the existing columns specified in the table_columns parameter without any sorting."""
|
|
180
|
+
show_key_fields: bool | None
|
|
181
|
+
"""Whether the key fields of the data type should be shown in the entry."""
|
|
182
|
+
|
|
183
|
+
def __init__(self):
|
|
184
|
+
super().__init__(ElnEntryType.Table)
|
|
185
|
+
self.layout_name = None
|
|
186
|
+
self.extension_types = None
|
|
187
|
+
self.table_columns = None
|
|
188
|
+
self.field_names = None
|
|
189
|
+
self.show_key_fields = None
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
class ELnDtTableStepCreation(StepCreation):
|
|
193
|
+
"""
|
|
194
|
+
An object that contains criteria for creating a new ELN data type table entry in an experiment.
|
|
195
|
+
"""
|
|
196
|
+
is_field_addable: bool | None
|
|
197
|
+
"""Whether new fields can be added to the entry by users."""
|
|
198
|
+
is_existing_field_removable: bool | None
|
|
199
|
+
"""Whether existing fields on the entry can be removed by users."""
|
|
200
|
+
field_sets: Iterable[int | str | ElnFieldSetInfo] | None
|
|
201
|
+
"""The predefined field sets to display in this form."""
|
|
202
|
+
field_definitions: Iterable[AbstractVeloxFieldDefinition] | None
|
|
203
|
+
"""New field definitions to be created for this entry."""
|
|
204
|
+
predefined_field_names: Iterable[str] | None
|
|
205
|
+
"""The names of the predefined fields to display in this form."""
|
|
206
|
+
table_columns: Iterable[TableColumn] | None
|
|
207
|
+
"""The columns to display in the table."""
|
|
208
|
+
|
|
209
|
+
def __init__(self):
|
|
210
|
+
super().__init__(ElnEntryType.Table)
|
|
211
|
+
self.is_field_addable = None
|
|
212
|
+
self.is_existing_field_removable = None
|
|
213
|
+
self.field_sets = None
|
|
214
|
+
self.field_definitions = None
|
|
215
|
+
self.predefined_field_names = None
|
|
216
|
+
self.table_columns = None
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
class TempDataStepCreation(StepCreation):
|
|
220
|
+
"""
|
|
221
|
+
An object that contains criteria for creating a new temp data entry in an experiment.
|
|
222
|
+
"""
|
|
223
|
+
plugin_path: str | None
|
|
224
|
+
"""The temp data plugin path to run to populate the entry."""
|
|
225
|
+
|
|
226
|
+
def __init__(self):
|
|
227
|
+
super().__init__(ElnEntryType.TempData)
|
|
228
|
+
self.plugin_path = None
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
class TextStepCreation(StepCreation):
|
|
232
|
+
"""
|
|
233
|
+
An object that contains criteria for creating a new text entry in an experiment.
|
|
234
|
+
"""
|
|
235
|
+
def __init__(self):
|
|
236
|
+
super().__init__(ElnEntryType.Text)
|
|
@@ -327,10 +327,10 @@ class FileUtil:
|
|
|
327
327
|
:param files: A dictionary of file name to file data as a string or bytes.
|
|
328
328
|
:return: The bytes for a zip file containing the input files.
|
|
329
329
|
"""
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
330
|
+
with io.BytesIO() as zip_buffer:
|
|
331
|
+
with zipfile.ZipFile(zip_buffer, "w", zipfile.ZIP_DEFLATED) as zip_file:
|
|
332
|
+
for file_name, file_data in files.items():
|
|
333
|
+
zip_file.writestr(file_name, file_data)
|
|
334
334
|
return zip_buffer.getvalue()
|
|
335
335
|
|
|
336
336
|
# Deprecated functions:
|
|
@@ -199,7 +199,7 @@ class AccessionRequestId(AbstractAccessionServiceOperator):
|
|
|
199
199
|
|
|
200
200
|
Properties:
|
|
201
201
|
numberOfCharacters: Number of characters maximum in the request ID.
|
|
202
|
-
accessorName: This is a legacy variable from drum.getNextIdListByMapName(), which allows setting different "accessorName" from old system. We need this for
|
|
202
|
+
accessorName: This is a legacy variable from drum.getNextIdListByMapName(), which allows setting different "accessorName" from old system. We need this for compatibility patch for converting these to the new preference format.
|
|
203
203
|
"""
|
|
204
204
|
_num_of_characters: int
|
|
205
205
|
_accessor_name: str
|
|
@@ -341,7 +341,7 @@ class AccessionService:
|
|
|
341
341
|
def get_affixed_id_in_batch(self, data_type_name: str, data_field_name: str, num_ids: int, prefix: str | None,
|
|
342
342
|
suffix: str | None, num_digits: int | None, start_num: int = 1) -> list[str]:
|
|
343
343
|
"""
|
|
344
|
-
Get the batch affixed IDs that are maximal in cache and
|
|
344
|
+
Get the batch affixed IDs that are maximal in cache and contiguous for a particular datatype.datafield under a given format.
|
|
345
345
|
:param data_type_name: The datatype name to look for max ID
|
|
346
346
|
:param data_field_name: The datafield name to look for max ID
|
|
347
347
|
:param num_ids: The number of IDs to accession.
|
|
@@ -7,6 +7,7 @@ from sapiopylib.rest.pojo.datatype.FieldDefinition import FieldType, AbstractVel
|
|
|
7
7
|
from sapiopylib.rest.pojo.eln.ElnExperiment import ElnExperiment
|
|
8
8
|
from sapiopylib.rest.pojo.eln.ExperimentEntry import ExperimentEntry
|
|
9
9
|
from sapiopylib.rest.pojo.eln.SapioELNEnums import ElnBaseDataType
|
|
10
|
+
from sapiopylib.rest.pojo.eln.eln_headings import ElnExperimentTab
|
|
10
11
|
from sapiopylib.rest.pojo.webhook.WebhookContext import SapioWebhookContext
|
|
11
12
|
from sapiopylib.rest.utils.Protocols import ElnExperimentProtocol, ElnEntryStep
|
|
12
13
|
from sapiopylib.rest.utils.recordmodel.PyRecordModel import PyRecordModel, AbstractRecordModel
|
|
@@ -219,7 +220,9 @@ class AliasUtil:
|
|
|
219
220
|
# noinspection PyTypeChecker
|
|
220
221
|
fields: FieldMap = record.get_fields()
|
|
221
222
|
else:
|
|
222
|
-
|
|
223
|
+
# TI-47593: Copy the record's fields by using the get() method instead of copy_to_dict() so that date
|
|
224
|
+
# macros get translated to valid field values.
|
|
225
|
+
fields: FieldMap = {f: record.fields.get(f) for f in record.fields}
|
|
223
226
|
# PR-47457: Only include the record ID if the caller requests it, since including the record ID can break
|
|
224
227
|
# callbacks in certain circumstances if the record ID is negative.
|
|
225
228
|
if include_record_id:
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
from enum import Enum
|
|
2
|
+
from typing import Iterable, Any, Collection
|
|
3
|
+
|
|
4
|
+
from sapiopycommons.general.exceptions import SapioException
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class ArrayTransformation(Enum):
|
|
8
|
+
"""
|
|
9
|
+
An enumeration of the different transformations that can be applied to a 2D array.
|
|
10
|
+
"""
|
|
11
|
+
ROTATE_CLOCKWISE = 0
|
|
12
|
+
ROTATE_COUNTER_CLOCKWISE = 1
|
|
13
|
+
ROTATE_180_DEGREES = 2
|
|
14
|
+
MIRROR_HORIZONTAL = 3
|
|
15
|
+
MIRROR_VERTICAL = 4
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
# FR-47524: Create a DataStructureUtils class that implements various collection utility functions from our Java
|
|
19
|
+
# libraries.
|
|
20
|
+
class DataStructureUtil:
|
|
21
|
+
"""
|
|
22
|
+
Utility class for working with data structures. Copies from ListUtil, SetUtil, and various other classes in
|
|
23
|
+
our Java library.
|
|
24
|
+
"""
|
|
25
|
+
@staticmethod
|
|
26
|
+
def find_first_or_none(values: Iterable[Any]) -> Any | None:
|
|
27
|
+
"""
|
|
28
|
+
Get the first value from an iterable, or None if the iterable is empty.
|
|
29
|
+
|
|
30
|
+
:param values: An iterable of values.
|
|
31
|
+
:return: The first value from the input, or None if the input is empty.
|
|
32
|
+
"""
|
|
33
|
+
return next(iter(values), None)
|
|
34
|
+
|
|
35
|
+
@staticmethod
|
|
36
|
+
def remove_null_values(values: Iterable[Any]) -> list[Any]:
|
|
37
|
+
"""
|
|
38
|
+
Remove null values from a list.
|
|
39
|
+
|
|
40
|
+
:param values: An iterable of values.
|
|
41
|
+
:return: A list containing all the non-null values from the input.
|
|
42
|
+
"""
|
|
43
|
+
return [value for value in values if value is not None]
|
|
44
|
+
|
|
45
|
+
@staticmethod
|
|
46
|
+
def transform_2d_array(values: Collection[Collection[Any]], transformation: ArrayTransformation) \
|
|
47
|
+
-> Collection[Collection[Any]]:
|
|
48
|
+
"""
|
|
49
|
+
Perform a transformation on a 2D list.
|
|
50
|
+
|
|
51
|
+
:param values: An iterable of iterables. The iterables should all be of the same size.
|
|
52
|
+
:param transformation: The transformation to apply to the input.
|
|
53
|
+
:return: A new 2D list containing the input transformed according to the specified transformation.
|
|
54
|
+
"""
|
|
55
|
+
x: int = len(values)
|
|
56
|
+
for row in values:
|
|
57
|
+
y = len(row)
|
|
58
|
+
if y != x:
|
|
59
|
+
raise SapioException(f"Input must be a square 2D array. The provided array has a length of {x} but "
|
|
60
|
+
f"at least one row has a length of {y}.")
|
|
61
|
+
|
|
62
|
+
match transformation:
|
|
63
|
+
case ArrayTransformation.ROTATE_CLOCKWISE:
|
|
64
|
+
return [list(row) for row in zip(*values[::-1])]
|
|
65
|
+
case ArrayTransformation.ROTATE_COUNTER_CLOCKWISE:
|
|
66
|
+
return [list(row) for row in zip(*values)][::-1]
|
|
67
|
+
case ArrayTransformation.ROTATE_180_DEGREES:
|
|
68
|
+
return [row[::-1] for row in values[::-1]]
|
|
69
|
+
case ArrayTransformation.MIRROR_HORIZONTAL:
|
|
70
|
+
return [list(row[::-1]) for row in values]
|
|
71
|
+
case ArrayTransformation.MIRROR_VERTICAL:
|
|
72
|
+
return values[::-1]
|
|
73
|
+
|
|
74
|
+
raise SapioException(f"Invalid transformation: {transformation}")
|
|
75
|
+
|
|
76
|
+
@staticmethod
|
|
77
|
+
def flatten_to_list(values: Iterable[Iterable[Any]]) -> list[Any]:
|
|
78
|
+
"""
|
|
79
|
+
Flatten a list of lists into a single list.
|
|
80
|
+
|
|
81
|
+
:param values: An iterable of iterables.
|
|
82
|
+
:return: A single list containing all the values from the input. Elements are in the order they appear in the
|
|
83
|
+
input.
|
|
84
|
+
"""
|
|
85
|
+
return [item for sublist in values for item in sublist]
|
|
86
|
+
|
|
87
|
+
@staticmethod
|
|
88
|
+
def flatten_to_set(values: Iterable[Iterable[Any]]) -> set[Any]:
|
|
89
|
+
"""
|
|
90
|
+
Flatten a list of lists into a single set.
|
|
91
|
+
|
|
92
|
+
:param values: An iterable of iterables.
|
|
93
|
+
:return: A single set containing all the values from the input. Elements are in the order they appear in the
|
|
94
|
+
input.
|
|
95
|
+
"""
|
|
96
|
+
return {item for subset in values for item in subset}
|
|
97
|
+
|
|
98
|
+
@staticmethod
|
|
99
|
+
def invert_dictionary(dictionary: dict[Any, Any], list_values: bool = False) \
|
|
100
|
+
-> dict[Any, Any] | dict[Any, list[Any]]:
|
|
101
|
+
"""
|
|
102
|
+
Invert a dictionary, swapping keys and values. Note that the values of the input dictionary must be hashable.
|
|
103
|
+
|
|
104
|
+
:param dictionary: A dictionary to invert.
|
|
105
|
+
:param list_values: If false, keys that share the same value in the input dictionary will be overwritten in
|
|
106
|
+
the output dictionary so that only the last key remains. If true, the values of the output dictionary will
|
|
107
|
+
be lists where input keys that share the same value will be stored together.
|
|
108
|
+
:return: A new dictionary with the keys and values swapped.
|
|
109
|
+
"""
|
|
110
|
+
if list_values:
|
|
111
|
+
inverted = {}
|
|
112
|
+
for key, value in dictionary.items():
|
|
113
|
+
inverted.setdefault(value, []).append(key)
|
|
114
|
+
return inverted
|
|
115
|
+
return {value: key for key, value in dictionary.items()}
|
|
@@ -10,8 +10,7 @@ class SapioNavigationLinker:
|
|
|
10
10
|
Given a URL to a system's webservice API (example: https://company.exemplareln.com/webservice/api), construct
|
|
11
11
|
URLs for navigation links to various locations in the system.
|
|
12
12
|
"""
|
|
13
|
-
|
|
14
|
-
webservice_url: str
|
|
13
|
+
base_url: str
|
|
15
14
|
|
|
16
15
|
def __init__(self, url: str | SapioUser | SapioWebhookContext):
|
|
17
16
|
"""
|
|
@@ -22,14 +21,7 @@ class SapioNavigationLinker:
|
|
|
22
21
|
url = url.user.url
|
|
23
22
|
elif isinstance(url, SapioUser):
|
|
24
23
|
url = url.url
|
|
25
|
-
self.
|
|
26
|
-
self.client_url = url.rstrip("/").replace('webservice/api', 'veloxClient')
|
|
27
|
-
|
|
28
|
-
def homepage(self) -> str:
|
|
29
|
-
"""
|
|
30
|
-
:return: A URL for navigating to the system's homepage.
|
|
31
|
-
"""
|
|
32
|
-
return self.client_url + "/#view=homepage"
|
|
24
|
+
self.base_url = url.rstrip("/").replace('webservice/api', 'veloxClient')
|
|
33
25
|
|
|
34
26
|
def data_record(self, record_identifier: RecordIdentifier, data_type_name: DataTypeIdentifier | None = None) -> str:
|
|
35
27
|
"""
|
|
@@ -47,7 +39,7 @@ class SapioNavigationLinker:
|
|
|
47
39
|
if not data_type_name:
|
|
48
40
|
raise SapioException("Unable to create a data record link without a data type name. "
|
|
49
41
|
"Only a record ID was provided.")
|
|
50
|
-
return self.
|
|
42
|
+
return self.base_url + f"/#dataType={data_type_name};recordId={record_id};view=dataRecord"
|
|
51
43
|
|
|
52
44
|
def experiment(self, experiment: ExperimentIdentifier) -> str:
|
|
53
45
|
"""
|
|
@@ -55,4 +47,4 @@ class SapioNavigationLinker:
|
|
|
55
47
|
object, experiment protocol, or a notebook ID.
|
|
56
48
|
:return: A URL for navigating to the input experiment.
|
|
57
49
|
"""
|
|
58
|
-
return self.
|
|
50
|
+
return self.base_url + f"/#notebookExperimentId={AliasUtil.to_notebook_id(experiment)};view=eln"
|
|
@@ -105,7 +105,8 @@ class QueueItemHandler:
|
|
|
105
105
|
"""
|
|
106
106
|
self.user = AliasUtil.to_sapio_user(context)
|
|
107
107
|
self.rec_handler = RecordHandler(self.user)
|
|
108
|
-
if
|
|
108
|
+
# PR-47565: Only initialize a ProcessQueueContext if the given context object has context_data.
|
|
109
|
+
if isinstance(context, SapioWebhookContext) and context.context_data:
|
|
109
110
|
self.context = ProcessQueueContext(context)
|
|
110
111
|
else:
|
|
111
112
|
self.context = None
|