dev: начало этапа идеального графика совмещено с этапом в реальном

This commit is contained in:
Andrew 2024-11-12 13:26:16 +03:00
parent 7d71a4774f
commit 40af0afda8
10 changed files with 104 additions and 59 deletions

View File

@ -15,5 +15,9 @@
"position_start_2": 0.08, "position_start_2": 0.08,
"k_prop": 0.05, "k_prop": 0.05,
"time_capture": 100000, "time_capture": 100000,
"UML_time_scaler": 1000 "UML_time_scaler": 1000,
"Closure_signal": "Closing",
"Squeeze_signal": "Squeeze",
"Welding_signal": "Welding",
"Release_signal": "Relief"
} }

Binary file not shown.

View File

@ -9,7 +9,7 @@ from src.gui import PlotWindow, settingsWindow
class app: class app:
def __init__(self): def __init__(self):
self.parser = DiagramParser()
self.request_generator = Request(server_url='http://www.plantuml.com/plantuml/svg/') self.request_generator = Request(server_url='http://www.plantuml.com/plantuml/svg/')
self.operSettings = settingsWindow("params\operator_params.json", 'Operator', self._update_settings) self.operSettings = settingsWindow("params\operator_params.json", 'Operator', self._update_settings)
@ -29,16 +29,18 @@ class app:
self.opt_algorithm = OptAlgorithm(operator_config=self.operator_params, system_config=self.system_params) 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.ideal_times = self._get_ideal_timings(self.opt_algorithm)
self.parser = DiagramParser(system_config=self.system_params)
self.parser.setData("trace_samples/2024_11_08-19_30_49.csv") self.parser.setData("trace_samples/2024_11_08-19_30_52.csv")
self.bool_dict = self.parser.getBoolDict() self.bool_dict = self.parser.getBoolDict()
self.float_dict = self.parser.getFloatDict() self.float_dict = self.parser.getFloatDict()
self.timings_dict = self.parser.getRealTimings()
self.plotter = PlotWindow(operator_config=self.operator_params, self.plotter = PlotWindow(operator_config=self.operator_params,
system_config=self.system_params, system_config=self.system_params,
opt=self.opt_algorithm, opt=self.opt_algorithm,
bool_dict=self.bool_dict, bool_dict=self.bool_dict,
float_dict=self.float_dict, float_dict=self.float_dict,
timings_dict=self.timings_dict,
show_settings_func=self._show_settings) show_settings_func=self._show_settings)
self.uml_creator = UMLCreator(operator_config=self.operator_params, self.uml_creator = UMLCreator(operator_config=self.operator_params,
@ -46,14 +48,16 @@ class app:
request_generator=self.request_generator, request_generator=self.request_generator,
ideal_time=self.ideal_times, ideal_time=self.ideal_times,
bool_dict=self.bool_dict, bool_dict=self.bool_dict,
float_dict=self.float_dict) float_dict=self.float_dict,
timings_dict=self.timings_dict)
self.uml_creator.update_uml(operator_config=self.operator_params, self.uml_creator.update_uml(operator_config=self.operator_params,
system_config=self.system_params, system_config=self.system_params,
request_generator=self.request_generator, request_generator=self.request_generator,
ideal_time=self.ideal_times, ideal_time=self.ideal_times,
bool_dict=self.bool_dict, bool_dict=self.bool_dict,
float_dict=self.float_dict) float_dict=self.float_dict,
timings_dict=self.timings_dict)
def _update_settings(self, _): def _update_settings(self, _):
@ -67,13 +71,15 @@ class app:
request_generator=self.request_generator, request_generator=self.request_generator,
ideal_time=self.ideal_times, ideal_time=self.ideal_times,
bool_dict=self.bool_dict, bool_dict=self.bool_dict,
float_dict=self.float_dict) float_dict=self.float_dict,
timings_dict=self.timings_dict)
self.plotter.update_data(operator_config=self.operator_params, self.plotter.update_data(operator_config=self.operator_params,
system_config=self.system_params, system_config=self.system_params,
opt=self.opt_algorithm, opt=self.opt_algorithm,
bool_dict=self.bool_dict, bool_dict=self.bool_dict,
float_dict=self.float_dict) float_dict=self.float_dict,
timings_dict=self.timings_dict)
def _show_settings(self): def _show_settings(self):
self.operSettings.show() self.operSettings.show()

View File

@ -13,11 +13,14 @@ class PlotWindow:
operator_config: dict, operator_config: dict,
opt: OptAlgorithm, opt: OptAlgorithm,
bool_dict: dict, bool_dict: dict,
float_dict: dict, show_settings_func): float_dict: dict,
timings_dict: dict,
show_settings_func):
pg.setConfigOptions(antialias=True) pg.setConfigOptions(antialias=True)
self.opt = opt self.opt = opt
self.bool_dict = bool_dict self.bool_dict = bool_dict
self.float_dict = float_dict self.float_dict = float_dict
self.timings_dict = timings_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.alpha = 100 #[0-255 прозрачность фона]
@ -32,10 +35,12 @@ class PlotWindow:
operator_config: dict, operator_config: dict,
opt: OptAlgorithm, opt: OptAlgorithm,
bool_dict: dict, bool_dict: dict,
float_dict: dict): float_dict: dict,
timings_dict: dict):
self.opt = opt self.opt = opt
self.bool_dict = bool_dict self.bool_dict = bool_dict
self.float_dict = float_dict self.float_dict = float_dict
self.timings_dict = timings_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._getIdealTimings() self._getIdealTimings()
@ -95,41 +100,54 @@ class PlotWindow:
self.p13.clear() self.p13.clear()
self.l13.clear() self.l13.clear()
self._plotRealData() timings = self._plotRealData()
times = np.arange(20000)/10 #timings = np.arange(20000)/10
self._plotIdealData(times) self._plotIdealData(timings)
def _getIdealTimings(self): def _getIdealTimings(self):
data = self.opt.Ts data = self.opt.Ts
self.idealTime = [data['tclose'], data['tgrow'], self.opt.getMarkOpen(), data["tmovement"]] self.idealTime = [data['tclose'], data['tgrow'], self.opt.getMarkOpen(), data["tmovement"]]
def _form_idealdatGraph(self, times): def _form_idealdatGraph(self, times):
self.idealPhase0 = (self.idealTime[0])*self.scaler #Подъезд closure_start = self.timings_dict["closure"][0]*self.scaler
self.idealPhase1 = (self.idealTime[0]+ self.idealTime[1])*self.scaler #Сжатие compression_start = self.timings_dict["compression"][0]*self.scaler
self.idealPhase2 = (self.idealTime[0]+ self.idealTime[1] + self.WeldTime)*self.scaler #Сварка welding_start = self.timings_dict["welding"][0]*self.scaler
self.idealPhase3 = (self.idealTime[0]+ self.idealTime[1] + self.idealTime[2] + self.WeldTime)*self.scaler #Разъезд opening_start = self.timings_dict["opening"][0]*self.scaler
self.idealPhase4 = (sum(self.idealTime[:4]) + self.WeldTime)*self.scaler #Последнее смыкание #TODO добавить идеальное время вместо 0.25 opening_end = self.timings_dict["opening"][1]*self.scaler
self.x_splitter = np.array([[0, self.idealPhase0],
[self.idealPhase0, self.idealPhase1], self.idealPhase0 = closure_start + (self.idealTime[0])*self.scaler #Подъезд
[self.idealPhase1, self.idealPhase2], self.idealPhase1 = compression_start + (self.idealTime[1])*self.scaler #Сжатие
[self.idealPhase2, self.idealPhase3], self.idealPhase2 = welding_start + (self.WeldTime)*self.scaler #Сварка
[self.idealPhase3, self.idealPhase4]]) self.idealPhase3 = opening_start + (self.idealTime[2])*self.scaler #Разъезд
self.idealPhase4 = opening_end + (self.idealTime[3])*self.scaler #Последнее смыкание
self.x_splitter = np.array([[closure_start, self.idealPhase0],
[compression_start, self.idealPhase1],
[welding_start, self.idealPhase2],
[opening_start, self.idealPhase3],
[opening_end, self.idealPhase4]])
data = [] data = []
for time in times: for time in times:
if time <= self.idealPhase0: if time >= closure_start and time <= self.idealPhase0:
x_fe, x_me, v_fe, v_me, f = self.opt.calcPhaseClose(time/self.scaler) x_fe, x_me, v_fe, v_me, f = self.opt.calcPhaseClose((time-closure_start)/self.scaler)
elif time <= self.idealPhase1: elif time >= compression_start and time <= self.idealPhase1:
x_fe, x_me, v_fe, v_me, f = self.opt.calcPhaseGrow(time/self.scaler-self.idealTime[0]) x_fe, x_me, v_fe, v_me, f = self.opt.calcPhaseGrow((time-compression_start)/self.scaler)
elif time <= self.idealPhase2: elif time >= welding_start and time <= self.idealPhase2:
x_fe, x_me, v_fe, v_me, f = data[-1] x_fe, x_me, v_fe, v_me, f = data[-1]
elif time <= self.idealPhase3: elif time >= opening_start and time <= self.idealPhase3:
x_fe, x_me, v_fe, v_me, f = self.opt.calcPhaseOpen(time/self.scaler-self.idealTime[0]-self.idealTime[1]-self.WeldTime) x_fe, x_me, v_fe, v_me, f = self.opt.calcPhaseOpen((time-opening_start)/self.scaler)
elif time >= opening_end and time <= self.idealPhase4:
x_fe, x_me, v_fe, v_me, f = self.opt.calcPhaseMovement((time-opening_end)/self.scaler)
else: else:
x_fe, x_me, v_fe, v_me, f = self.opt.calcPhaseMovement(time/self.scaler-sum(self.idealTime[:3])-self.WeldTime) if data:
x_fe, x_me, v_fe, v_me, f = data[-1]
else:
x_fe, x_me, v_fe, v_me, f = 0,0,0,0,0
data.append([x_fe, x_me, v_fe, v_me, f]) data.append([x_fe, x_me, v_fe, v_me, f])
data = np.array(data).T data = np.array(data).T
return data return data
def _plotRealData(self): def _plotRealData(self):
for i, (key, dat) in enumerate(self.float_dict.items()): for i, (key, dat) in enumerate(self.float_dict.items()):
dat = np.array(dat).T dat = np.array(dat).T

View File

@ -8,31 +8,30 @@ class UMLCreator:
request_generator: Request, request_generator: Request,
ideal_time: list[float], ideal_time: list[float],
bool_dict: dict, bool_dict: dict,
float_dict: dict): float_dict: dict,
timings_dict: dict):
self._request_generator = request_generator self._request_generator = request_generator
self._ideal_time = ideal_time self._ideal_time = ideal_time
self.bool_dict = bool_dict self.bool_dict = bool_dict
self.float_dict = float_dict self.float_dict = float_dict
self.timings_dict = timings_dict
self.scaler = int(system_config['UML_time_scaler']) self.scaler = int(system_config['UML_time_scaler'])
self.WeldTime = operator_config['time_wielding'] self.WeldTime = operator_config['time_wielding']
def _build_data(self): def _build_data(self):
sig = [
"Closing",
"Relief",
"Squeeze",
"Welding"
]
closure = [self.bool_dict[sig[0]][1][0], self.bool_dict[sig[0]][2][0]]
compression = [self.bool_dict[sig[2]][1][0], self.bool_dict[sig[2]][2][0]]
opening = [self.bool_dict[sig[1]][1][0], self.bool_dict[sig[1]][-1][0]]
closure = self.timings_dict["closure"]
compression = self.timings_dict["compression"]
welding = self.timings_dict["welding"]
opening = self.timings_dict["opening"]
real_data = [ real_data = [
[closure[0]*self.scaler, 'closure #green'], [closure[0]*self.scaler, 'closure #green'],
[closure[1]*self.scaler, '{-}'], [closure[1]*self.scaler, '{-}'],
[compression[0]*self.scaler+0.0001, 'compression #green'], [compression[0]*self.scaler+0.0001, 'compression #green'],
[compression[1]*self.scaler, 'welding #green'], [compression[1]*self.scaler, '{-}'],
[welding[0]*self.scaler+0.0001, 'welding #green'],
[welding[1]*self.scaler, '{-}'],
[opening[0]*self.scaler+0.0001, 'opening #green'], [opening[0]*self.scaler+0.0001, 'opening #green'],
[opening[1]*self.scaler, '{-}'], [opening[1]*self.scaler, '{-}'],
] ]
@ -101,14 +100,17 @@ class UMLCreator:
request_generator: Request, request_generator: Request,
ideal_time: list[float], ideal_time: list[float],
bool_dict: dict, bool_dict: dict,
float_dict: dict): float_dict: dict,
timings_dict: dict):
self._request_generator = request_generator self._request_generator = request_generator
self._ideal_time = ideal_time self._ideal_time = ideal_time
self.bool_dict = bool_dict self.bool_dict = bool_dict
self.float_dict = float_dict self.float_dict = float_dict
self.timings_dict = timings_dict
self.scaler = int(system_config['UML_time_scaler']) self.scaler = int(system_config['UML_time_scaler'])
self.WeldTime = operator_config['time_wielding'] self.WeldTime = operator_config['time_wielding']
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_)

View File

@ -2,28 +2,43 @@ import pandas as pd
import numpy as np import numpy as np
class DiagramParser: class DiagramParser:
def __init__(self): def __init__(self, system_config: dict):
self.data = pd.DataFrame({}) self.data = pd.DataFrame({})
self.signals = [system_config["Closure_signal"],
system_config["Squeeze_signal"],
system_config["Welding_signal"],
system_config["Release_signal"]]
self.boolDict = {}
self.floatDict = {}
self.timingsDict = {}
def setData(self, path): def setData(self, path):
self.data = pd.read_csv(path) self.data = pd.read_csv(path)
def getBoolDict (self):
boolDict = {}
for signalName in self.data.columns: for signalName in self.data.columns:
if type (self.data[signalName].iloc[0]) == np.bool: if type (self.data[signalName].iloc[0]) == np.bool:
boolDict[signalName] = self._getBoolChanges(signalName) self.boolDict[signalName] = self._getBoolChanges(signalName)
return boolDict
def getFloatDict (self):
floatDict = {}
for signalName in self.data.columns: for signalName in self.data.columns:
if type (self.data[signalName].iloc[0]) == np.float64: if type (self.data[signalName].iloc[0]) == np.float64:
floatDict[signalName] = self._getFloatChanges(signalName) self.floatDict[signalName] = self._getFloatChanges(signalName)
return floatDict
self.timingsDict["closure"] = [self.boolDict[self.signals[0]][1][0], self.boolDict[self.signals[0]][2][0]]
self.timingsDict["compression"] = [self.boolDict[self.signals[1]][1][0], self.boolDict[self.signals[1]][2][0]]
self.timingsDict["welding"] = [self.boolDict[self.signals[2]][1][0], self.boolDict[self.signals[2]][2][0]]
self.timingsDict["opening"] = [self.boolDict[self.signals[3]][1][0], self.boolDict[self.signals[3]][-1][0]]
def _getBoolChanges(self, signalName): def getBoolDict (self) -> dict:
return self.boolDict
def getFloatDict (self) -> dict:
return self.floatDict
def getRealTimings(self) -> dict:
return self.timingsDict
def _getBoolChanges(self, signalName) -> list:
timeCode = self.data['time'] timeCode = self.data['time']
signal_values = self.data[signalName] signal_values = self.data[signalName]
changes = [] changes = []
@ -38,7 +53,7 @@ class DiagramParser:
return changes return changes
def _getFloatChanges(self, signalName): def _getFloatChanges(self, signalName) -> list:
timeCode = self.data['time'] timeCode = self.data['time']
signal_values = self.data[signalName] signal_values = self.data[signalName]
changes = [] changes = []