Compare commits
3 Commits
8a611998c0
...
ac502c5fdf
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ac502c5fdf | ||
|
|
eeaf15ff42 | ||
|
|
d158aa449c |
@ -11,7 +11,7 @@ pillow==11.0.0
|
||||
plantuml==0.3.0
|
||||
pyparsing==3.2.0
|
||||
PyQt5==5.15.11
|
||||
PyQt5-Qt5==5.15.15
|
||||
PyQt5-Qt5==5.15.2
|
||||
PyQt5_sip==12.15.0
|
||||
pyqtgraph==0.13.7
|
||||
python-dateutil==2.9.0.post0
|
||||
|
||||
BIN
src/OptAlgorithm/__pycache__/AutoConfigClass.cpython-310.pyc
Normal file
BIN
src/OptAlgorithm/__pycache__/AutoConfigClass.cpython-310.pyc
Normal file
Binary file not shown.
BIN
src/OptAlgorithm/__pycache__/ConstantCalculator.cpython-310.pyc
Normal file
BIN
src/OptAlgorithm/__pycache__/ConstantCalculator.cpython-310.pyc
Normal file
Binary file not shown.
BIN
src/OptAlgorithm/__pycache__/OptAlgorithm.cpython-310.pyc
Normal file
BIN
src/OptAlgorithm/__pycache__/OptAlgorithm.cpython-310.pyc
Normal file
Binary file not shown.
BIN
src/OptAlgorithm/__pycache__/OptTimeCalculator.cpython-310.pyc
Normal file
BIN
src/OptAlgorithm/__pycache__/OptTimeCalculator.cpython-310.pyc
Normal file
Binary file not shown.
BIN
src/OptAlgorithm/__pycache__/PhaseCalc.cpython-310.pyc
Normal file
BIN
src/OptAlgorithm/__pycache__/PhaseCalc.cpython-310.pyc
Normal file
Binary file not shown.
BIN
src/OptAlgorithm/__pycache__/__init__.cpython-310.pyc
Normal file
BIN
src/OptAlgorithm/__pycache__/__init__.cpython-310.pyc
Normal file
Binary file not shown.
1
src/__init__.py
Normal file
1
src/__init__.py
Normal file
@ -0,0 +1 @@
|
||||
|
||||
BIN
src/__pycache__/__init__.cpython-310.pyc
Normal file
BIN
src/__pycache__/__init__.cpython-310.pyc
Normal file
Binary file not shown.
BIN
src/__pycache__/main.cpython-310.pyc
Normal file
BIN
src/__pycache__/main.cpython-310.pyc
Normal file
Binary file not shown.
@ -1 +1,3 @@
|
||||
from .plot_window import PlotWindow
|
||||
from .settings_window import settingsWindow
|
||||
from .app import app
|
||||
|
||||
BIN
src/gui/__pycache__/__init__.cpython-310.pyc
Normal file
BIN
src/gui/__pycache__/__init__.cpython-310.pyc
Normal file
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.
BIN
src/gui/__pycache__/plot_window.cpython-310.pyc
Normal file
BIN
src/gui/__pycache__/plot_window.cpython-310.pyc
Normal file
Binary file not shown.
BIN
src/gui/__pycache__/qt_settings.cpython-310.pyc
Normal file
BIN
src/gui/__pycache__/qt_settings.cpython-310.pyc
Normal file
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.
BIN
src/gui/__pycache__/settings_windows.cpython-310.pyc
Normal file
BIN
src/gui/__pycache__/settings_windows.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
|
||||
|
||||
from src.gui import qt_settings as qts
|
||||
|
||||
from src.OptAlgorithm import OptAlgorithm
|
||||
|
||||
|
||||
@ -18,14 +19,27 @@ class PlotWindow:
|
||||
self.float_dict = float_dict
|
||||
self.scaler = int(system_config['UML_time_scaler'])
|
||||
self.WeldTime = operator_config['time_wielding'] #[sec]
|
||||
|
||||
self.alpha = 100 #[0-255 прозрачность фона]
|
||||
|
||||
self._getIdealTimings()
|
||||
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):
|
||||
self.app = pg.mkQApp("Plotting")
|
||||
self.win = pg.GraphicsLayoutWidget(show=True, title="")
|
||||
self.win.resize(1000,600)
|
||||
self.win.setWindowTitle('')
|
||||
@ -50,16 +64,25 @@ class PlotWindow:
|
||||
self.p12.setAutoVisible(x=False, y=True)
|
||||
self.p13.setAutoVisible(x=False, y=True)
|
||||
|
||||
def _init_graph(self, title, Yname, Yunits, Xname, Xunits):
|
||||
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
|
||||
self._updatePlots()
|
||||
|
||||
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()
|
||||
times = np.arange(20000)/10
|
||||
self._plotIdealData(times)
|
||||
@ -169,8 +192,8 @@ class PlotWindow:
|
||||
|
||||
def _makeFiller(self, x1, y1, x2, y2, color):
|
||||
alpha = self.alpha
|
||||
eq1 = pg.PlotDataItem(x1, y1, pen=pg.mkPen(color='#000000', width=2))
|
||||
eq2 = pg.PlotDataItem(x2, y2, pen=pg.mkPen(color='#000000', width=2))
|
||||
eq1 = pg.PlotDataItem(x1, y1, pen=pg.mkPen(color='#000000', width=1))
|
||||
eq2 = pg.PlotDataItem(x2, y2, pen=pg.mkPen(color='#000000', width=1))
|
||||
bg = pg.FillBetweenItem(eq1, eq2, qts.RGBA[color]+(alpha,))
|
||||
return eq1, eq2, bg
|
||||
|
||||
|
||||
56
src/gui/settings_window.py
Normal file
56
src/gui/settings_window.py
Normal file
@ -0,0 +1,56 @@
|
||||
import pyqtgraph as pg
|
||||
from pyqtgraph.Qt import QtWidgets
|
||||
from pyqtgraph.parametertree import Parameter, ParameterTree
|
||||
|
||||
from src.utils.json_tools import read_json, write_json
|
||||
|
||||
class settingsWindow(QtWidgets.QWidget):
|
||||
def __init__(self, path: str, name: str, upd_func):
|
||||
super(settingsWindow, self).__init__()
|
||||
self.settingsPath = path
|
||||
self.name = name
|
||||
|
||||
self.data = {}
|
||||
self.params = None
|
||||
self.load_settings()
|
||||
self._init_ui()
|
||||
self.params.sigTreeStateChanged.connect(upd_func)
|
||||
|
||||
def load_settings(self):
|
||||
self.data = read_json(self.settingsPath)
|
||||
|
||||
def write_settings(self):
|
||||
write_json(self.settingsPath, self.data)
|
||||
|
||||
def _getTreeStructure(self) -> list:
|
||||
params = []
|
||||
for key, value in self.data.items():
|
||||
params.append({'name': str(key), 'type': type(value).__name__, 'value': value})
|
||||
return params
|
||||
|
||||
def _init_ui(self):
|
||||
temp = self._getTreeStructure()
|
||||
self.params = Parameter.create(name='params', type='group', children=temp)
|
||||
|
||||
|
||||
ParamsTree = ParameterTree()
|
||||
ParamsTree.setParameters(self.params)
|
||||
ParamsTree.setWindowTitle('Settings ,f,f')
|
||||
layout = QtWidgets.QGridLayout()
|
||||
layout.addWidget(ParamsTree, 0,0)
|
||||
self.setLayout(layout)
|
||||
|
||||
self.show()
|
||||
|
||||
def getParams(self) -> dict:
|
||||
self.data = {}
|
||||
for p in self.params:
|
||||
self.data[p.name()] = p.value()
|
||||
return self.data
|
||||
|
||||
if __name__ == '__main__':
|
||||
app = pg.mkQApp("Parameter Tree Example")
|
||||
window = settingsWindow('params\operator_params.json', 'operator')
|
||||
app.exec()
|
||||
|
||||
|
||||
39
src/main.py
39
src/main.py
@ -1,43 +1,10 @@
|
||||
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
|
||||
|
||||
|
||||
def get_ideal_timings(opt: OptAlgorithm) -> list[float]:
|
||||
data = opt.Ts
|
||||
ideal_time = [data['tclose'], data['tgrow'], opt.getMarkOpen()]
|
||||
return ideal_time
|
||||
|
||||
from src.gui import app
|
||||
|
||||
def main():
|
||||
operator_params = read_json("params/operator_params.json")
|
||||
system_params = read_json("params/system_params.json")
|
||||
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.mkQApp("Plotting")
|
||||
temp = app()
|
||||
pg.exec()
|
||||
|
||||
|
||||
|
||||
BIN
src/uml/__pycache__/__init__.cpython-310.pyc
Normal file
BIN
src/uml/__pycache__/__init__.cpython-310.pyc
Normal file
Binary file not shown.
BIN
src/uml/__pycache__/creator.cpython-310.pyc
Normal file
BIN
src/uml/__pycache__/creator.cpython-310.pyc
Normal file
Binary file not shown.
BIN
src/uml/__pycache__/request_generator.cpython-310.pyc
Normal file
BIN
src/uml/__pycache__/request_generator.cpython-310.pyc
Normal file
Binary file not shown.
@ -95,6 +95,18 @@ class UMLCreator:
|
||||
except Exception as 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()
|
||||
self._generate_svg(real, client, ideal, bool_)
|
||||
|
||||
@ -1,2 +1,2 @@
|
||||
from .json_tools import read_json
|
||||
from .json_tools import read_json, write_json
|
||||
from .diagram_parser import DiagramParser
|
||||
BIN
src/utils/__pycache__/__init__.cpython-310.pyc
Normal file
BIN
src/utils/__pycache__/__init__.cpython-310.pyc
Normal file
Binary file not shown.
BIN
src/utils/__pycache__/diagram_parser.cpython-310.pyc
Normal file
BIN
src/utils/__pycache__/diagram_parser.cpython-310.pyc
Normal file
Binary file not shown.
BIN
src/utils/__pycache__/json_tools.cpython-310.pyc
Normal file
BIN
src/utils/__pycache__/json_tools.cpython-310.pyc
Normal file
Binary file not shown.
@ -9,3 +9,13 @@ def read_json(filepath: str) -> dict:
|
||||
with open(filepath, 'r') as json_file:
|
||||
data = json.load(json_file)
|
||||
return data
|
||||
|
||||
def write_json(filepath: str, data: dict):
|
||||
if not path.exists(filepath):
|
||||
raise FileNotFoundError(f"JSON file {filepath} not found!")
|
||||
|
||||
try:
|
||||
with open(filepath, 'w') as json_file:
|
||||
json.dump(data, json_file)
|
||||
except Exception as e:
|
||||
raise e
|
||||
Loading…
Reference in New Issue
Block a user