sapiopycommons 2025.2.20a441__py3-none-any.whl → 2025.2.20a443__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/ai/tool_of_tools.py +32 -16
- {sapiopycommons-2025.2.20a441.dist-info → sapiopycommons-2025.2.20a443.dist-info}/METADATA +1 -1
- {sapiopycommons-2025.2.20a441.dist-info → sapiopycommons-2025.2.20a443.dist-info}/RECORD +5 -5
- {sapiopycommons-2025.2.20a441.dist-info → sapiopycommons-2025.2.20a443.dist-info}/WHEEL +0 -0
- {sapiopycommons-2025.2.20a441.dist-info → sapiopycommons-2025.2.20a443.dist-info}/licenses/LICENSE +0 -0
|
@@ -2,7 +2,7 @@ import base64
|
|
|
2
2
|
import io
|
|
3
3
|
import math
|
|
4
4
|
import re
|
|
5
|
-
from typing import Final, Mapping, Any
|
|
5
|
+
from typing import Final, Mapping, Any, cast
|
|
6
6
|
|
|
7
7
|
import requests
|
|
8
8
|
from pandas import DataFrame
|
|
@@ -18,7 +18,8 @@ from sapiopylib.rest.pojo.chartdata.DashboardEnums import ChartGroupingType, Cha
|
|
|
18
18
|
from sapiopylib.rest.pojo.chartdata.DashboardSeries import GaugeChartSeries
|
|
19
19
|
from sapiopylib.rest.pojo.datatype.DataType import DataTypeDefinition
|
|
20
20
|
from sapiopylib.rest.pojo.datatype.DataTypeLayout import DataTypeLayout, TableLayout
|
|
21
|
-
from sapiopylib.rest.pojo.datatype.FieldDefinition import AbstractVeloxFieldDefinition, FieldType
|
|
21
|
+
from sapiopylib.rest.pojo.datatype.FieldDefinition import AbstractVeloxFieldDefinition, FieldType, \
|
|
22
|
+
VeloxStringFieldDefinition
|
|
22
23
|
from sapiopylib.rest.pojo.eln.ElnEntryPosition import ElnEntryPosition
|
|
23
24
|
from sapiopylib.rest.pojo.eln.ElnExperiment import ElnExperiment
|
|
24
25
|
from sapiopylib.rest.pojo.eln.ExperimentEntry import ExperimentEntry
|
|
@@ -310,17 +311,39 @@ class AiHelper:
|
|
|
310
311
|
# Determine which fields in the JSON can be used to create field definitions.
|
|
311
312
|
fb = FieldBuilder()
|
|
312
313
|
fields: list[AbstractVeloxFieldDefinition] = []
|
|
313
|
-
|
|
314
|
+
fields_by_json_key: dict[str, AbstractVeloxFieldDefinition] = {}
|
|
315
|
+
string_field_lengths: dict[str, int] = {}
|
|
314
316
|
for key, value in json_list[0].items():
|
|
315
|
-
|
|
317
|
+
# The field name is the JSON key name, but with spaces and dashes replaced by underscores and with a leading
|
|
318
|
+
# underscore added if the field name starts with a number.
|
|
319
|
+
field_name: str = key.strip()
|
|
320
|
+
if " " in field_name:
|
|
321
|
+
field_name = field_name.replace(" ", "_")
|
|
322
|
+
if "-" in field_name:
|
|
323
|
+
field_name = field_name.replace("-", "_")
|
|
324
|
+
if field_name[0].isnumeric():
|
|
325
|
+
field_name = "_" + field_name
|
|
326
|
+
|
|
316
327
|
if isinstance(value, str):
|
|
317
328
|
field = fb.string_field(field_name, display_name=key)
|
|
318
329
|
fields.append(field)
|
|
319
|
-
|
|
330
|
+
fields_by_json_key[key] = field
|
|
331
|
+
string_field_lengths[key] = 100
|
|
320
332
|
elif isinstance(value, (int, float)):
|
|
321
333
|
field = fb.double_field(field_name, display_name=key, precision=3)
|
|
322
334
|
fields.append(field)
|
|
323
|
-
|
|
335
|
+
fields_by_json_key[key] = field
|
|
336
|
+
|
|
337
|
+
# Determine the max length of each string field.
|
|
338
|
+
for values in json_list:
|
|
339
|
+
for key in string_field_lengths:
|
|
340
|
+
length: int = len(values.get(key)) if values.get(key) else 0
|
|
341
|
+
string_field_lengths[key] = max(string_field_lengths[key], length)
|
|
342
|
+
|
|
343
|
+
# Update the max length of each string field.
|
|
344
|
+
for key in string_field_lengths:
|
|
345
|
+
field = cast(VeloxStringFieldDefinition, fields_by_json_key[key])
|
|
346
|
+
field.max_length = string_field_lengths[key]
|
|
324
347
|
|
|
325
348
|
# Sort the JSON list if requested.
|
|
326
349
|
if sort_field and sort_direction != SortDirection.NONE:
|
|
@@ -340,7 +363,7 @@ class AiHelper:
|
|
|
340
363
|
field_maps: list[dict[str, Any]] = []
|
|
341
364
|
for json_dict in json_list:
|
|
342
365
|
field_map: dict[str, Any] = {}
|
|
343
|
-
for key, field in
|
|
366
|
+
for key, field in fields_by_json_key.items():
|
|
344
367
|
# Watch out for NaN values or other special values in numeric columns.
|
|
345
368
|
val: Any = json_dict.get(key)
|
|
346
369
|
if (field.data_field_type == FieldType.DOUBLE
|
|
@@ -497,14 +520,14 @@ class AiHelper:
|
|
|
497
520
|
with io.BytesIO(image) as bytes_io:
|
|
498
521
|
self.dr_man.set_record_image(record, bytes_io)
|
|
499
522
|
|
|
500
|
-
def create_bar_chart(self, entry_name: str,
|
|
523
|
+
def create_bar_chart(self, entry_name: str, tab: ElnExperimentTab, source_entry: ExperimentEntry,
|
|
501
524
|
x_axis: str, y_axis: str) -> ExperimentEntry:
|
|
502
525
|
"""
|
|
503
526
|
Create a bar chart in the experiment based on the contents of the given source entry.
|
|
504
527
|
|
|
505
528
|
:param entry_name: The name of the bar chart.
|
|
506
|
-
:param source_entry: The source entry to base the bar chart on.
|
|
507
529
|
:param tab: The tab to create the bar chart in.
|
|
530
|
+
:param source_entry: The source entry to base the bar chart on.
|
|
508
531
|
:param x_axis: The field to use for the x-axis.
|
|
509
532
|
:param y_axis: The field to use for the y-axis.
|
|
510
533
|
:return: The newly created bar chart entry.
|
|
@@ -676,13 +699,6 @@ class ToolOfToolsHelper:
|
|
|
676
699
|
dash_update_crit.column_span = 2
|
|
677
700
|
self.eln_man.update_experiment_entry(self.exp_id, self.progress_gauge_entry.get_id(), dash_update_crit)
|
|
678
701
|
|
|
679
|
-
# TODO: Bulk updates aren't working?
|
|
680
|
-
# self.eln_man.update_experiment_entries(self.exp_id, {
|
|
681
|
-
# self.progress_entry.get_id(): form_update_crit,
|
|
682
|
-
# self.progress_gauge_entry.get_id(): dash_update_crit,
|
|
683
|
-
# self.description_entry.get_id(): text_update_crit
|
|
684
|
-
# })
|
|
685
|
-
|
|
686
702
|
# Create a results entry if this tool produces result records.
|
|
687
703
|
if self.results_data_type:
|
|
688
704
|
results_entry = ELNStepFactory.create_table_step(self.helper.protocol, f"{self.name} Results",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.3
|
|
2
2
|
Name: sapiopycommons
|
|
3
|
-
Version: 2025.2.
|
|
3
|
+
Version: 2025.2.20a443
|
|
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>
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
sapiopycommons/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
2
|
sapiopycommons/ai/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
3
|
-
sapiopycommons/ai/tool_of_tools.py,sha256=
|
|
3
|
+
sapiopycommons/ai/tool_of_tools.py,sha256=SlicwK03u3xcUXCJXwycyfmFxj7dZL0qII6ERSHtno4,40226
|
|
4
4
|
sapiopycommons/callbacks/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
5
5
|
sapiopycommons/callbacks/callback_util.py,sha256=68lPK8GtE6zd8C0fQaMLxT57PtU-6HnO37Zk-u56Mrs,129933
|
|
6
6
|
sapiopycommons/callbacks/field_builder.py,sha256=p2XacN99MuKk3ite8GAqstUMpixqugul2CsC4gB83-o,38620
|
|
@@ -58,7 +58,7 @@ sapiopycommons/webhook/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3
|
|
|
58
58
|
sapiopycommons/webhook/webhook_context.py,sha256=D793uLsb1691SalaPnBUk3rOSxn_hYLhdvkaIxjNXss,1909
|
|
59
59
|
sapiopycommons/webhook/webhook_handlers.py,sha256=L0HetSm43NvA5KyW3xbLpGFh2DbAaeZJVtXIEl2fvV8,39689
|
|
60
60
|
sapiopycommons/webhook/webservice_handlers.py,sha256=Y5dHx_UFWFuSqaoPL6Re-fsKYRuxvCWZ8bj6KSZ3jfM,14285
|
|
61
|
-
sapiopycommons-2025.2.
|
|
62
|
-
sapiopycommons-2025.2.
|
|
63
|
-
sapiopycommons-2025.2.
|
|
64
|
-
sapiopycommons-2025.2.
|
|
61
|
+
sapiopycommons-2025.2.20a443.dist-info/METADATA,sha256=c8AWeg4g5tywBd_vxdNmcu-FWp7l6PAvdoydtCTE4cQ,3143
|
|
62
|
+
sapiopycommons-2025.2.20a443.dist-info/WHEEL,sha256=C2FUgwZgiLbznR-k0b_5k3Ai_1aASOXDss3lzCUsUug,87
|
|
63
|
+
sapiopycommons-2025.2.20a443.dist-info/licenses/LICENSE,sha256=HyVuytGSiAUQ6ErWBHTqt1iSGHhLmlC8fO7jTCuR8dU,16725
|
|
64
|
+
sapiopycommons-2025.2.20a443.dist-info/RECORD,,
|
|
File without changes
|
{sapiopycommons-2025.2.20a441.dist-info → sapiopycommons-2025.2.20a443.dist-info}/licenses/LICENSE
RENAMED
|
File without changes
|