создан класс приложения с окнами настроек и графиков
This commit is contained in:
parent
eeaf15ff42
commit
ac502c5fdf
BIN
src/__pycache__/main.cpython-310.pyc
Normal file
BIN
src/__pycache__/main.cpython-310.pyc
Normal file
Binary file not shown.
@ -1,2 +1,3 @@
|
|||||||
from .plot_window import PlotWindow
|
from .plot_window import PlotWindow
|
||||||
from .settings_windows import settingsWindow
|
from .settings_window import settingsWindow
|
||||||
|
from .app import app
|
||||||
|
|||||||
Binary file not shown.
BIN
src/gui/__pycache__/app.cpython-310.pyc
Normal file
BIN
src/gui/__pycache__/app.cpython-310.pyc
Normal file
Binary file not shown.
Binary file not shown.
BIN
src/gui/__pycache__/settings_window.cpython-310.pyc
Normal file
BIN
src/gui/__pycache__/settings_window.cpython-310.pyc
Normal file
Binary file not shown.
71
src/gui/app.py
Normal file
71
src/gui/app.py
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
import pyqtgraph as pg
|
||||||
|
|
||||||
|
from src.utils import read_json, DiagramParser
|
||||||
|
from src.uml import Request, UMLCreator
|
||||||
|
from src.OptAlgorithm import OptAlgorithm
|
||||||
|
from src.gui import PlotWindow, settingsWindow
|
||||||
|
|
||||||
|
|
||||||
|
class app:
|
||||||
|
def __init__(self):
|
||||||
|
|
||||||
|
self.parser = DiagramParser()
|
||||||
|
self.request_generator = Request(server_url='http://www.plantuml.com/plantuml/svg/')
|
||||||
|
|
||||||
|
self.operSettings = settingsWindow("params\operator_params.json", 'Operator', self._update_settings)
|
||||||
|
self.sysSettings = settingsWindow("params\system_params.json", 'System', self._update_settings)
|
||||||
|
|
||||||
|
self._load_preset()
|
||||||
|
|
||||||
|
def _get_ideal_timings(self, opt: OptAlgorithm) -> list[float]:
|
||||||
|
data = opt.Ts
|
||||||
|
ideal_time = [data['tclose'], data['tgrow'], opt.getMarkOpen()]
|
||||||
|
return ideal_time
|
||||||
|
|
||||||
|
def _load_preset(self):
|
||||||
|
self.operator_params = read_json("params/operator_params.json")
|
||||||
|
self.system_params = read_json("params/system_params.json")
|
||||||
|
|
||||||
|
self.opt_algorithm = OptAlgorithm(operator_config=self.operator_params, system_config=self.system_params)
|
||||||
|
self.ideal_times = self._get_ideal_timings(self.opt_algorithm)
|
||||||
|
|
||||||
|
self.parser.setData("trace_samples/2024_11_01-09_39_17B00.csv")
|
||||||
|
self.bool_dict = self.parser.getBoolDict()
|
||||||
|
self.float_dict = self.parser.getFloatDict()
|
||||||
|
|
||||||
|
self.plotter = PlotWindow(operator_config=self.operator_params,
|
||||||
|
system_config=self.system_params,
|
||||||
|
opt=self.opt_algorithm,
|
||||||
|
bool_dict=self.bool_dict,
|
||||||
|
float_dict=self.float_dict)
|
||||||
|
|
||||||
|
self.uml_creator = UMLCreator(system_config=self.system_params,
|
||||||
|
request_generator=self.request_generator,
|
||||||
|
ideal_time=self.ideal_times,
|
||||||
|
bool_dict=self.bool_dict,
|
||||||
|
float_dict=self.float_dict)
|
||||||
|
|
||||||
|
def _update_settings(self, _):
|
||||||
|
self.operator_params = self.operSettings.getParams()
|
||||||
|
self.system_params = self.sysSettings.getParams()
|
||||||
|
|
||||||
|
self.opt_algorithm = OptAlgorithm(operator_config=self.operator_params, system_config=self.system_params)
|
||||||
|
self.ideal_times = self._get_ideal_timings(self.opt_algorithm)
|
||||||
|
|
||||||
|
self.uml_creator.update_uml(system_config=self.system_params,
|
||||||
|
request_generator=self.request_generator,
|
||||||
|
ideal_time=self.ideal_times,
|
||||||
|
bool_dict=self.bool_dict,
|
||||||
|
float_dict=self.float_dict)
|
||||||
|
|
||||||
|
self.plotter.update_data(operator_config=self.operator_params,
|
||||||
|
system_config=self.system_params,
|
||||||
|
opt=self.opt_algorithm,
|
||||||
|
bool_dict=self.bool_dict,
|
||||||
|
float_dict=self.float_dict)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
pg.mkQApp("Plotting")
|
||||||
|
temp = app()
|
||||||
|
pg.exec()
|
||||||
@ -2,6 +2,7 @@ import pyqtgraph as pg
|
|||||||
import numpy as np
|
import numpy as np
|
||||||
|
|
||||||
from src.gui import qt_settings as qts
|
from src.gui import qt_settings as qts
|
||||||
|
|
||||||
from src.OptAlgorithm import OptAlgorithm
|
from src.OptAlgorithm import OptAlgorithm
|
||||||
|
|
||||||
|
|
||||||
@ -18,14 +19,27 @@ class PlotWindow:
|
|||||||
self.float_dict = float_dict
|
self.float_dict = float_dict
|
||||||
self.scaler = int(system_config['UML_time_scaler'])
|
self.scaler = int(system_config['UML_time_scaler'])
|
||||||
self.WeldTime = operator_config['time_wielding'] #[sec]
|
self.WeldTime = operator_config['time_wielding'] #[sec]
|
||||||
|
self.alpha = 100 #[0-255 прозрачность фона]
|
||||||
|
|
||||||
self._getIdealTimings()
|
self._getIdealTimings()
|
||||||
self._init_app()
|
self._init_app()
|
||||||
self.alpha = 100 #[0-255 прозрачность фона]
|
|
||||||
|
|
||||||
|
def update_data(self,
|
||||||
|
system_config : dict,
|
||||||
|
operator_config: dict,
|
||||||
|
opt: OptAlgorithm,
|
||||||
|
bool_dict: dict,
|
||||||
|
float_dict: dict):
|
||||||
|
self.opt = opt
|
||||||
|
self.bool_dict = bool_dict
|
||||||
|
self.float_dict = float_dict
|
||||||
|
self.scaler = int(system_config['UML_time_scaler'])
|
||||||
|
self.WeldTime = operator_config['time_wielding'] #[sec]
|
||||||
|
self._getIdealTimings()
|
||||||
|
self._updatePlots()
|
||||||
|
|
||||||
def _init_app(self):
|
def _init_app(self):
|
||||||
self.app = pg.mkQApp("Plotting")
|
|
||||||
self.win = pg.GraphicsLayoutWidget(show=True, title="")
|
self.win = pg.GraphicsLayoutWidget(show=True, title="")
|
||||||
self.win.resize(1000,600)
|
self.win.resize(1000,600)
|
||||||
self.win.setWindowTitle('')
|
self.win.setWindowTitle('')
|
||||||
@ -50,16 +64,25 @@ class PlotWindow:
|
|||||||
self.p12.setAutoVisible(x=False, y=True)
|
self.p12.setAutoVisible(x=False, y=True)
|
||||||
self.p13.setAutoVisible(x=False, y=True)
|
self.p13.setAutoVisible(x=False, y=True)
|
||||||
|
|
||||||
def _init_graph(self, title, Yname, Yunits, Xname, Xunits):
|
self._updatePlots()
|
||||||
p11 = self.win.addPlot(title = title)
|
|
||||||
p11.showGrid(x=True, y=True)
|
|
||||||
p11.setLabel('left', Yname, units=Yunits)
|
|
||||||
p11.setLabel('bottom', Xname, units=Xunits)
|
|
||||||
legend1 = pg.LegendItem((80,60), offset=(70,20))
|
|
||||||
legend1.setParentItem(p11)
|
|
||||||
return p11, legend1
|
|
||||||
|
|
||||||
def updatePlots(self):
|
def _init_graph(self, title, Yname, Yunits, Xname, Xunits):
|
||||||
|
plot = self.win.addPlot(title = title)
|
||||||
|
plot.showGrid(x=True, y=True)
|
||||||
|
plot.setLabel('left', Yname, units=Yunits)
|
||||||
|
plot.setLabel('bottom', Xname, units=Xunits)
|
||||||
|
legend1 = pg.LegendItem((80,60), offset=(70,20))
|
||||||
|
legend1.setParentItem(plot)
|
||||||
|
return plot, legend1
|
||||||
|
|
||||||
|
def _updatePlots(self):
|
||||||
|
self.p11.clear()
|
||||||
|
self.l11.clear()
|
||||||
|
self.p12.clear()
|
||||||
|
self.l12.clear()
|
||||||
|
self.p13.clear()
|
||||||
|
self.l13.clear()
|
||||||
|
|
||||||
self._plotRealData()
|
self._plotRealData()
|
||||||
times = np.arange(20000)/10
|
times = np.arange(20000)/10
|
||||||
self._plotIdealData(times)
|
self._plotIdealData(times)
|
||||||
|
|||||||
@ -1,20 +1,20 @@
|
|||||||
import pyqtgraph as pg
|
import pyqtgraph as pg
|
||||||
from pyqtgraph.Qt import QtWidgets
|
from pyqtgraph.Qt import QtWidgets
|
||||||
import pyqtgraph.parametertree.parameterTypes as pTypes
|
|
||||||
from pyqtgraph.parametertree import Parameter, ParameterTree
|
from pyqtgraph.parametertree import Parameter, ParameterTree
|
||||||
|
|
||||||
from src.utils.json_tools import read_json, write_json
|
from src.utils.json_tools import read_json, write_json
|
||||||
|
|
||||||
class settingsWindow(QtWidgets.QWidget):
|
class settingsWindow(QtWidgets.QWidget):
|
||||||
def __init__(self, path: str, name: str):
|
def __init__(self, path: str, name: str, upd_func):
|
||||||
super(settingsWindow, self).__init__()
|
super(settingsWindow, self).__init__()
|
||||||
self.settingsPath = path
|
self.settingsPath = path
|
||||||
self.name = name
|
self.name = name
|
||||||
|
|
||||||
self.data = {}
|
self.data = {}
|
||||||
self.params = None
|
self.params = None
|
||||||
self.load_settings()
|
self.load_settings()
|
||||||
self.init_ui()
|
self._init_ui()
|
||||||
|
self.params.sigTreeStateChanged.connect(upd_func)
|
||||||
|
|
||||||
def load_settings(self):
|
def load_settings(self):
|
||||||
self.data = read_json(self.settingsPath)
|
self.data = read_json(self.settingsPath)
|
||||||
@ -28,10 +28,10 @@ class settingsWindow(QtWidgets.QWidget):
|
|||||||
params.append({'name': str(key), 'type': type(value).__name__, 'value': value})
|
params.append({'name': str(key), 'type': type(value).__name__, 'value': value})
|
||||||
return params
|
return params
|
||||||
|
|
||||||
def init_ui(self):
|
def _init_ui(self):
|
||||||
temp = self._getTreeStructure()
|
temp = self._getTreeStructure()
|
||||||
self.params = Parameter.create(name='params', type='group', children=temp)
|
self.params = Parameter.create(name='params', type='group', children=temp)
|
||||||
self.params.sigTreeStateChanged.connect(self.change)
|
|
||||||
|
|
||||||
ParamsTree = ParameterTree()
|
ParamsTree = ParameterTree()
|
||||||
ParamsTree.setParameters(self.params)
|
ParamsTree.setParameters(self.params)
|
||||||
@ -41,20 +41,12 @@ class settingsWindow(QtWidgets.QWidget):
|
|||||||
self.setLayout(layout)
|
self.setLayout(layout)
|
||||||
|
|
||||||
self.show()
|
self.show()
|
||||||
|
|
||||||
def change(self, param, changes):
|
|
||||||
print("tree changes:")
|
|
||||||
for param, change, data in changes:
|
|
||||||
path = self.params.childPath(param)
|
|
||||||
if path is not None:
|
|
||||||
childName = '.'.join(path)
|
|
||||||
else:
|
|
||||||
childName = param.name()
|
|
||||||
print(' parameter: %s'% childName)
|
|
||||||
print(' change: %s'% change)
|
|
||||||
print(' data: %s'% str(data))
|
|
||||||
print(' ----------')
|
|
||||||
|
|
||||||
|
def getParams(self) -> dict:
|
||||||
|
self.data = {}
|
||||||
|
for p in self.params:
|
||||||
|
self.data[p.name()] = p.value()
|
||||||
|
return self.data
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
app = pg.mkQApp("Parameter Tree Example")
|
app = pg.mkQApp("Parameter Tree Example")
|
||||||
39
src/main.py
39
src/main.py
@ -1,43 +1,10 @@
|
|||||||
import pyqtgraph as pg
|
import pyqtgraph as pg
|
||||||
|
|
||||||
from utils import read_json, DiagramParser
|
from src.gui import app
|
||||||
from uml import Request, UMLCreator
|
|
||||||
from OptAlgorithm import OptAlgorithm
|
|
||||||
from gui import PlotWindow
|
|
||||||
|
|
||||||
|
|
||||||
def get_ideal_timings(opt: OptAlgorithm) -> list[float]:
|
|
||||||
data = opt.Ts
|
|
||||||
ideal_time = [data['tclose'], data['tgrow'], opt.getMarkOpen()]
|
|
||||||
return ideal_time
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
operator_params = read_json("params/operator_params.json")
|
pg.mkQApp("Plotting")
|
||||||
system_params = read_json("params/system_params.json")
|
temp = app()
|
||||||
opt_algorithm = OptAlgorithm(operator_config=operator_params, system_config=system_params)
|
|
||||||
ideal_times = get_ideal_timings(opt_algorithm)
|
|
||||||
|
|
||||||
parser = DiagramParser()
|
|
||||||
parser.setData("trace_samples/2024_11_01-09_39_17B00.csv")
|
|
||||||
bool_dict = parser.getBoolDict()
|
|
||||||
float_dict = parser.getFloatDict()
|
|
||||||
|
|
||||||
request_generator = Request(server_url='http://www.plantuml.com/plantuml/svg/')
|
|
||||||
uml_creator = UMLCreator(system_config=system_params,
|
|
||||||
request_generator=request_generator,
|
|
||||||
ideal_time=ideal_times,
|
|
||||||
bool_dict=bool_dict,
|
|
||||||
float_dict=float_dict)
|
|
||||||
uml_creator.update_uml()
|
|
||||||
|
|
||||||
app = PlotWindow(operator_config=operator_params,
|
|
||||||
system_config=system_params,
|
|
||||||
opt=opt_algorithm,
|
|
||||||
bool_dict=bool_dict,
|
|
||||||
float_dict=float_dict)
|
|
||||||
|
|
||||||
app.updatePlots()
|
|
||||||
pg.exec()
|
pg.exec()
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
@ -95,6 +95,18 @@ class UMLCreator:
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"SVG generate error: {e}")
|
print(f"SVG generate error: {e}")
|
||||||
|
|
||||||
def update_uml(self) -> None:
|
def update_uml(self,
|
||||||
|
system_config : dict,
|
||||||
|
request_generator: Request,
|
||||||
|
ideal_time: list[float],
|
||||||
|
bool_dict: dict,
|
||||||
|
float_dict: dict):
|
||||||
|
|
||||||
|
self._request_generator = request_generator
|
||||||
|
self._ideal_time = ideal_time
|
||||||
|
self.bool_dict = bool_dict
|
||||||
|
self.float_dict = float_dict
|
||||||
|
self.scaler = int(system_config['UML_time_scaler'])
|
||||||
|
|
||||||
real, client, ideal, bool_ = self._build_data()
|
real, client, ideal, bool_ = self._build_data()
|
||||||
self._generate_svg(real, client, ideal, bool_)
|
self._generate_svg(real, client, ideal, bool_)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user