ivoryos 1.0.9__py3-none-any.whl → 1.2.0__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 ivoryos might be problematic. Click here for more details.
- ivoryos/__init__.py +26 -7
- ivoryos/routes/api/api.py +56 -0
- ivoryos/routes/auth/auth.py +5 -5
- ivoryos/routes/control/control.py +77 -372
- ivoryos/routes/control/control_file.py +36 -0
- ivoryos/routes/control/control_new_device.py +142 -0
- ivoryos/routes/control/templates/controllers.html +166 -0
- ivoryos/routes/control/templates/controllers_new.html +112 -0
- ivoryos/routes/control/utils.py +38 -0
- ivoryos/routes/data/data.py +129 -0
- ivoryos/routes/data/templates/components/step_card.html +13 -0
- ivoryos/routes/{database/templates/database → data/templates}/workflow_database.html +14 -8
- ivoryos/routes/{database/templates/database → data/templates}/workflow_view.html +3 -3
- ivoryos/routes/design/__init__.py +4 -0
- ivoryos/routes/design/design.py +298 -656
- ivoryos/routes/design/design_file.py +68 -0
- ivoryos/routes/design/design_step.py +145 -0
- ivoryos/routes/design/templates/components/action_form.html +53 -0
- ivoryos/routes/design/templates/components/actions_panel.html +25 -0
- ivoryos/routes/design/templates/components/autofill_toggle.html +10 -0
- ivoryos/routes/design/templates/components/canvas.html +5 -0
- ivoryos/routes/design/templates/components/canvas_footer.html +9 -0
- ivoryos/routes/design/templates/components/canvas_header.html +75 -0
- ivoryos/routes/design/templates/components/canvas_main.html +34 -0
- ivoryos/routes/design/templates/components/deck_selector.html +10 -0
- ivoryos/routes/design/templates/components/edit_action_form.html +38 -0
- ivoryos/routes/design/templates/components/instruments_panel.html +66 -0
- ivoryos/routes/design/templates/components/modals/drop_modal.html +17 -0
- ivoryos/routes/design/templates/components/modals/json_modal.html +22 -0
- ivoryos/routes/design/templates/components/modals/new_script_modal.html +17 -0
- ivoryos/routes/design/templates/components/modals/rename_modal.html +23 -0
- ivoryos/routes/design/templates/components/modals/saveas_modal.html +27 -0
- ivoryos/routes/design/templates/components/modals.html +6 -0
- ivoryos/routes/design/templates/components/python_code_overlay.html +39 -0
- ivoryos/routes/design/templates/components/sidebar.html +15 -0
- ivoryos/routes/design/templates/components/text_to_code_panel.html +20 -0
- ivoryos/routes/design/templates/experiment_builder.html +41 -0
- ivoryos/routes/execute/__init__.py +0 -0
- ivoryos/routes/execute/execute.py +317 -0
- ivoryos/routes/execute/execute_file.py +78 -0
- ivoryos/routes/execute/templates/components/error_modal.html +20 -0
- ivoryos/routes/execute/templates/components/logging_panel.html +31 -0
- ivoryos/routes/execute/templates/components/progress_panel.html +27 -0
- ivoryos/routes/execute/templates/components/run_panel.html +9 -0
- ivoryos/routes/execute/templates/components/run_tabs.html +17 -0
- ivoryos/routes/execute/templates/components/tab_bayesian.html +398 -0
- ivoryos/routes/execute/templates/components/tab_configuration.html +98 -0
- ivoryos/routes/execute/templates/components/tab_repeat.html +14 -0
- ivoryos/routes/execute/templates/experiment_run.html +294 -0
- ivoryos/routes/library/__init__.py +0 -0
- ivoryos/routes/library/library.py +159 -0
- ivoryos/routes/{database/templates/database/scripts_database.html → library/templates/library.html} +30 -22
- ivoryos/routes/main/main.py +1 -1
- ivoryos/routes/main/templates/{main/home.html → home.html} +4 -4
- ivoryos/socket_handlers.py +52 -0
- ivoryos/static/js/action_handlers.js +213 -0
- ivoryos/static/js/db_delete.js +23 -0
- ivoryos/static/js/script_metadata.js +39 -0
- ivoryos/static/js/sortable_design.js +89 -56
- ivoryos/static/js/ui_state.js +113 -0
- ivoryos/templates/base.html +4 -4
- ivoryos/utils/bo_campaign.py +179 -3
- ivoryos/utils/db_models.py +14 -5
- ivoryos/utils/form.py +5 -9
- ivoryos/utils/global_config.py +13 -1
- ivoryos/utils/py_to_json.py +225 -0
- ivoryos/utils/script_runner.py +49 -7
- ivoryos/utils/serilize.py +203 -0
- ivoryos/utils/task_runner.py +4 -1
- ivoryos/version.py +1 -1
- {ivoryos-1.0.9.dist-info → ivoryos-1.2.0.dist-info}/METADATA +5 -8
- ivoryos-1.2.0.dist-info/RECORD +105 -0
- ivoryos/routes/control/templates/control/controllers.html +0 -78
- ivoryos/routes/control/templates/control/controllers_home.html +0 -55
- ivoryos/routes/control/templates/control/controllers_new.html +0 -89
- ivoryos/routes/database/database.py +0 -306
- ivoryos/routes/database/templates/database/step_card.html +0 -7
- ivoryos/routes/design/templates/design/experiment_builder.html +0 -521
- ivoryos/routes/design/templates/design/experiment_run.html +0 -558
- ivoryos-1.0.9.dist-info/RECORD +0 -61
- /ivoryos/routes/auth/templates/{auth/login.html → login.html} +0 -0
- /ivoryos/routes/auth/templates/{auth/signup.html → signup.html} +0 -0
- /ivoryos/routes/{database → data}/__init__.py +0 -0
- /ivoryos/routes/main/templates/{main/help.html → help.html} +0 -0
- {ivoryos-1.0.9.dist-info → ivoryos-1.2.0.dist-info}/LICENSE +0 -0
- {ivoryos-1.0.9.dist-info → ivoryos-1.2.0.dist-info}/WHEEL +0 -0
- {ivoryos-1.0.9.dist-info → ivoryos-1.2.0.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import os
|
|
2
|
+
from flask import Blueprint, request, current_app, send_file, flash, redirect, url_for, session, render_template
|
|
3
|
+
from flask_login import login_required
|
|
4
|
+
|
|
5
|
+
from ivoryos.utils import utils
|
|
6
|
+
from ivoryos.routes.control.utils import find_instrument_by_name
|
|
7
|
+
from ivoryos.utils.global_config import GlobalConfig
|
|
8
|
+
|
|
9
|
+
global_config = GlobalConfig()
|
|
10
|
+
|
|
11
|
+
control_temp = Blueprint('temp', __name__)
|
|
12
|
+
|
|
13
|
+
@control_temp.route("/new/module", methods=['POST'])
|
|
14
|
+
def import_api():
|
|
15
|
+
"""
|
|
16
|
+
.. :quickref: Advanced Features; Manually import API module(s)
|
|
17
|
+
|
|
18
|
+
importing other Python modules
|
|
19
|
+
|
|
20
|
+
.. http:post:: /instruments/new/module
|
|
21
|
+
|
|
22
|
+
:form filepath: API (Python class) module filepath
|
|
23
|
+
|
|
24
|
+
import the module and redirect to :http:get:`/ivoryos/instruments/new/`
|
|
25
|
+
|
|
26
|
+
"""
|
|
27
|
+
filepath = request.form.get('filepath')
|
|
28
|
+
# filepath.replace('\\', '/')
|
|
29
|
+
name = os.path.split(filepath)[-1].split('.')[0]
|
|
30
|
+
try:
|
|
31
|
+
spec = utils.importlib.util.spec_from_file_location(name, filepath)
|
|
32
|
+
module = utils.importlib.util.module_from_spec(spec)
|
|
33
|
+
spec.loader.exec_module(module)
|
|
34
|
+
classes = utils.inspect.getmembers(module, utils.inspect.isclass)
|
|
35
|
+
if len(classes) == 0:
|
|
36
|
+
flash("Invalid import: no class found in the path")
|
|
37
|
+
return redirect(url_for("control.controllers_home"))
|
|
38
|
+
for i in classes:
|
|
39
|
+
globals()[i[0]] = i[1]
|
|
40
|
+
global_config.api_variables.add(i[0])
|
|
41
|
+
# should handle path error and file type error
|
|
42
|
+
except Exception as e:
|
|
43
|
+
flash(e.__str__())
|
|
44
|
+
return redirect(url_for("control.temp.new_controller"))
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
@control_temp.route("/new/deck-python", methods=['POST'])
|
|
49
|
+
def import_deck():
|
|
50
|
+
"""
|
|
51
|
+
.. :quickref: Advanced Features; Manually import a deck
|
|
52
|
+
|
|
53
|
+
.. http:post:: /instruments/new/deck-python
|
|
54
|
+
|
|
55
|
+
:form filepath: deck module filepath
|
|
56
|
+
|
|
57
|
+
import the module and redirect to the previous page
|
|
58
|
+
|
|
59
|
+
"""
|
|
60
|
+
script = utils.get_script_file()
|
|
61
|
+
filepath = request.form.get('filepath')
|
|
62
|
+
session['dismiss'] = request.form.get('dismiss')
|
|
63
|
+
update = request.form.get('update')
|
|
64
|
+
back = request.referrer
|
|
65
|
+
if session['dismiss']:
|
|
66
|
+
return redirect(back)
|
|
67
|
+
name = os.path.split(filepath)[-1].split('.')[0]
|
|
68
|
+
try:
|
|
69
|
+
module = utils.import_module_by_filepath(filepath=filepath, name=name)
|
|
70
|
+
utils.save_to_history(filepath, current_app.config["DECK_HISTORY"])
|
|
71
|
+
module_sigs = utils.create_deck_snapshot(module, save=update, output_path=current_app.config["DUMMY_DECK"])
|
|
72
|
+
if not len(module_sigs) > 0:
|
|
73
|
+
flash("Invalid hardware deck, connect instruments in deck script", "error")
|
|
74
|
+
return redirect(url_for("control.deck_controllers"))
|
|
75
|
+
global_config.deck = module
|
|
76
|
+
global_config.deck_snapshot = module_sigs
|
|
77
|
+
|
|
78
|
+
if script.deck is None:
|
|
79
|
+
script.deck = module.__name__
|
|
80
|
+
# file path error exception
|
|
81
|
+
except Exception as e:
|
|
82
|
+
flash(e.__str__())
|
|
83
|
+
return redirect(back)
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
@control_temp.route("/new/", strict_slashes=False)
|
|
87
|
+
@control_temp.route("/new/<string:instrument>", methods=['GET', 'POST'])
|
|
88
|
+
@login_required
|
|
89
|
+
def new_controller(instrument:str=None):
|
|
90
|
+
"""
|
|
91
|
+
.. :quickref: Advanced Features; connect to a new device
|
|
92
|
+
|
|
93
|
+
interface for connecting a new <instrument>
|
|
94
|
+
|
|
95
|
+
.. http:get:: /instruments/new/
|
|
96
|
+
|
|
97
|
+
:param instrument: instrument name
|
|
98
|
+
:type instrument: str
|
|
99
|
+
|
|
100
|
+
.. http:post:: /instruments/new/
|
|
101
|
+
|
|
102
|
+
:form device_name: module instance name (e.g. my_instance = MyClass())
|
|
103
|
+
:form kwargs: dynamic module initialization kwargs fields
|
|
104
|
+
|
|
105
|
+
"""
|
|
106
|
+
device = None
|
|
107
|
+
args = None
|
|
108
|
+
if instrument:
|
|
109
|
+
|
|
110
|
+
device = globals()[instrument]
|
|
111
|
+
args = utils.inspect.signature(device.__init__)
|
|
112
|
+
|
|
113
|
+
if request.method == 'POST':
|
|
114
|
+
device_name = request.form.get("device_name", "")
|
|
115
|
+
if device_name and device_name in globals():
|
|
116
|
+
flash("Device name is defined. Try another name, or leave it as blank to auto-configure")
|
|
117
|
+
# return render_template('controllers_new.html', instrument=instrument,
|
|
118
|
+
# api_variables=global_config.api_variables,
|
|
119
|
+
# device=device, args=args, defined_variables=global_config.defined_variables)
|
|
120
|
+
if device_name == "":
|
|
121
|
+
device_name = device.__name__.lower() + "_"
|
|
122
|
+
num = 1
|
|
123
|
+
while device_name + str(num) in global_config.defined_variables:
|
|
124
|
+
num += 1
|
|
125
|
+
device_name = device_name + str(num)
|
|
126
|
+
kwargs = request.form.to_dict()
|
|
127
|
+
kwargs.pop("device_name")
|
|
128
|
+
for i in kwargs:
|
|
129
|
+
if kwargs[i] in global_config.defined_variables:
|
|
130
|
+
kwargs[i] = global_config.defined_variables[kwargs[i]]
|
|
131
|
+
try:
|
|
132
|
+
utils.convert_config_type(kwargs, device.__init__.__annotations__, is_class=True)
|
|
133
|
+
except Exception as e:
|
|
134
|
+
flash(e)
|
|
135
|
+
try:
|
|
136
|
+
global_config.defined_variables[device_name] = device(**kwargs)
|
|
137
|
+
# global_config.defined_variables.add(device_name)
|
|
138
|
+
return redirect(url_for('control.deck_controllers'))
|
|
139
|
+
except Exception as e:
|
|
140
|
+
flash(e)
|
|
141
|
+
return render_template('controllers_new.html', instrument=instrument, api_variables=global_config.api_variables,
|
|
142
|
+
device=device, args=args, defined_variables=global_config.defined_variables)
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
{% extends 'base.html' %}
|
|
2
|
+
{% block title %}IvoryOS | Controllers {% endblock %}
|
|
3
|
+
|
|
4
|
+
{% block body %}
|
|
5
|
+
<div id="overlay" class="overlay">
|
|
6
|
+
<div>
|
|
7
|
+
<h3 id="overlay-text"></h3>
|
|
8
|
+
<div class="spinner-border" role="status"></div>
|
|
9
|
+
</div>
|
|
10
|
+
</div>
|
|
11
|
+
<div class="container-fluid">
|
|
12
|
+
<div class="row">
|
|
13
|
+
<!-- Sidebar: Instruments -->
|
|
14
|
+
<nav class="col-md-3 col-lg-2 d-md-block bg-light sidebar py-3" style="height: 100vh; overflow-y: auto; position: sticky; top: 0;">
|
|
15
|
+
<div class="sidebar-sticky">
|
|
16
|
+
<!-- Deck Instruments -->
|
|
17
|
+
<div class="mb-4">
|
|
18
|
+
<div class="list-group">
|
|
19
|
+
{% for inst in defined_variables %}
|
|
20
|
+
<a class="list-group-item list-group-item-action d-flex align-items-center {% if instrument == inst %}active bg-primary text-white border-0{% else %}bg-light{% endif %}"
|
|
21
|
+
href="{{ url_for('control.deck_controllers') }}?instrument={{ inst }}"
|
|
22
|
+
style="border-radius: 0.5rem; margin-bottom: 0.5rem; transition: background 0.2s;">
|
|
23
|
+
<span class="flex-grow-1">{{ inst | format_name }}</span>
|
|
24
|
+
{% if instrument == inst %}
|
|
25
|
+
<span class="ms-auto">></span>
|
|
26
|
+
{% endif %}
|
|
27
|
+
</a>
|
|
28
|
+
{% endfor %}
|
|
29
|
+
</div>
|
|
30
|
+
</div>
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
<!-- Temp Instruments -->
|
|
35
|
+
{% if temp_variables %}
|
|
36
|
+
<div class="mb-4">
|
|
37
|
+
<h6 class="fw-bold text-secondary mb-2" style="letter-spacing: 1px;">Temp Instruments</h6>
|
|
38
|
+
<div class="list-group">
|
|
39
|
+
{% for inst in temp_variables %}
|
|
40
|
+
<a class="list-group-item list-group-item-action d-flex align-items-center {% if instrument == inst %}active bg-warning text-dark border-0{% else %}bg-light{% endif %}"
|
|
41
|
+
href="{{ url_for('control.deck_controllers') }}?instrument={{ inst }}"
|
|
42
|
+
style="border-radius: 0.5rem; margin-bottom: 0.5rem; transition: background 0.2s;">
|
|
43
|
+
<span class="flex-grow-1">{{ inst | format_name }}</span>
|
|
44
|
+
{% if instrument == inst %}
|
|
45
|
+
<span class="ms-auto">></span>
|
|
46
|
+
{% endif %}
|
|
47
|
+
</a>
|
|
48
|
+
{% endfor %}
|
|
49
|
+
</div>
|
|
50
|
+
</div>
|
|
51
|
+
{% endif %}
|
|
52
|
+
<!-- Action Buttons -->
|
|
53
|
+
<div class="mb-4">
|
|
54
|
+
<a href="{{ url_for('control.file.download_proxy', filetype='proxy') }}" class="btn btn-outline-primary w-100 mb-2">
|
|
55
|
+
Download proxy
|
|
56
|
+
</a>
|
|
57
|
+
<a href="{{ url_for('control.temp.new_controller') }}" class="btn btn-outline-success w-100">
|
|
58
|
+
New connection
|
|
59
|
+
</a>
|
|
60
|
+
</div>
|
|
61
|
+
</div>
|
|
62
|
+
</nav>
|
|
63
|
+
|
|
64
|
+
<!-- Main: Method Cards -->
|
|
65
|
+
<main class="col-md-9 ms-sm-auto col-lg-10 px-md-4" style="height: 100vh; overflow-y: auto;">
|
|
66
|
+
{% if instrument%}
|
|
67
|
+
{# <h2 class="text-secondary">{{ instrument }} controller</h2>#}
|
|
68
|
+
<div class="grid-container" id="sortable-grid" style="display: grid; grid-template-columns: repeat(auto-fit, minmax(350px, 1fr)); gap: 1rem; width: 100%;">
|
|
69
|
+
{% set hidden = session.get('hidden_functions', {}) %}
|
|
70
|
+
{% set hidden_instrument = hidden.get(instrument, []) %}
|
|
71
|
+
{% for function, form in forms.items() %}
|
|
72
|
+
{% if function not in hidden_instrument %}
|
|
73
|
+
<div class="card" id="{{function}}" style="margin: 0;">
|
|
74
|
+
<div class="bg-white rounded shadow-sm h-100">
|
|
75
|
+
<i class="bi bi-info-circle ms-2" data-bs-toggle="tooltip" data-bs-placement="top" title='{{ form.hidden_name.description or "Docstring is not available" }}' ></i>
|
|
76
|
+
<a href="{{ url_for('control.hide_function', instrument=instrument, function=function) }}"
|
|
77
|
+
data-method="patch" data-payload='{"hidden":true}' class="toggle-visibility">
|
|
78
|
+
<i style="float: right;" class="bi bi-eye-slash-fill text-muted" title="Hide function"></i>
|
|
79
|
+
</a>
|
|
80
|
+
<div class="form-control" style="border: none">
|
|
81
|
+
<form role="form" method='POST' name="{{function}}" id="{{function}}" action="{{ url_for('control.deck_controllers') }}?instrument={{ instrument }}">
|
|
82
|
+
<div class="form-group">
|
|
83
|
+
{{ form.hidden_tag() }}
|
|
84
|
+
{% for field in form %}
|
|
85
|
+
{% if field.type not in ['CSRFTokenField', 'HiddenField'] %}
|
|
86
|
+
<div class="input-group mb-3">
|
|
87
|
+
<label class="input-group-text">{{ field.label.text | format_name }}</label>
|
|
88
|
+
{% if field.type == "SubmitField" %}
|
|
89
|
+
{{ field(class="btn btn-dark") }}
|
|
90
|
+
{% elif field.type == "BooleanField" %}
|
|
91
|
+
{{ field(class="form-check-input") }}
|
|
92
|
+
{% else %}
|
|
93
|
+
{{ field(class="form-control") }}
|
|
94
|
+
{% endif %}
|
|
95
|
+
</div>
|
|
96
|
+
{% endif %}
|
|
97
|
+
{% endfor %}
|
|
98
|
+
</div>
|
|
99
|
+
<div class="input-group mb-3">
|
|
100
|
+
<button type="submit" name="{{ function }}" id="{{ function }}" class="form-control" style="background-color: #a5cece;">
|
|
101
|
+
{{ function | format_name }}
|
|
102
|
+
</button>
|
|
103
|
+
</div>
|
|
104
|
+
</form>
|
|
105
|
+
</div>
|
|
106
|
+
</div>
|
|
107
|
+
</div>
|
|
108
|
+
{% endif %}
|
|
109
|
+
{% endfor %}
|
|
110
|
+
</div>
|
|
111
|
+
<!-- Hidden functions accordion -->
|
|
112
|
+
<div class="accordion accordion-flush" id="accordionActions" >
|
|
113
|
+
<div class="accordion-item">
|
|
114
|
+
<h4 class="accordion-header">
|
|
115
|
+
<button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#hidden">
|
|
116
|
+
Hidden functions
|
|
117
|
+
</button>
|
|
118
|
+
</h4>
|
|
119
|
+
</div>
|
|
120
|
+
<div id="hidden" class="accordion-collapse collapse" data-bs-parent="#accordionActions">
|
|
121
|
+
<div class="accordion-body">
|
|
122
|
+
{% for function in hidden_instrument %}
|
|
123
|
+
<div>
|
|
124
|
+
{{ function }}
|
|
125
|
+
<a href="{{ url_for('control.hide_function', instrument=instrument, function=function) }}"
|
|
126
|
+
data-method="patch" data-payload='{"hidden":false}' class="toggle-visibility">
|
|
127
|
+
<i class="bi bi-eye-fill text-success" title="Show function"></i>
|
|
128
|
+
</a>
|
|
129
|
+
</div>
|
|
130
|
+
{% endfor %}
|
|
131
|
+
</div>
|
|
132
|
+
</div>
|
|
133
|
+
</div>
|
|
134
|
+
<script>
|
|
135
|
+
|
|
136
|
+
document.querySelectorAll('.toggle-visibility').forEach(el => {
|
|
137
|
+
el.addEventListener('click', e => {
|
|
138
|
+
e.preventDefault();
|
|
139
|
+
const url = el.getAttribute('href');
|
|
140
|
+
const payload = JSON.parse(el.getAttribute('data-payload') || '{}');
|
|
141
|
+
fetch(url, {
|
|
142
|
+
method: 'PATCH',
|
|
143
|
+
headers: {
|
|
144
|
+
'Content-Type': 'application/json'
|
|
145
|
+
},
|
|
146
|
+
body: JSON.stringify(payload)
|
|
147
|
+
}).then(response => {
|
|
148
|
+
if (response.ok) {
|
|
149
|
+
location.reload(); // or update the DOM directly
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
});
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
const saveOrderUrl = `{{ url_for('control.save_order', instrument=instrument) }}`;
|
|
156
|
+
const buttonIds = {{ session['card_order'][instrument] | tojson }};
|
|
157
|
+
</script>
|
|
158
|
+
<script src="{{ url_for('static', filename='js/sortable_card.js') }}"></script>
|
|
159
|
+
<script src="{{ url_for('static', filename='js/overlay.js') }}"></script>
|
|
160
|
+
{% else %}
|
|
161
|
+
<div class="alert alert-info mt-4">Select an instrument to view its methods.</div>
|
|
162
|
+
{% endif %}
|
|
163
|
+
</main>
|
|
164
|
+
</div>
|
|
165
|
+
</div>
|
|
166
|
+
{% endblock %}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
{% extends 'base.html' %}
|
|
2
|
+
{% block title %}IvoryOS | New devices{% endblock %}
|
|
3
|
+
|
|
4
|
+
{% block body %}
|
|
5
|
+
<div class="row">
|
|
6
|
+
<!-- Available Python API -->
|
|
7
|
+
<div class="col-xl-4 col-lg-4 col-md-6 mb-4">
|
|
8
|
+
<div class="card shadow-sm mb-4">
|
|
9
|
+
<div class="card-header">
|
|
10
|
+
<h5 class="mb-0">Available Python API</h5>
|
|
11
|
+
</div>
|
|
12
|
+
<div class="card-body">
|
|
13
|
+
{% for instrument in api_variables %}
|
|
14
|
+
<div class="card mb-2">
|
|
15
|
+
<div class="card-body p-2">
|
|
16
|
+
<a href="{{ url_for('control.temp.new_controller', instrument=instrument) }}" class="text-dark stretched-link">{{ instrument }}</a>
|
|
17
|
+
</div>
|
|
18
|
+
</div>
|
|
19
|
+
{% endfor %}
|
|
20
|
+
<div class="card mt-3">
|
|
21
|
+
<div class="card-body p-2">
|
|
22
|
+
<a data-bs-toggle="modal" href="#importAPI" class="stretched-link">
|
|
23
|
+
<i class="bi bi-folder-plus"></i> Import API
|
|
24
|
+
</a>
|
|
25
|
+
</div>
|
|
26
|
+
</div>
|
|
27
|
+
</div>
|
|
28
|
+
</div>
|
|
29
|
+
</div>
|
|
30
|
+
|
|
31
|
+
<!-- Connecting Device -->
|
|
32
|
+
<div class="col-xl-5 col-lg-5 col-md-6 mb-4">
|
|
33
|
+
{% if device %}
|
|
34
|
+
{# {{ device }}#}
|
|
35
|
+
<div class="card shadow-sm mb-4">
|
|
36
|
+
<div class="card-header">
|
|
37
|
+
<h5 class="mb-0">Connecting</h5>
|
|
38
|
+
</div>
|
|
39
|
+
<div class="card-body">
|
|
40
|
+
<form role="form" method="POST" name="init" action="{{ url_for('control.temp.new_controller', instrument=instrument) }}">
|
|
41
|
+
<div class="mb-3">
|
|
42
|
+
<label class="form-label" for="device_name">Name this device</label>
|
|
43
|
+
<input class="form-control" type="text" id="device_name" name="device_name" aria-describedby="nameHelpBlock" placeholder="e.g. {{device.__name__}}_1">
|
|
44
|
+
<div id="nameHelpBlock" class="form-text">
|
|
45
|
+
Name your instrument, avoid names that are defined on the right
|
|
46
|
+
</div>
|
|
47
|
+
</div>
|
|
48
|
+
{% for arg in device.__init__.__annotations__ %}
|
|
49
|
+
{% if not arg == "return" %}
|
|
50
|
+
<div class="mb-3">
|
|
51
|
+
<label class="form-label" for="{{arg}}">{{arg}}</label>
|
|
52
|
+
<input class="form-control" type="text" id="{{arg}}" name="{{arg}}"
|
|
53
|
+
placeholder="{{device.__init__.__annotations__[arg].__name__}}"
|
|
54
|
+
value="{{args.parameters[arg].default if not args.parameters[arg].default.__name__ == '_empty' else ''}}">
|
|
55
|
+
{% if device.__init__.__annotations__[arg].__module__ is not in ["builtins", "typing"] %}
|
|
56
|
+
<a role="button" href="{{ url_for('control.temp.new_controller', instrument=device.__init__.__annotations__[arg].__name__) }}" class="btn btn-secondary btn-sm mt-2">Initialize {{device.__init__.__annotations__[arg].__name__}} first</a>
|
|
57
|
+
{% endif %}
|
|
58
|
+
</div>
|
|
59
|
+
{% endif %}
|
|
60
|
+
{% endfor %}
|
|
61
|
+
<button type="submit" class="btn btn-dark">Connect</button>
|
|
62
|
+
</form>
|
|
63
|
+
</div>
|
|
64
|
+
</div>
|
|
65
|
+
{% endif %}
|
|
66
|
+
</div>
|
|
67
|
+
|
|
68
|
+
<!-- Defined Instruments -->
|
|
69
|
+
<div class="col-xl-3 col-lg-3 col-md-6 mb-4">
|
|
70
|
+
<div class="card shadow-sm mb-4">
|
|
71
|
+
<div class="card-header">
|
|
72
|
+
<h5 class="mb-0">Defined Instruments</h5>
|
|
73
|
+
</div>
|
|
74
|
+
<div class="card-body">
|
|
75
|
+
{% if defined_variables %}
|
|
76
|
+
<ul class="list-group">
|
|
77
|
+
{% for instrument in defined_variables %}
|
|
78
|
+
<li class="list-group-item">{{ instrument }}</li>
|
|
79
|
+
{% endfor %}
|
|
80
|
+
</ul>
|
|
81
|
+
{% else %}
|
|
82
|
+
<span class="text-muted">No instruments defined.</span>
|
|
83
|
+
{% endif %}
|
|
84
|
+
</div>
|
|
85
|
+
</div>
|
|
86
|
+
</div>
|
|
87
|
+
</div>
|
|
88
|
+
|
|
89
|
+
<!-- Import API Modal -->
|
|
90
|
+
<div class="modal fade" id="importAPI" tabindex="-1" aria-labelledby="importModal" aria-hidden="true">
|
|
91
|
+
<div class="modal-dialog">
|
|
92
|
+
<div class="modal-content">
|
|
93
|
+
<div class="modal-header">
|
|
94
|
+
<h1 class="modal-title fs-5" id="importModal">Import API by file path</h1>
|
|
95
|
+
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
|
96
|
+
</div>
|
|
97
|
+
<form method="POST" action="{{ url_for('control.temp.import_api') }}" enctype="multipart/form-data">
|
|
98
|
+
<div class="modal-body">
|
|
99
|
+
<div class="mb-3">
|
|
100
|
+
<label class="form-label" for="filepath">File Path:</label>
|
|
101
|
+
<input type="text" class="form-control" name="filepath" id="filepath">
|
|
102
|
+
</div>
|
|
103
|
+
</div>
|
|
104
|
+
<div class="modal-footer">
|
|
105
|
+
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
|
|
106
|
+
<button type="submit" class="btn btn-primary">Save</button>
|
|
107
|
+
</div>
|
|
108
|
+
</form>
|
|
109
|
+
</div>
|
|
110
|
+
</div>
|
|
111
|
+
</div>
|
|
112
|
+
{% endblock %}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
from flask import session
|
|
2
|
+
|
|
3
|
+
from ivoryos.utils.global_config import GlobalConfig
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
global_config = GlobalConfig()
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def find_instrument_by_name(name: str):
|
|
10
|
+
"""
|
|
11
|
+
find instrument class object by instance name
|
|
12
|
+
"""
|
|
13
|
+
if name.startswith("deck"):
|
|
14
|
+
name = name.replace("deck.", "")
|
|
15
|
+
return getattr(global_config.deck, name)
|
|
16
|
+
elif name in global_config.defined_variables:
|
|
17
|
+
return global_config.defined_variables[name]
|
|
18
|
+
elif name in globals():
|
|
19
|
+
return globals()[name]
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def get_session_by_instrument(session_name, instrument):
|
|
23
|
+
"""get data from session by instrument"""
|
|
24
|
+
session_object = session.get(session_name, {})
|
|
25
|
+
functions = session_object.get(instrument, [])
|
|
26
|
+
return functions
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def post_session_by_instrument(session_name, instrument, data):
|
|
30
|
+
"""
|
|
31
|
+
save new data to session by instrument
|
|
32
|
+
:param session_name: "card_order" or "hidden_functions"
|
|
33
|
+
:param instrument: function name of class object
|
|
34
|
+
:param data: order list or hidden function list
|
|
35
|
+
"""
|
|
36
|
+
session_object = session.get(session_name, {})
|
|
37
|
+
session_object[instrument] = data
|
|
38
|
+
session[session_name] = session_object
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import os
|
|
2
|
+
|
|
3
|
+
from flask import Blueprint, redirect, url_for, request, render_template, current_app, jsonify, send_file
|
|
4
|
+
from flask_login import login_required
|
|
5
|
+
|
|
6
|
+
from ivoryos.utils.db_models import db, WorkflowRun, WorkflowStep
|
|
7
|
+
|
|
8
|
+
data = Blueprint('data', __name__, template_folder='templates')
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
@data.route('/executions/records')
|
|
13
|
+
def list_workflows():
|
|
14
|
+
"""
|
|
15
|
+
.. :quickref: Workflow Execution Database; list all workflow execution records
|
|
16
|
+
|
|
17
|
+
list all workflow execution records
|
|
18
|
+
|
|
19
|
+
.. http:get:: /executions/records
|
|
20
|
+
|
|
21
|
+
"""
|
|
22
|
+
query = WorkflowRun.query.order_by(WorkflowRun.id.desc())
|
|
23
|
+
search_term = request.args.get("keyword", None)
|
|
24
|
+
if search_term:
|
|
25
|
+
query = query.filter(WorkflowRun.name.like(f'%{search_term}%'))
|
|
26
|
+
page = request.args.get('page', default=1, type=int)
|
|
27
|
+
per_page = 10
|
|
28
|
+
|
|
29
|
+
workflows = query.paginate(page=page, per_page=per_page, error_out=False)
|
|
30
|
+
if request.accept_mimetypes.best_match(['application/json', 'text/html']) == 'application/json':
|
|
31
|
+
workflows = query.all()
|
|
32
|
+
workflow_data = {w.id:{"workflow_name":w.name, "start_time":w.start_time} for w in workflows}
|
|
33
|
+
return jsonify({
|
|
34
|
+
"workflow_data": workflow_data,
|
|
35
|
+
})
|
|
36
|
+
else:
|
|
37
|
+
return render_template('workflow_database.html', workflows=workflows)
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
@data.get("/executions/records/<int:workflow_id>")
|
|
41
|
+
def workflow_logs(workflow_id:int):
|
|
42
|
+
"""
|
|
43
|
+
.. :quickref: Workflow Data Database; get workflow data, steps, and logs
|
|
44
|
+
|
|
45
|
+
get workflow data logs by workflow id
|
|
46
|
+
|
|
47
|
+
.. http:get:: /executions/<int:workflow_id>
|
|
48
|
+
|
|
49
|
+
:param workflow_id: workflow id
|
|
50
|
+
:type workflow_id: int
|
|
51
|
+
"""
|
|
52
|
+
|
|
53
|
+
if request.method == 'GET':
|
|
54
|
+
workflow = db.session.get(WorkflowRun, workflow_id)
|
|
55
|
+
steps = WorkflowStep.query.filter_by(workflow_id=workflow_id).order_by(WorkflowStep.start_time).all()
|
|
56
|
+
|
|
57
|
+
# Use full objects for template rendering
|
|
58
|
+
grouped = {
|
|
59
|
+
"prep": [],
|
|
60
|
+
"script": {},
|
|
61
|
+
"cleanup": [],
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
# Use dicts for JSON response
|
|
65
|
+
grouped_json = {
|
|
66
|
+
"prep": [],
|
|
67
|
+
"script": {},
|
|
68
|
+
"cleanup": [],
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
for step in steps:
|
|
72
|
+
step_dict = step.as_dict()
|
|
73
|
+
|
|
74
|
+
if step.phase == "prep":
|
|
75
|
+
grouped["prep"].append(step)
|
|
76
|
+
grouped_json["prep"].append(step_dict)
|
|
77
|
+
|
|
78
|
+
elif step.phase == "script":
|
|
79
|
+
grouped["script"].setdefault(step.repeat_index, []).append(step)
|
|
80
|
+
grouped_json["script"].setdefault(step.repeat_index, []).append(step_dict)
|
|
81
|
+
|
|
82
|
+
elif step.phase == "cleanup" or step.method_name == "stop":
|
|
83
|
+
grouped["cleanup"].append(step)
|
|
84
|
+
grouped_json["cleanup"].append(step_dict)
|
|
85
|
+
|
|
86
|
+
if request.accept_mimetypes.best_match(['application/json', 'text/html']) == 'application/json':
|
|
87
|
+
return jsonify({
|
|
88
|
+
"workflow_info": workflow.as_dict(),
|
|
89
|
+
"steps": grouped_json,
|
|
90
|
+
})
|
|
91
|
+
else:
|
|
92
|
+
return render_template("workflow_view.html", workflow=workflow, grouped=grouped)
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
@data.delete("/executions/records/<int:workflow_id>")
|
|
96
|
+
@login_required
|
|
97
|
+
def delete_workflow_record(workflow_id: int):
|
|
98
|
+
"""
|
|
99
|
+
.. :quickref: Workflow Data Database; delete a workflow execution record
|
|
100
|
+
|
|
101
|
+
delete a workflow execution record by workflow id
|
|
102
|
+
|
|
103
|
+
.. http:delete:: /executions/records/<int:workflow_id>
|
|
104
|
+
|
|
105
|
+
:param workflow_id: workflow id
|
|
106
|
+
:type workflow_id: int
|
|
107
|
+
:status 200: return success message
|
|
108
|
+
"""
|
|
109
|
+
run = WorkflowRun.query.get(workflow_id)
|
|
110
|
+
db.session.delete(run)
|
|
111
|
+
db.session.commit()
|
|
112
|
+
return jsonify(success=True)
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
@data.route('/files/execution-data/<string:filename>')
|
|
116
|
+
def download_results(filename:str):
|
|
117
|
+
"""
|
|
118
|
+
.. :quickref: Workflow data; download a workflow data file (.CSV)
|
|
119
|
+
|
|
120
|
+
.. http:get:: /files/execution-data/<string:filename>
|
|
121
|
+
|
|
122
|
+
:param filename: workflow data filename
|
|
123
|
+
:type filename: str
|
|
124
|
+
|
|
125
|
+
# :status 302: load pseudo deck and then redirects to :http:get:`/ivoryos/executions`
|
|
126
|
+
"""
|
|
127
|
+
|
|
128
|
+
filepath = os.path.join(current_app.config["DATA_FOLDER"], filename)
|
|
129
|
+
return send_file(os.path.abspath(filepath), as_attachment=True)
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
<div class="card mb-2 {{ 'border-danger text-danger bg-light' if step.run_error else 'border-secondary' }}">
|
|
2
|
+
<div class="card-body p-2">
|
|
3
|
+
<strong>{{ step.method_name | format_name }}</strong>
|
|
4
|
+
<small class="text-muted">
|
|
5
|
+
<i class="fas fa-play-circle me-1"></i> Start: {{ step.start_time.strftime('%H:%M:%S') if step.start_time else 'N/A' }}
|
|
6
|
+
<i class="fas fa-stop-circle ms-2 me-1"></i> End: {{ step.end_time.strftime('%H:%M:%S') if step.end_time else 'N/A' }}
|
|
7
|
+
<!-- {% if step.run_error %}
|
|
8
|
+
<i class="fas fa-stop-circle ms-2 me-1"></i> Error: {{ step.run_error if step.run_error else 'N/A' }}
|
|
9
|
+
{% endif %} -->
|
|
10
|
+
</small>
|
|
11
|
+
<!-- <small>Error: {{ step.run_error }}</small> -->
|
|
12
|
+
</div>
|
|
13
|
+
</div>
|