sapiopycommons 2025.2.17a438__tar.gz → 2025.2.17a439__tar.gz

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.

Files changed (83) hide show
  1. {sapiopycommons-2025.2.17a438 → sapiopycommons-2025.2.17a439}/PKG-INFO +1 -1
  2. {sapiopycommons-2025.2.17a438 → sapiopycommons-2025.2.17a439}/pyproject.toml +1 -1
  3. sapiopycommons-2025.2.17a438/src/sapiopycommons/ai/tool_of_tools.py +0 -782
  4. sapiopycommons-2025.2.17a438/src/sapiopycommons/webhook/__init__.py +0 -0
  5. {sapiopycommons-2025.2.17a438 → sapiopycommons-2025.2.17a439}/.gitignore +0 -0
  6. {sapiopycommons-2025.2.17a438 → sapiopycommons-2025.2.17a439}/LICENSE +0 -0
  7. {sapiopycommons-2025.2.17a438 → sapiopycommons-2025.2.17a439}/README.md +0 -0
  8. {sapiopycommons-2025.2.17a438 → sapiopycommons-2025.2.17a439}/src/sapiopycommons/__init__.py +0 -0
  9. {sapiopycommons-2025.2.17a438/src/sapiopycommons/ai → sapiopycommons-2025.2.17a439/src/sapiopycommons/callbacks}/__init__.py +0 -0
  10. {sapiopycommons-2025.2.17a438 → sapiopycommons-2025.2.17a439}/src/sapiopycommons/callbacks/callback_util.py +0 -0
  11. {sapiopycommons-2025.2.17a438 → sapiopycommons-2025.2.17a439}/src/sapiopycommons/callbacks/field_builder.py +0 -0
  12. {sapiopycommons-2025.2.17a438 → sapiopycommons-2025.2.17a439}/src/sapiopycommons/chem/IndigoMolecules.py +0 -0
  13. {sapiopycommons-2025.2.17a438 → sapiopycommons-2025.2.17a439}/src/sapiopycommons/chem/Molecules.py +0 -0
  14. {sapiopycommons-2025.2.17a438/src/sapiopycommons/callbacks → sapiopycommons-2025.2.17a439/src/sapiopycommons/chem}/__init__.py +0 -0
  15. {sapiopycommons-2025.2.17a438/src/sapiopycommons/chem → sapiopycommons-2025.2.17a439/src/sapiopycommons/customreport}/__init__.py +0 -0
  16. {sapiopycommons-2025.2.17a438 → sapiopycommons-2025.2.17a439}/src/sapiopycommons/customreport/auto_pagers.py +0 -0
  17. {sapiopycommons-2025.2.17a438 → sapiopycommons-2025.2.17a439}/src/sapiopycommons/customreport/column_builder.py +0 -0
  18. {sapiopycommons-2025.2.17a438 → sapiopycommons-2025.2.17a439}/src/sapiopycommons/customreport/custom_report_builder.py +0 -0
  19. {sapiopycommons-2025.2.17a438 → sapiopycommons-2025.2.17a439}/src/sapiopycommons/customreport/term_builder.py +0 -0
  20. {sapiopycommons-2025.2.17a438/src/sapiopycommons/customreport → sapiopycommons-2025.2.17a439/src/sapiopycommons/datatype}/__init__.py +0 -0
  21. {sapiopycommons-2025.2.17a438 → sapiopycommons-2025.2.17a439}/src/sapiopycommons/datatype/attachment_util.py +0 -0
  22. {sapiopycommons-2025.2.17a438 → sapiopycommons-2025.2.17a439}/src/sapiopycommons/datatype/data_fields.py +0 -0
  23. {sapiopycommons-2025.2.17a438 → sapiopycommons-2025.2.17a439}/src/sapiopycommons/datatype/pseudo_data_types.py +0 -0
  24. {sapiopycommons-2025.2.17a438/src/sapiopycommons/datatype → sapiopycommons-2025.2.17a439/src/sapiopycommons/eln}/__init__.py +0 -0
  25. {sapiopycommons-2025.2.17a438 → sapiopycommons-2025.2.17a439}/src/sapiopycommons/eln/experiment_handler.py +0 -0
  26. {sapiopycommons-2025.2.17a438 → sapiopycommons-2025.2.17a439}/src/sapiopycommons/eln/experiment_report_util.py +0 -0
  27. {sapiopycommons-2025.2.17a438 → sapiopycommons-2025.2.17a439}/src/sapiopycommons/eln/plate_designer.py +0 -0
  28. {sapiopycommons-2025.2.17a438/src/sapiopycommons/eln → sapiopycommons-2025.2.17a439/src/sapiopycommons/files}/__init__.py +0 -0
  29. {sapiopycommons-2025.2.17a438 → sapiopycommons-2025.2.17a439}/src/sapiopycommons/files/complex_data_loader.py +0 -0
  30. {sapiopycommons-2025.2.17a438 → sapiopycommons-2025.2.17a439}/src/sapiopycommons/files/file_bridge.py +0 -0
  31. {sapiopycommons-2025.2.17a438 → sapiopycommons-2025.2.17a439}/src/sapiopycommons/files/file_bridge_handler.py +0 -0
  32. {sapiopycommons-2025.2.17a438 → sapiopycommons-2025.2.17a439}/src/sapiopycommons/files/file_data_handler.py +0 -0
  33. {sapiopycommons-2025.2.17a438 → sapiopycommons-2025.2.17a439}/src/sapiopycommons/files/file_util.py +0 -0
  34. {sapiopycommons-2025.2.17a438 → sapiopycommons-2025.2.17a439}/src/sapiopycommons/files/file_validator.py +0 -0
  35. {sapiopycommons-2025.2.17a438 → sapiopycommons-2025.2.17a439}/src/sapiopycommons/files/file_writer.py +0 -0
  36. {sapiopycommons-2025.2.17a438 → sapiopycommons-2025.2.17a439}/src/sapiopycommons/flowcyto/flow_cyto.py +0 -0
  37. {sapiopycommons-2025.2.17a438 → sapiopycommons-2025.2.17a439}/src/sapiopycommons/flowcyto/flowcyto_data.py +0 -0
  38. {sapiopycommons-2025.2.17a438/src/sapiopycommons/files → sapiopycommons-2025.2.17a439/src/sapiopycommons/general}/__init__.py +0 -0
  39. {sapiopycommons-2025.2.17a438 → sapiopycommons-2025.2.17a439}/src/sapiopycommons/general/accession_service.py +0 -0
  40. {sapiopycommons-2025.2.17a438 → sapiopycommons-2025.2.17a439}/src/sapiopycommons/general/aliases.py +0 -0
  41. {sapiopycommons-2025.2.17a438 → sapiopycommons-2025.2.17a439}/src/sapiopycommons/general/audit_log.py +0 -0
  42. {sapiopycommons-2025.2.17a438 → sapiopycommons-2025.2.17a439}/src/sapiopycommons/general/custom_report_util.py +0 -0
  43. {sapiopycommons-2025.2.17a438 → sapiopycommons-2025.2.17a439}/src/sapiopycommons/general/directive_util.py +0 -0
  44. {sapiopycommons-2025.2.17a438 → sapiopycommons-2025.2.17a439}/src/sapiopycommons/general/exceptions.py +0 -0
  45. {sapiopycommons-2025.2.17a438 → sapiopycommons-2025.2.17a439}/src/sapiopycommons/general/popup_util.py +0 -0
  46. {sapiopycommons-2025.2.17a438 → sapiopycommons-2025.2.17a439}/src/sapiopycommons/general/sapio_links.py +0 -0
  47. {sapiopycommons-2025.2.17a438 → sapiopycommons-2025.2.17a439}/src/sapiopycommons/general/storage_util.py +0 -0
  48. {sapiopycommons-2025.2.17a438 → sapiopycommons-2025.2.17a439}/src/sapiopycommons/general/time_util.py +0 -0
  49. {sapiopycommons-2025.2.17a438 → sapiopycommons-2025.2.17a439}/src/sapiopycommons/multimodal/multimodal.py +0 -0
  50. {sapiopycommons-2025.2.17a438 → sapiopycommons-2025.2.17a439}/src/sapiopycommons/multimodal/multimodal_data.py +0 -0
  51. {sapiopycommons-2025.2.17a438/src/sapiopycommons/general → sapiopycommons-2025.2.17a439/src/sapiopycommons/processtracking}/__init__.py +0 -0
  52. {sapiopycommons-2025.2.17a438 → sapiopycommons-2025.2.17a439}/src/sapiopycommons/processtracking/custom_workflow_handler.py +0 -0
  53. {sapiopycommons-2025.2.17a438 → sapiopycommons-2025.2.17a439}/src/sapiopycommons/processtracking/endpoints.py +0 -0
  54. {sapiopycommons-2025.2.17a438/src/sapiopycommons/processtracking → sapiopycommons-2025.2.17a439/src/sapiopycommons/recordmodel}/__init__.py +0 -0
  55. {sapiopycommons-2025.2.17a438 → sapiopycommons-2025.2.17a439}/src/sapiopycommons/recordmodel/record_handler.py +0 -0
  56. {sapiopycommons-2025.2.17a438/src/sapiopycommons/recordmodel → sapiopycommons-2025.2.17a439/src/sapiopycommons/rules}/__init__.py +0 -0
  57. {sapiopycommons-2025.2.17a438 → sapiopycommons-2025.2.17a439}/src/sapiopycommons/rules/eln_rule_handler.py +0 -0
  58. {sapiopycommons-2025.2.17a438 → sapiopycommons-2025.2.17a439}/src/sapiopycommons/rules/on_save_rule_handler.py +0 -0
  59. {sapiopycommons-2025.2.17a438 → sapiopycommons-2025.2.17a439}/src/sapiopycommons/samples/aliquot.py +0 -0
  60. {sapiopycommons-2025.2.17a438/src/sapiopycommons/rules → sapiopycommons-2025.2.17a439/src/sapiopycommons/sftpconnect}/__init__.py +0 -0
  61. {sapiopycommons-2025.2.17a438 → sapiopycommons-2025.2.17a439}/src/sapiopycommons/sftpconnect/sftp_builder.py +0 -0
  62. {sapiopycommons-2025.2.17a438/src/sapiopycommons/sftpconnect → sapiopycommons-2025.2.17a439/src/sapiopycommons/webhook}/__init__.py +0 -0
  63. {sapiopycommons-2025.2.17a438 → sapiopycommons-2025.2.17a439}/src/sapiopycommons/webhook/webhook_context.py +0 -0
  64. {sapiopycommons-2025.2.17a438 → sapiopycommons-2025.2.17a439}/src/sapiopycommons/webhook/webhook_handlers.py +0 -0
  65. {sapiopycommons-2025.2.17a438 → sapiopycommons-2025.2.17a439}/src/sapiopycommons/webhook/webservice_handlers.py +0 -0
  66. {sapiopycommons-2025.2.17a438 → sapiopycommons-2025.2.17a439}/tests/AF-A0A009IHW8-F1-model_v4.cif +0 -0
  67. {sapiopycommons-2025.2.17a438 → sapiopycommons-2025.2.17a439}/tests/_do_not_add_init_py_here +0 -0
  68. {sapiopycommons-2025.2.17a438 → sapiopycommons-2025.2.17a439}/tests/accession_test.py +0 -0
  69. {sapiopycommons-2025.2.17a438 → sapiopycommons-2025.2.17a439}/tests/aliquot_test.py +0 -0
  70. {sapiopycommons-2025.2.17a438 → sapiopycommons-2025.2.17a439}/tests/bio_reg_test.py +0 -0
  71. {sapiopycommons-2025.2.17a438 → sapiopycommons-2025.2.17a439}/tests/chem_test.py +0 -0
  72. {sapiopycommons-2025.2.17a438 → sapiopycommons-2025.2.17a439}/tests/chem_test_curation_queue.py +0 -0
  73. {sapiopycommons-2025.2.17a438 → sapiopycommons-2025.2.17a439}/tests/curation_queue_test.sdf +0 -0
  74. {sapiopycommons-2025.2.17a438 → sapiopycommons-2025.2.17a439}/tests/data_type_models.py +0 -0
  75. {sapiopycommons-2025.2.17a438 → sapiopycommons-2025.2.17a439}/tests/flowcyto/101_DEN084Y5_15_E01_008_clean.fcs +0 -0
  76. {sapiopycommons-2025.2.17a438 → sapiopycommons-2025.2.17a439}/tests/flowcyto/101_DEN084Y5_15_E03_009_clean.fcs +0 -0
  77. {sapiopycommons-2025.2.17a438 → sapiopycommons-2025.2.17a439}/tests/flowcyto/101_DEN084Y5_15_E05_010_clean.fcs +0 -0
  78. {sapiopycommons-2025.2.17a438 → sapiopycommons-2025.2.17a439}/tests/flowcyto/8_color_ICS.wsp +0 -0
  79. {sapiopycommons-2025.2.17a438 → sapiopycommons-2025.2.17a439}/tests/flowcyto/COVID19_W_001_O.fcs +0 -0
  80. {sapiopycommons-2025.2.17a438 → sapiopycommons-2025.2.17a439}/tests/flowcyto_test.py +0 -0
  81. {sapiopycommons-2025.2.17a438 → sapiopycommons-2025.2.17a439}/tests/kappa.chains.fasta +0 -0
  82. {sapiopycommons-2025.2.17a438 → sapiopycommons-2025.2.17a439}/tests/mafft_test.py +0 -0
  83. {sapiopycommons-2025.2.17a438 → sapiopycommons-2025.2.17a439}/tests/test.gb +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: sapiopycommons
3
- Version: 2025.2.17a438
3
+ Version: 2025.2.17a439
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>
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "sapiopycommons"
7
- version='2025.02.17a438'
7
+ version='2025.02.17a439'
8
8
  authors = [
9
9
  { name="Jonathan Steck", email="jsteck@sapiosciences.com" },
10
10
  { name="Yechen Qiao", email="yqiao@sapiosciences.com" },
@@ -1,782 +0,0 @@
1
- import base64
2
- import io
3
- import math
4
- import re
5
- from typing import Final, Mapping, Any
6
-
7
- from pandas import DataFrame
8
- from sapiopylib.rest.DataRecordManagerService import DataRecordManager
9
- from sapiopylib.rest.DataTypeService import DataTypeManager
10
- from sapiopylib.rest.ELNService import ElnManager
11
- from sapiopylib.rest.User import SapioUser
12
- from sapiopylib.rest.pojo.DataRecord import DataRecord
13
- from sapiopylib.rest.pojo.Sort import SortDirection
14
- from sapiopylib.rest.pojo.chartdata.DashboardDefinition import GaugeChartDefinition
15
- from sapiopylib.rest.pojo.chartdata.DashboardEnums import ChartGroupingType, ChartOperationType
16
- from sapiopylib.rest.pojo.chartdata.DashboardSeries import GaugeChartSeries
17
- from sapiopylib.rest.pojo.datatype.DataType import DataTypeDefinition
18
- from sapiopylib.rest.pojo.datatype.DataTypeLayout import DataTypeLayout, TableLayout
19
- from sapiopylib.rest.pojo.datatype.FieldDefinition import AbstractVeloxFieldDefinition, FieldType
20
- from sapiopylib.rest.pojo.eln.ElnEntryPosition import ElnEntryPosition
21
- from sapiopylib.rest.pojo.eln.ElnExperiment import ElnExperiment
22
- from sapiopylib.rest.pojo.eln.ExperimentEntry import ExperimentEntry
23
- from sapiopylib.rest.pojo.eln.ExperimentEntryCriteria import ElnEntryCriteria, ElnFormEntryUpdateCriteria, \
24
- ElnDashboardEntryUpdateCriteria, ElnTextEntryUpdateCriteria
25
- from sapiopylib.rest.pojo.eln.SapioELNEnums import ElnEntryType, ElnBaseDataType
26
- from sapiopylib.rest.pojo.eln.eln_headings import ElnExperimentTabAddCriteria, ElnExperimentTab
27
- from sapiopylib.rest.pojo.eln.field_set import ElnFieldSetInfo
28
- from sapiopylib.rest.utils.ProtocolUtils import ELNStepFactory
29
- from sapiopylib.rest.utils.Protocols import ElnEntryStep, ElnExperimentProtocol
30
-
31
- from sapiopycommons.callbacks.field_builder import FieldBuilder
32
- from sapiopycommons.general.aliases import AliasUtil, SapioRecord
33
- from sapiopycommons.general.exceptions import SapioException
34
- from sapiopycommons.general.time_util import TimeUtil
35
- from sapiopycommons.multimodal.multimodal import MultiModalManager
36
- from sapiopycommons.multimodal.multimodal_data import ImageDataRequestPojo
37
-
38
- CREDENTIALS_HEADER: Final[str] = "SAPIO_APP_API_KEY"
39
- API_URL_HEADER: Final[str] = "SAPIO_APP_API_URL"
40
- EXP_ID_HEADER: Final[str] = "EXPERIMENT_ID"
41
- TAB_PREFIX_HEADER: Final[str] = "TAB_PREFIX"
42
-
43
-
44
- # FR-47422: Create utility classes and methods to assist the tool of tools.
45
- def create_tot_headers(url: str, username: str, password: str, experiment_id: int, tab_prefix: str) \
46
- -> dict[str, str]:
47
- """
48
- Create the headers to be passed to a tool of tools endpoint.
49
-
50
- :param url: The webservice URL of the system to make the changes in.
51
- :param username: The username of the user making the changes.
52
- :param password: The password of the user making the changes.
53
- :param experiment_id: The ID of the experiment to make the changes in.
54
- :param tab_prefix: The prefix to use for the tab name that will be created by the tool.
55
- :return: The headers to be passed to the endpoint.
56
- """
57
- # Combine the credentials into the format "username:password"
58
- credentials: str = f"{username}:{password}"
59
- # Encode the credentials to bytes, then encode them using base64,
60
- # and finally convert the result back into a string.
61
- encoded_credentials: str = base64.b64encode(credentials.encode('utf-8')).decode('utf-8')
62
- # Remove the trailing slash from the URL if it exists.
63
- if url.endswith("/"):
64
- url.rstrip("/")
65
- headers: dict[str, str] = {
66
- CREDENTIALS_HEADER: f"Basic {encoded_credentials}",
67
- API_URL_HEADER: url,
68
- EXP_ID_HEADER: str(experiment_id),
69
- TAB_PREFIX_HEADER: tab_prefix
70
- }
71
- return headers
72
-
73
-
74
- def create_user_from_tot_headers(headers: Mapping[str, str]) -> SapioUser:
75
- """
76
- Create a SapioUser object from the headers passed to a tool of tools endpoint.
77
-
78
- :param headers: The headers that were passed to the endpoint.
79
- :return: A SapioUser object created from the headers that can be used to communicate with the Sapio server.
80
- """
81
- headers: dict[str, str] = format_tot_headers(headers)
82
- credentials = (base64.b64decode(headers[CREDENTIALS_HEADER.lower()].removeprefix("Basic "))
83
- .decode("utf-8").split(":", 1))
84
- url: str = headers[API_URL_HEADER.lower()]
85
- if url.endswith("/"):
86
- url.rstrip("/")
87
- return SapioUser(url, username=credentials[0], password=credentials[1])
88
-
89
-
90
- def format_tot_headers(headers: Mapping[str, str]) -> dict[str, str]:
91
- """
92
- Format the headers passed to a tool of tools endpoint to guarantee that the keys are lowercase.
93
-
94
- :param headers: The headers that were passed to the endpoint.
95
- :return: The headers with all keys converted to lowercase. (Conflicting keys will cause one to overwrite the other,
96
- but there should not be any conflicting keys in the headers passed to a tool of tools endpoint.)
97
- """
98
- return {k.lower(): v for k, v in headers.items()}
99
-
100
-
101
- class HtmlFormatter:
102
- """
103
- A class for formatting text in HTML with tag classes supported by the client.
104
- """
105
- TIMESTAMP_TEXT__CSS_CLASS_NAME: Final[str] = "timestamp-text"
106
- HEADER_1_TEXT__CSS_CLASS_NAME: Final[str] = "header1-text"
107
- HEADER_2_TEXT__CSS_CLASS_NAME: Final[str] = "header2-text"
108
- HEADER_3_TEXT__CSS_CLASS_NAME: Final[str] = "header3-text"
109
- BODY_TEXT__CSS_CLASS_NAME: Final[str] = "body-text"
110
- CAPTION_TEXT__CSS_CLASS_NAME: Final[str] = "caption-text"
111
-
112
- @staticmethod
113
- def timestamp(text: str) -> str:
114
- """
115
- Given a text string, return that same text string HTML formatted using the timestamp CSS class.
116
-
117
- :param text: The text to format.
118
- :return: The HTML formatted text.
119
- """
120
- return f"<span class=\"{HtmlFormatter.TIMESTAMP_TEXT__CSS_CLASS_NAME}\">{text}</span>"
121
-
122
- @staticmethod
123
- def header_1(text: str) -> str:
124
- """
125
- Given a text string, return that same text string HTML formatted using the header 1 CSS class.
126
-
127
- :param text: The text to format.
128
- :return: The HTML formatted text.
129
- """
130
- return f"<span class=\"{HtmlFormatter.HEADER_1_TEXT__CSS_CLASS_NAME}\">{text}</span>"
131
-
132
- @staticmethod
133
- def header_2(text: str) -> str:
134
- """
135
- Given a text string, return that same text string HTML formatted using the header 2 CSS class.
136
-
137
- :param text: The text to format.
138
- :return: The HTML formatted text.
139
- """
140
- return f"<span class=\"{HtmlFormatter.HEADER_2_TEXT__CSS_CLASS_NAME}\">{text}</span>"
141
-
142
- @staticmethod
143
- def header_3(text: str) -> str:
144
- """
145
- Given a text string, return that same text string HTML formatted using the header 3 CSS class.
146
-
147
- :param text: The text to format.
148
- :return: The HTML formatted text.
149
- """
150
- return f"<span class=\"{HtmlFormatter.HEADER_3_TEXT__CSS_CLASS_NAME}\">{text}</span>"
151
-
152
- @staticmethod
153
- def body(text: str) -> str:
154
- """
155
- Given a text string, return that same text string HTML formatted using the body CSS class.
156
-
157
- :param text: The text to format.
158
- :return: The HTML formatted text.
159
- """
160
- return f"<span class=\"{HtmlFormatter.BODY_TEXT__CSS_CLASS_NAME}\">{text}</span>"
161
-
162
- @staticmethod
163
- def caption(text: str) -> str:
164
- """
165
- Given a text string, return that same text string HTML formatted using the caption CSS class.
166
-
167
- :param text: The text to format.
168
- :return: The HTML formatted text.
169
- """
170
- return f"<span class=\"{HtmlFormatter.CAPTION_TEXT__CSS_CLASS_NAME}\">{text}</span>"
171
-
172
- @staticmethod
173
- def replace_newlines(text: str) -> str:
174
- """
175
- Given a text string, return that same text string HTML formatted with newlines replaced by HTML line breaks.
176
-
177
- :param text: The text to format.
178
- :return: The HTML formatted text.
179
- """
180
- return re.sub("\r?\n", "<br>", text)
181
-
182
-
183
- class AiHelper:
184
- """
185
- A class with helper methods for the AI to make use of when creating/updating experiment tabs and entries.
186
- """
187
- # Contextual info.
188
- user: SapioUser
189
- exp_id: int
190
-
191
- # Managers.
192
- dr_man: DataRecordManager
193
- eln_man: ElnManager
194
- dt_man: DataTypeManager
195
-
196
- def __init__(self, user: SapioUser, exp_id: int):
197
- """
198
- :param user: The user to send the requests from.
199
- :param exp_id: The ID of the experiment to create the entries in.
200
- """
201
- self.user = user
202
- self.exp_id = exp_id
203
-
204
- self.dr_man = DataRecordManager(self.user)
205
- self.eln_man = ElnManager(self.user)
206
- self.dt_man = DataTypeManager(self.user)
207
-
208
- @property
209
- def protocol(self) -> ElnExperimentProtocol:
210
- """
211
- :return: An experiment protocol object for this helper's experiment. (Recreating a new protocol object every
212
- time this is called since the protocol's cache could be invalidated by things that the AI is doing.)
213
- """
214
- # The experiment name and record ID aren't necessary to know for our purposes.
215
- return ElnExperimentProtocol(ElnExperiment(self.exp_id, "", 0), self.user)
216
-
217
- def create_tab(self, name: str) -> ElnExperimentTab:
218
- """
219
- Create a new tab in the experiment.
220
-
221
- :param name: The name of the tab to create.
222
- :return: The newly created tab.
223
- """
224
- tab_crit = ElnExperimentTabAddCriteria(name, [])
225
- return self.eln_man.add_tab_for_experiment(self.exp_id, tab_crit)
226
-
227
- def tab_next_entry_order(self, tab: ElnExperimentTab) -> int:
228
- """
229
- :param tab: A tab in this helper's experiment.
230
- :return: The order that the next entry that gets created in the tab should have.
231
- """
232
- max_order: int = 0
233
- for step in self.protocol.get_sorted_step_list():
234
- if step.eln_entry.notebook_experiment_tab_id == tab.tab_id and step.eln_entry.order > max_order:
235
- max_order = step.eln_entry.order
236
- return max_order + 1
237
-
238
- def create_experiment_details_from_data_frame(self,
239
- tab: ElnExperimentTab,
240
- entry_name: str,
241
- df: DataFrame,
242
- sort_field: str | None = None,
243
- sort_direction: SortDirection = SortDirection.DESCENDING,
244
- smiles_column: str | None = None) -> ExperimentEntry | None:
245
- """
246
- Create an experiment detail entry from a DataFrame.
247
-
248
- :param tab: The tab that the entry should be added to.
249
- :param entry_name: The name of the entry.
250
- :param df: The DataFrame to create the entry from.
251
- :param sort_field: The field to sort the resulting entry rows by, if any.
252
- :param sort_direction: The direction to sort the resulting entry rows in, if a sort_field is provided.
253
- :param smiles_column: The column name in the provided DataFrame that corresponds to the SMILES strings of the
254
- compounds tracked in the DataFrame, if any. If this is provided, then the entry will be created with
255
- images of the compounds corresponding to the SMILES strings in each row of the table.
256
- :return: The newly created experiment detail entry.
257
- """
258
- json_list: list[dict[str, Any]] = []
259
- smiles: list[str] = []
260
- for _, row in df.iterrows():
261
- row_dict: dict[str, Any] = row.to_dict()
262
- if smiles_column is not None:
263
- smiles.append(row_dict.get(smiles_column))
264
- json_list.append(row_dict)
265
- images: list[bytes] | None = None
266
- if smiles:
267
- images = self.smiles_to_svg(smiles)
268
- return self.create_experiment_details_from_json(tab, entry_name, json_list, sort_field, sort_direction, images)
269
-
270
- def create_experiment_details_from_json(self,
271
- tab: ElnExperimentTab,
272
- entry_name: str,
273
- json_list: list[dict[str, Any]],
274
- sort_field: str | None = None,
275
- sort_direction: SortDirection = SortDirection.DESCENDING,
276
- images: list[bytes] | None = None) -> ExperimentEntry | None:
277
- """
278
- Create an experiment detail entry from a list of JSON dictionaries.
279
-
280
- :param tab: The tab that the entry should be added to.
281
- :param entry_name: The name of the entry.
282
- :param json_list: The list of JSON dictionaries to create the entry from. Each dictionary is expected to have the
283
- same keys.
284
- :param sort_field: The field to sort the resulting entry rows by, if any.
285
- :param sort_direction: The direction to sort the resulting entry rows in, if a sort_field is provided.
286
- :param images: The images to include in the entry, if any. The images will be added to the rows that they
287
- correspond to based on the order of the images in the images list and the order of the rows in the
288
- json list.
289
- :return: The newly created experiment detail entry.
290
- """
291
- if not json_list:
292
- return None
293
-
294
- # Determine which fields in the JSON can be used to create field definitions.
295
- fb = FieldBuilder()
296
- fields: list[AbstractVeloxFieldDefinition] = []
297
- fields_by_name: dict[str, AbstractVeloxFieldDefinition] = {}
298
- for key, value in json_list[0].items():
299
- field_name: str = key.replace(" ", "_")
300
- if isinstance(value, str):
301
- field = fb.string_field(field_name, display_name=key)
302
- fields.append(field)
303
- fields_by_name[key] = field
304
- elif isinstance(value, (int, float)):
305
- field = fb.double_field(field_name, display_name=key, precision=3)
306
- fields.append(field)
307
- fields_by_name[key] = field
308
-
309
- # Sort the JSON list if requested.
310
- if sort_field and sort_direction != SortDirection.NONE:
311
- if images:
312
- old_order: list[str] = [x[sort_field] for x in json_list]
313
- json_list.sort(key=lambda x: x.get(sort_field), reverse=sort_direction == SortDirection.DESCENDING)
314
- # We'll need to resort the images as well.
315
- if images:
316
- new_order: list[str] = [x[sort_field] for x in json_list]
317
- new_images: list[bytes] = []
318
- for val in new_order:
319
- # noinspection PyUnboundLocalVariable
320
- new_images.append(images[old_order.index(val)])
321
- images = new_images
322
-
323
- # Extract the valid field values from the JSON.
324
- field_maps: list[dict[str, Any]] = []
325
- for json_dict in json_list:
326
- field_map: dict[str, Any] = {}
327
- for key, field in fields_by_name.items():
328
- # Watch out for NaN values or other special values in numeric columns.
329
- val: Any = json_dict.get(key)
330
- if (field.data_field_type == FieldType.DOUBLE
331
- and (not isinstance(val, (int, float))) or (isinstance(val, float) and math.isnan(val))):
332
- val = None
333
- field_map[field.data_field_name] = val
334
- field_maps.append(field_map)
335
-
336
- # Create the experiment detail entry.
337
- detail_entry = ElnEntryCriteria(ElnEntryType.Table, entry_name,
338
- ElnBaseDataType.EXPERIMENT_DETAIL.data_type_name,
339
- self.tab_next_entry_order(tab),
340
- notebook_experiment_tab_id=tab.tab_id,
341
- field_definition_list=fields)
342
- entry = self.eln_man.add_experiment_entry(self.exp_id, detail_entry)
343
- records: list[DataRecord] = self.dr_man.add_data_records_with_data(entry.data_type_name, field_maps)
344
-
345
- # If images are provided, update the data type definition of the experiment detail data type to allow
346
- # record images and add the images to the records.
347
- if images:
348
- dt: DataTypeDefinition = self.dt_man.get_data_type_definition(entry.data_type_name)
349
- dt.is_record_image_assignable = True
350
- self.eln_man.update_eln_data_type_definition(self.exp_id, entry.entry_id, dt)
351
-
352
- layout: DataTypeLayout = self.dt_man.get_default_layout(entry.data_type_name)
353
- layout.table_layout = TableLayout(cell_size=128, record_image_width=128)
354
- self.eln_man.update_eln_data_type_layout(self.exp_id, entry.entry_id, layout)
355
-
356
- self.update_record_images(records, images)
357
-
358
- return entry
359
-
360
- def create_text_entry(self, tab: ElnExperimentTab, timestamp: str, description: str, auto_format: bool = True) \
361
- -> ExperimentEntry:
362
- """
363
- Create a new text entry in the experiment.
364
-
365
- :param tab: The tab to create the text entry in.
366
- :param timestamp: The timestamp to display at the top of the text entry.
367
- :param description: The description to display in the text entry.
368
- :param auto_format: Whether to automatically format the text to be added.
369
- :return: The newly created text entry.
370
- """
371
- if auto_format:
372
- description: str = f"<p>{HtmlFormatter.timestamp(timestamp)}<br>{HtmlFormatter.body(description)}</p>"
373
- else:
374
- description: str = f"<p>{timestamp}<br>{description}</p>"
375
- position = ElnEntryPosition(tab.tab_id, self.tab_next_entry_order(tab))
376
- text_entry: ElnEntryStep = ELNStepFactory.create_text_entry(self.protocol, description, position)
377
- return text_entry.eln_entry
378
-
379
- def set_text_entry(self, text_entry: ExperimentEntry, timestamp: str, description: str,
380
- auto_format: bool = True) -> None:
381
- """
382
- Set the text of a text entry.
383
-
384
- :param text_entry: The text entry to set the text of.
385
- :param timestamp: The timestamp to display at the top of the text entry.
386
- :param description: The description to display in the text entry.
387
- :param auto_format: Whether to automatically format the text to be added.
388
- """
389
- if auto_format:
390
- timestamp = HtmlFormatter.timestamp(timestamp)
391
- description = HtmlFormatter.body(description)
392
- description: str = f"<p>{timestamp}<br>{description}</p>"
393
- step = ElnEntryStep(self.protocol, text_entry)
394
- text_record: DataRecord = step.get_records()[0]
395
- text_record.set_field_value(ElnBaseDataType.get_text_entry_data_field_name(), description)
396
- self.dr_man.commit_data_records([text_record])
397
-
398
- def add_to_text_entry(self, text_entry: ExperimentEntry, description: str, auto_format: bool = True) -> None:
399
- """
400
- Add to the text of a text entry.
401
-
402
- :param text_entry: The text entry to add the text to.
403
- :param description: The text to add to the text entry.
404
- :param auto_format: Whether to automatically format the text to be added.
405
- """
406
- step = ElnEntryStep(self.protocol, text_entry)
407
- text_record: DataRecord = step.get_records()[0]
408
- update: str = text_record.get_field_value(ElnBaseDataType.get_text_entry_data_field_name())
409
- if auto_format:
410
- description = HtmlFormatter.body(description)
411
- update += f"<p style=\"padding-top: 10px;\">{description}</p>"
412
- text_record.set_field_value(ElnBaseDataType.get_text_entry_data_field_name(), update)
413
- self.dr_man.commit_data_records([text_record])
414
-
415
- def create_attachment_entry(self, tab: ElnExperimentTab, entry_name: str, file_name: str, file_data: str | bytes) \
416
- -> ExperimentEntry:
417
- """
418
- Add a new attachment entry to the experiment with the provided attachment data.
419
-
420
- :param tab: The tab where the attachment entry will be added.
421
- :param entry_name: Name of the attachment entry to create in the experiment.
422
- :param file_name: The name of the attachment.
423
- :param file_data: The data of the attachment. This can be a string or bytes.
424
- :return: The newly created attachment entry.
425
- """
426
- tab_id: int = tab.tab_id
427
-
428
- # Encode the file contents in base64.
429
- if isinstance(file_data, str):
430
- file_data: bytes = file_data.encode("utf-8")
431
- base64_encoded: str = base64.b64encode(file_data).decode("utf-8")
432
-
433
- # Crete an attachment entry with the provided data.
434
- attachment_entry = self.eln_man.add_experiment_entry(
435
- self.exp_id,
436
- ElnEntryCriteria(ElnEntryType.Attachment, entry_name, "Attachment", order=2,
437
- notebook_experiment_tab_id=tab_id, attachment_file_name=file_name,
438
- attachment_data_base64=base64_encoded)
439
- )
440
-
441
- # Return the entry object for further use.
442
- return attachment_entry
443
-
444
- def create_attachment_entry_from_file(self, tab: ElnExperimentTab, entry_name: str, file_path: str) \
445
- -> ExperimentEntry:
446
- """
447
- Add a new attachment entry to the experiment with the provided file path to a file in the file system.
448
-
449
- :param tab: The tab where the attachment entry will be added.
450
- :param entry_name: Name of the attachment entry to create in the experiment.
451
- :param file_path: The path to a file in the system to attach to the experiment.
452
- :return: The newly created attachment entry.
453
- """
454
- with open(file_path, 'rb') as f:
455
- file_contents: bytes = f.read()
456
- return self.create_attachment_entry(tab, entry_name, file_path, file_contents)
457
-
458
- def smiles_to_svg(self, smiles: list[str]) -> list[bytes]:
459
- """
460
- Given a list of SMILES strings, return a list of the corresponding images in SVG format.
461
-
462
- :param smiles: The SMILES strings to retrieve images for.
463
- :return: The images in SVG format. The indices of the returned list correspond to the indices of the input
464
- SMILES.
465
- """
466
- if not smiles:
467
- return []
468
- reg_man = MultiModalManager(self.user)
469
- image_list: list[str] = reg_man.load_image_data(ImageDataRequestPojo(smiles, False))
470
- return [x.encode() for x in image_list]
471
-
472
- def update_record_images(self, records: list[SapioRecord], images: list[bytes]) -> None:
473
- """
474
- Update the images of the given records with the given images.
475
-
476
- :param records: The records to update the images of.
477
- :param images: The images to update the records with. Records will be match with the image in the matching
478
- index of this list.
479
- """
480
- for record, image in zip(AliasUtil.to_data_records(records), images):
481
- with io.BytesIO(image) as bytes_io:
482
- self.dr_man.set_record_image(record, bytes_io)
483
-
484
-
485
- class ToolOfToolsHelper:
486
- """
487
- A class with helper methods utilized by the Tool of Tools for the creation and updating of experiment tabs that
488
- track a tool's progress and results.
489
- """
490
- # Contextual info.
491
- user: SapioUser
492
- tab_prefix: str
493
- exp_id: int
494
- helper: AiHelper
495
-
496
- # Tool info.
497
- name: str
498
- description: str
499
- results_data_type: str | None
500
-
501
- # Managers.
502
- dr_man: DataRecordManager
503
- eln_man: ElnManager
504
-
505
- # Stuff created by this helper.
506
- _initialized: bool
507
- """Whether a tab for this tool has been initialized."""
508
- tab: ElnExperimentTab
509
- """The tab that contains the tool's entries."""
510
- description_entry: ElnEntryStep | None
511
- """The text entry that displays the description of the tool."""
512
- description_record: DataRecord | None
513
- """The record that stores the description of the tool."""
514
- progress_entry: ElnEntryStep | None
515
- """A hidden entry for tracking the progress of the tool."""
516
- progress_record: DataRecord | None
517
- """The record that stores the progress of the tool."""
518
- progress_gauge_entry: ElnEntryStep | None
519
- """A chart entry that displays the progress of the tool using the hidden progress entry."""
520
- results_entry: ElnEntryStep | None
521
- """An entry for displaying the results of the tool. If None, the tool does not produce result records."""
522
-
523
- def __init__(self, headers: Mapping[str, str], name: str, description: str,
524
- results_data_type: str | None = None):
525
- """
526
- :param headers: The headers that were passed to the endpoint.
527
- :param name: The name of the tool.
528
- :param description: A description of the tool.
529
- :param results_data_type: The data type name for the results of the tool. If None, the tool does not produce
530
- result records.
531
- """
532
- headers: dict[str, str] = format_tot_headers(headers)
533
- self.user = create_user_from_tot_headers(headers)
534
- self.exp_id = int(headers[EXP_ID_HEADER.lower()])
535
- self.tab_prefix = headers[TAB_PREFIX_HEADER.lower()]
536
- self.helper = AiHelper(self.user, self.exp_id)
537
-
538
- self.name = name
539
- self.description = description
540
- self.results_data_type = results_data_type
541
-
542
- self.dr_man = DataRecordManager(self.user)
543
- self.eln_man = ElnManager(self.user)
544
-
545
- self._initialized = False
546
-
547
- def initialize_tab(self) -> ElnExperimentTab:
548
- if self._initialized:
549
- return self.tab
550
- self._initialized = True
551
-
552
- # Determine if a previous call to this endpoint already created a tab for these results. If so, grab the entries
553
- # from that tab.
554
- tab_name: str = f"{self.tab_prefix.strip()} {self.name.strip()}"
555
- tabs: list[ElnExperimentTab] = self.eln_man.get_tabs_for_experiment(self.exp_id)
556
- for tab in tabs:
557
- if tab.tab_name != tab_name:
558
- continue
559
-
560
- for entry in self.helper.protocol.get_sorted_step_list():
561
- if entry.eln_entry.notebook_experiment_tab_id != tab.tab_id:
562
- continue
563
-
564
- dt: str = entry.get_data_type_names()[0] if entry.get_data_type_names() else None
565
- if (entry.eln_entry.entry_type == ElnEntryType.Form
566
- and ElnBaseDataType.get_base_type(dt) == ElnBaseDataType.EXPERIMENT_DETAIL
567
- and not hasattr(self, "progress_entry")):
568
- self.progress_entry = entry
569
- self.progress_record = entry.get_records()[0]
570
- elif (entry.eln_entry.entry_type == ElnEntryType.Dashboard
571
- and not hasattr(self, "progress_gauge_entry")):
572
- self.progress_gauge_entry = entry
573
- elif (entry.eln_entry.entry_type == ElnEntryType.Text
574
- and not hasattr(self, "description_entry")):
575
- self.description_entry = entry
576
- self.description_record = entry.get_records()[0]
577
- elif (entry.eln_entry.entry_type == ElnEntryType.Table
578
- and dt == self.results_data_type
579
- and not hasattr(self, "results_entry")):
580
- self.results_entry = entry
581
-
582
- if not hasattr(self, "progress_entry"):
583
- self.progress_entry = None
584
- self.progress_record = None
585
- if not hasattr(self, "progress_gauge_entry"):
586
- self.progress_gauge_entry = None
587
- if not hasattr(self, "description_entry"):
588
- self.description_entry = None
589
- self.description_record = None
590
- if not hasattr(self, "results_entry"):
591
- self.results_entry = None
592
-
593
- self.tab = tab
594
- return tab
595
-
596
- # Otherwise, create the tab for the tool progress and results.
597
- self.tab = self.helper.create_tab(tab_name)
598
-
599
- # Create a hidden entry for tracking the progress of the tool.
600
- field_sets: list[ElnFieldSetInfo] = self.eln_man.get_field_set_info_list()
601
- progress_field_set: list[ElnFieldSetInfo] = [x for x in field_sets if
602
- x.field_set_name == "Tool of Tools Progress"]
603
- if not progress_field_set:
604
- raise SapioException("Unable to locate the field set for the Tool of Tools progress.")
605
- progress_entry_crit = ElnEntryCriteria(ElnEntryType.Form, f"{tab_name} Progress",
606
- ElnBaseDataType.EXPERIMENT_DETAIL.data_type_name, 1,
607
- notebook_experiment_tab_id=self.tab.tab_id,
608
- enb_field_set_id=progress_field_set[0].field_set_id)
609
- progress_entry = ElnEntryStep(self.helper.protocol,
610
- self.eln_man.add_experiment_entry(self.exp_id, progress_entry_crit))
611
- self.progress_entry = progress_entry
612
- self.progress_record = progress_entry.get_records()[0]
613
-
614
- # Hide the progress entry.
615
- form_update_crit = ElnFormEntryUpdateCriteria()
616
- form_update_crit.is_hidden = True
617
- self.eln_man.update_experiment_entry(self.exp_id, self.progress_entry.get_id(), form_update_crit)
618
-
619
- # Create the text entry that displays the description of the tool. Include the timestamp of when the
620
- # tool started and format the description so that the text isn't too small to read.
621
- # TODO: Get the UTC offset in seconds from the header once that's being sent.
622
- now: str = TimeUtil.now_in_format("%Y-%m-%d %H:%M:%S UTC", "UTC")
623
- text_entry = ElnEntryStep(self.helper.protocol, self.helper.create_text_entry(self.tab, now, self.description))
624
- self.description_entry = text_entry
625
- self.description_record = text_entry.get_records()[0]
626
-
627
- # Shrink the text entry by one column.
628
- text_update_crit = ElnTextEntryUpdateCriteria()
629
- text_update_crit.column_order = 0
630
- text_update_crit.column_span = 2
631
- self.eln_man.update_experiment_entry(self.exp_id, self.description_entry.get_id(), text_update_crit)
632
-
633
- # Create a gauge entry to display the progress.
634
- gauge_entry: ElnEntryStep = self._create_gauge_chart(self.helper.protocol, progress_entry,
635
- f"{self.name} Progress", "Progress", "StatusMsg")
636
- self.progress_gauge_entry = gauge_entry
637
-
638
- # Make sure the gauge entry isn't too big and stick it to the right of the text entry.
639
- dash_update_crit = ElnDashboardEntryUpdateCriteria()
640
- dash_update_crit.entry_height = 250
641
- dash_update_crit.column_order = 2
642
- dash_update_crit.column_span = 2
643
- self.eln_man.update_experiment_entry(self.exp_id, self.progress_gauge_entry.get_id(), dash_update_crit)
644
-
645
- # TODO: Bulk updates aren't working?
646
- # self.eln_man.update_experiment_entries(self.exp_id, {
647
- # self.progress_entry.get_id(): form_update_crit,
648
- # self.progress_gauge_entry.get_id(): dash_update_crit,
649
- # self.description_entry.get_id(): text_update_crit
650
- # })
651
-
652
- # Create a results entry if this tool produces result records.
653
- if self.results_data_type:
654
- results_entry = ELNStepFactory.create_table_step(self.helper.protocol, f"{self.name} Results",
655
- self.results_data_type)
656
- self.results_entry = results_entry
657
- else:
658
- self.results_entry = None
659
-
660
- return self.tab
661
-
662
- def add_to_description(self, description: str, auto_format: bool = True) -> None:
663
- """
664
- Add to the description entry of the tool.
665
-
666
- :param description: The text to add to the description.
667
- :param auto_format: Whether to automatically format the text to be added.
668
- """
669
- if not self._initialized:
670
- raise SapioException("The tab for this tool has not been initialized.")
671
- field: str = ElnBaseDataType.get_text_entry_data_field_name()
672
- update: str = self.description_record.get_field_value(field)
673
- if auto_format:
674
- description = HtmlFormatter.body(description)
675
- update += f"<p style=\"padding-top: 10px;\">{description}</p>"
676
- self.description_record.set_field_value(field, update)
677
- self.dr_man.commit_data_records([self.description_record])
678
-
679
- def update_progress(self, progress: float, status_msg: str | None = None) -> None:
680
- """
681
- Updates the progress of the tool.
682
-
683
- :param progress: A value between 0 and 100 representing the progress of the tool.
684
- :param status_msg: A status message to display to the user alongside the progress gauge.
685
- """
686
- if not self._initialized:
687
- raise SapioException("The tab for this tool has not been initialized.")
688
- self.progress_record.set_field_value("Progress", progress)
689
- self.progress_record.set_field_value("StatusMsg", status_msg)
690
- self.dr_man.commit_data_records([self.progress_record])
691
-
692
- def add_results(self, results: list[SapioRecord]) -> None:
693
- """
694
- Add the results of the tool to the results entry.
695
-
696
- :param results: The result records to add to the results entry.
697
- """
698
- if not self._initialized:
699
- raise SapioException("The tab for this tool has not been initialized.")
700
- self.results_entry.add_records(AliasUtil.to_data_records(results))
701
-
702
- def add_results_bar_chart(self, x_axis: str, y_axis: str) -> ExperimentEntry:
703
- """
704
- Create a bar chart entry for the results of the tool.
705
-
706
- :param x_axis: The data field to use for the x-axis of the chart.
707
- :param y_axis: The data field to use for the y-axis of the chart.
708
- :return: The newly created chart entry.
709
- """
710
- if not self._initialized:
711
- raise SapioException("The tab for this tool has not been initialized.")
712
- if not self.results_entry:
713
- raise SapioException("This tool does not produce result records.")
714
- return ELNStepFactory.create_bar_chart_step(self.helper.protocol, self.results_entry,
715
- f"{self.name} Results Chart", x_axis, y_axis)[0].eln_entry
716
-
717
- def add_attachment_entry(self, entry_name: str, file_name: str, file_data: str | bytes) -> ExperimentEntry:
718
- """
719
- Add a new attachment entry to the experiment with the provided attachment data.
720
-
721
- :param entry_name: Name of the attachment entry to create in the experiment.
722
- :param file_name: The name of the attachment.
723
- :param file_data: The data of the attachment. This can be a string or bytes.
724
- :return: The newly created attachment entry.
725
- """
726
- if not self._initialized:
727
- raise SapioException("The tab for this tool has not been initialized.")
728
-
729
- return self.helper.create_attachment_entry(self.tab, entry_name, file_name, file_data)
730
-
731
- def add_attachment_entry_from_file(self, entry_name: str, file_path: str) -> ExperimentEntry:
732
- """
733
- Add a new attachment entry to the experiment with the provided file path to a file in the file system.
734
-
735
- :param entry_name: Name of the attachment entry to create in the experiment.
736
- :param file_path: The path to a file in the system to attach to the experiment.
737
- :return: The newly created attachment entry.
738
- """
739
- if not self._initialized:
740
- raise SapioException("The tab for this tool has not been initialized.")
741
-
742
- return self.helper.create_attachment_entry_from_file(self.tab, entry_name, file_path)
743
-
744
- # TODO: Remove this once pylib's gauge chart definition is up to date.
745
- @staticmethod
746
- def _create_gauge_chart(protocol: ElnExperimentProtocol, data_source_step: ElnEntryStep, step_name: str,
747
- field_name: str, status_field: str, group_by_field_name: str = "DataRecordName") \
748
- -> ElnEntryStep:
749
- """
750
- Create a gauge chart step in the experiment protocol.
751
- """
752
- if not data_source_step.get_data_type_names():
753
- raise ValueError("The data source step did not declare a data type name.")
754
- data_type_name: str = data_source_step.get_data_type_names()[0]
755
- series = GaugeChartSeries(data_type_name, field_name)
756
- series.operation_type = ChartOperationType.VALUE
757
- chart = _GaugeChartDefinition()
758
- chart.main_data_type_name = data_type_name
759
- chart.status_field = status_field
760
- chart.minimum_value = 0.
761
- chart.maximum_value = 100.
762
- chart.series_list = [series]
763
- chart.grouping_type = ChartGroupingType.GROUP_BY_FIELD
764
- chart.grouping_type_data_type_name = data_type_name
765
- chart.grouping_type_data_field_name = group_by_field_name
766
- dashboard, step = ELNStepFactory._create_dashboard_step_from_chart(chart, data_source_step, protocol, step_name,
767
- None)
768
- protocol.invalidate()
769
- return step
770
-
771
-
772
- # TODO: Using this to set the new status field setting.
773
- class _GaugeChartDefinition(GaugeChartDefinition):
774
- status_field: str
775
-
776
- def to_json(self) -> dict[str, Any]:
777
- result = super().to_json()
778
- result["statusValueField"] = {
779
- "dataTypeName": self.main_data_type_name,
780
- "dataFieldName": self.status_field
781
- }
782
- return result