chore: без укакзания csv запускается в режиме демонстрации идеальных данных

This commit is contained in:
Andrew 2024-11-12 14:34:07 +03:00
parent 0587ca1a06
commit b6b7de2fcb
8 changed files with 74 additions and 55 deletions

View File

@ -20,6 +20,9 @@ class app:
self.operator_params = read_json("params/operator_params.json")
self.system_params = read_json("params/system_params.json")
self.parser = DiagramParser(system_config=self.system_params)
self.parser.setData("trace_samples/2024_11_08-19_30_52.csv")
self.opt_algorithm = OptAlgorithm(operator_config=self.operator_params, system_config=self.system_params)
generator = Request(server_url='http://www.plantuml.com/plantuml/svg/')
self.operSettings = settingsWindow("params\operator_params.json", 'Operator', self._update_settings)
@ -29,8 +32,7 @@ class app:
self.uml_creator = UMLCreator(request_generator=generator)
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_52.csv")
self.bool_dict = self.parser.getBoolDict()
self.float_dict = self.parser.getFloatDict()
self.timings_dict = self.parser.getRealTimings()

View File

@ -88,8 +88,10 @@ class PlotWindow:
self.p13.clear()
self.l13.clear()
timings = self._plotRealData()
#timings = np.arange(20000)/10
if self.theor_mode:
timings = np.arange(20000)/10
else:
timings = self._plotRealData()
self._plotIdealData(timings)
def _getIdealTimings(self):
@ -97,11 +99,19 @@ class PlotWindow:
self.idealTime = [data['tclose'], data['tgrow'], self.opt.getMarkOpen(), data["tmovement"]]
def _form_idealdatGraph(self, times):
closure_start = self.timings_dict["closure"][0]*self.scaler
compression_start = self.timings_dict["compression"][0]*self.scaler
welding_start = self.timings_dict["welding"][0]*self.scaler
opening_start = self.timings_dict["opening"][0]*self.scaler
opening_end = self.timings_dict["opening"][1]*self.scaler
if self.theor_mode:
closure_start = 0
compression_start = self.idealTime[0]*self.scaler
welding_start = sum(self.idealTime[:2])*self.scaler
opening_start = (sum(self.idealTime[:2])+ self.WeldTime)*self.scaler
opening_end = (sum(self.idealTime[:3])+ self.WeldTime)*self.scaler
else:
closure_start = self.timings_dict["closure"][0]*self.scaler
compression_start = self.timings_dict["compression"][0]*self.scaler
welding_start = self.timings_dict["welding"][0]*self.scaler
opening_start = self.timings_dict["opening"][0]*self.scaler
opening_end = self.timings_dict["opening"][1]*self.scaler
self.idealPhase0 = closure_start + (self.idealTime[0])*self.scaler #Подъезд
self.idealPhase1 = compression_start + (self.idealTime[1])*self.scaler #Сжатие

View File

@ -7,22 +7,36 @@ class UMLCreator:
def _build_data(self):
if not self.theor_mode:
closure = self.timings_dict["closure"]
compression = self.timings_dict["compression"]
welding = self.timings_dict["welding"]
opening = self.timings_dict["opening"]
real_data = [
[closure[0]*self.scaler, 'closure #green'],
[closure[1]*self.scaler, '{-}'],
[compression[0]*self.scaler+0.0001, 'compression #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[1]*self.scaler, '{-}'],
]
closure = self.timings_dict["closure"]
compression = self.timings_dict["compression"]
welding = self.timings_dict["welding"]
opening = self.timings_dict["opening"]
real_data = [
[closure[0]*self.scaler, 'closure #green'],
[closure[1]*self.scaler, '{-}'],
[compression[0]*self.scaler+0.0001, 'compression #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[1]*self.scaler, '{-}'],
ideal_data = [
[closure[0] * self.scaler, 'closure #yellow'],
[(self._ideal_time[0]+closure[0]) * self.scaler, '{-}'],
[compression[0] * self.scaler, 'compression #yellow'],
[(compression[0] + self._ideal_time[1]) * self.scaler, '{-}'],
[welding[0] * self.scaler, 'welding #yellow'],
[(welding[0] + self.WeldTime)*self.scaler, '{-}'],
[opening[0] * self.scaler, 'opening #yellow'],
[(opening[0] + self._ideal_time[2]) * self.scaler, '{-}'],
]
else:
real_data = []
client_data = [
[0.0 * self.scaler, 'closure'],
[0.165 * self.scaler, '{-}'],
@ -46,31 +60,24 @@ class UMLCreator:
]
return real_data, client_data, ideal_data, self.bool_dict
def _get_time(self, signals = '', states = ''):
res = []
for i, sig in enumerate(signals):
if states: state = states[i]
else: state = 'high'
index1 = next ((i for i, _ in enumerate(self.bool_dict[sig]) if _[1]==state), -1)
time = self.bool_dict[sig][index1][0]
res.append(time)
return res
def _generate_svg(self, real_data, client_data, ideal_data, bool_data) -> None:
try:
self._request_generator.clear()
self._request_generator.addLineStyle('biba', 'red', 2)
if not self.theor_mode:
self._request_generator.addLineStyle('biba', 'red', 2)
for i, [signal, changes] in enumerate(bool_data.items()):
name = 'bool_' + str(i)
times = []
for f in changes:
times.append([str(float(f[0])*self.scaler), f[1]])
self._request_generator.addBinary(name, str(signal), 'biba')
self._request_generator.setTimestamps(name, times)
for i, [signal, changes] in enumerate(bool_data.items()):
name = 'bool_' + str(i)
times = []
for f in changes:
times.append([str(float(f[0])*self.scaler), f[1]])
self._request_generator.addBinary(name, str(signal), 'biba')
self._request_generator.setTimestamps(name, times)
self._request_generator.addConcise('RD', 'Real data')
self._request_generator.setTimestamps('RD', real_data)
self._request_generator.addConcise('RD', 'Real data')
self._request_generator.setTimestamps('RD', real_data)
self._request_generator.addConcise('CD', 'Client data')
self._request_generator.setTimestamps('CD', client_data)
self._request_generator.addConcise('ID', 'Ideal data')

View File

@ -17,21 +17,21 @@ class DiagramParser:
def setData(self, path):
if not path:
self.theor_mode = True
else:
self.data = pd.read_csv(path)
self.data = pd.read_csv(path)
for signalName in self.data.columns:
if type (self.data[signalName].iloc[0]) == np.bool:
self.boolDict[signalName] = self._getBoolChanges(signalName)
for signalName in self.data.columns:
if type (self.data[signalName].iloc[0]) == np.bool:
self.boolDict[signalName] = self._getBoolChanges(signalName)
for signalName in self.data.columns:
if type (self.data[signalName].iloc[0]) == np.float64:
self.floatDict[signalName] = self._getFloatChanges(signalName)
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]]
for signalName in self.data.columns:
if type (self.data[signalName].iloc[0]) == np.float64:
self.floatDict[signalName] = self._getFloatChanges(signalName)
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]][2][0]]
def getBoolDict (self) -> dict:
return self.boolDict