Skip to content

Commit 57af93c

Browse files
authored
set project parameters block
1 parent 6ba00df commit 57af93c

File tree

5 files changed

+74
-63
lines changed

5 files changed

+74
-63
lines changed

Preparation/Set Project Parameter/README.md

Lines changed: 0 additions & 1 deletion
This file was deleted.

Preparation/Set Project Parameter/script.py

Lines changed: 0 additions & 48 deletions
This file was deleted.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
### Set Project Parameters\nThis block sets project parameters by reading input data. It uses two options—one for the column containing the parameter names and another for the column with the parameter values—to build a list of updates. Finally, it sends a single update request to change the project parameters based on the input data.

Preparation/Set Project Parameter/manifest.json renamed to Preparation/Set Project Parameters/manifest.json

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"@visokiotype": "CustomBlockSchema.CustomBlockManifest",
3-
"name": "Set Project Parameter",
3+
"name": "Set Project Parameters",
44
"scriptFilename": "script.py",
55
"language": "PYTHON",
66
"executableVersion": null,
@@ -19,7 +19,7 @@
1919
"parameter",
2020
"param"
2121
],
22-
"introductoryText": "## Set Project Parameter\nThis block sets a project parameter.",
22+
"introductoryText": "## Set Project Parameters\nThis block sets project parameters by reading input data. It uses two options—one for the column containing the parameter names and another for the column with the parameter values—to build a list of updates. Finally, it sends a single update request to change the project parameters based on the input data.",
2323
"dependencies": "",
2424
"options": [
2525
{
@@ -33,24 +33,28 @@
3333
"defaultValue": "http://127.0.0.1:24679/Admin+dashboards/Errors+Monitor.iox/"
3434
},
3535
{
36-
"name": "Param_Name",
37-
"title": "Name",
36+
"name": "Params_Name",
37+
"title": "Names",
3838
"description": "The name of the parameter to change",
39-
"groupTitle": "Parameter",
40-
"width": "TWO",
41-
"@visokiotype": "CustomBlockSchema.TextCustomBlockPublicOption",
42-
"mandatory": true,
43-
"defaultValue": ""
39+
"groupTitle": "Parameters",
40+
"width": "ONE",
41+
"@visokiotype": "CustomBlockSchema.FieldCustomBlockPublicOption",
42+
"mandatory": false,
43+
"inputIndex": 0,
44+
"defaultValue": null,
45+
"fieldTypes": []
4446
},
4547
{
46-
"name": "Param_Value",
47-
"title": "Value",
48+
"name": "Params_Value",
49+
"title": "Values",
4850
"description": "The value to set in the parameter",
49-
"groupTitle": "Parameter",
51+
"groupTitle": "Parameters",
5052
"width": "ONE",
51-
"@visokiotype": "CustomBlockSchema.TextCustomBlockPublicOption",
53+
"@visokiotype": "CustomBlockSchema.FieldCustomBlockPublicOption",
5254
"mandatory": false,
53-
"defaultValue": ""
55+
"inputIndex": 0,
56+
"defaultValue": null,
57+
"fieldTypes": []
5458
}
5559
],
5660
"blockOutputs": [],
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
from omniscope.api import OmniscopeApi
2+
import urllib3
3+
import json
4+
5+
def send_update(omniscope_api, message):
6+
try:
7+
omniscope_api.update_message(message)
8+
except Exception:
9+
pass # For compatibility with older API versions
10+
11+
# Initialize the Omniscope API
12+
omniscope_api = OmniscopeApi()
13+
14+
# Read input records from the first input block.
15+
input_data = omniscope_api.read_input_records(input_number=0)
16+
17+
# Read the column names from the block options that contain the parameter names and values.
18+
params_name_option = omniscope_api.get_option("Params_Name")
19+
params_value_option = omniscope_api.get_option("Params_Value")
20+
21+
# Build the list of parameter updates from the input data.
22+
updates_list = []
23+
for index, row in input_data.iterrows():
24+
param_name = row[params_name_option]
25+
param_value = row[params_value_option]
26+
updates_list.append({
27+
"name": param_name,
28+
"value": param_value
29+
})
30+
31+
# Build the JSON payload for the update request.
32+
payload = json.dumps({
33+
"updates": updates_list,
34+
"waitForIdle": False
35+
})
36+
37+
# Retrieve the Iox_File_Url from the block options.
38+
iox_url = omniscope_api.get_option("Iox_File_Url")
39+
if not iox_url.endswith("/"):
40+
iox_url += "/"
41+
42+
# Construct the URL for updating project parameters.
43+
update_params_url = iox_url + "w/updateparams"
44+
45+
# Create an HTTP pool manager.
46+
http = urllib3.PoolManager()
47+
48+
# Log that the project parameter update is being enqueued.
49+
send_update(omniscope_api, "Updating project parameters from input data...")
50+
51+
# Send a single POST request with all parameter updates.
52+
http.request('POST', update_params_url, headers={'Content-Type': 'application/json'}, body=payload)
53+
54+
# Close the Omniscope API with a completion message.
55+
omniscope_api.close("Project parameters update enqueued.")

0 commit comments

Comments
 (0)