From 10e7cf2a37ea0843aa2669c149a251c9f0611ff3 Mon Sep 17 00:00:00 2001 From: Andrew Date: Mon, 2 Dec 2024 18:41:02 +0300 Subject: [PATCH] =?UTF-8?q?dev:=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=20=D0=BF=D0=B0=D1=80=D1=81=D0=B5=D1=80=20r64=20?= =?UTF-8?q?=D1=84=D0=B0=D0=B9=D0=BB=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../__pycache__/roboter.cpython-310.pyc | Bin 0 -> 5318 bytes src/performance/performance.py | 23 +++ src/performance/roboter.py | 166 ++++++++++++++++++ src/utils/base/base.py | 4 +- 4 files changed, 192 insertions(+), 1 deletion(-) create mode 100644 src/performance/__pycache__/roboter.cpython-310.pyc create mode 100644 src/performance/performance.py create mode 100644 src/performance/roboter.py diff --git a/src/performance/__pycache__/roboter.cpython-310.pyc b/src/performance/__pycache__/roboter.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..51c2cce662cd7b1f461c84f7bec8e25599881473 GIT binary patch literal 5318 zcmb7I-ESMm5x?8pJ03qp%ZhBJsUzp3DFN4!HT8ydn8X4~kPo@r8>wOPmVtPc0M=B>8faXd%2 zc{}IjAj8|Pm)E}quXx)Kws0OB!U?S%%PWD;2^YMp`7-#tD1a}7C5%_V7exttN%Irn z%c26l5|%Mu1wSFG;H#QHBlxmWJM)zEubHYCbi2JINTOaht}$g@yM9Aeg4H;YK_lse z$y!f9%DvksiJ)C?(7f@F1!j@<{s9`H;hDnlSZE1Tu*b%Z>2YBR{@CzrF{SsxJx9DG zN}~LjWAD@AjF?2r6=$KJfh{I1p+3d+q&~1dbphZt^H_WjmsZGxf{CrQQ7sj&j z#H>F7Q9KUYO_@ipCi{!x*DFg=;LETduLKJ#pNDM`bz95*UNW}KN-P^I{pZWB$lhu% z3FYPfwyHEU9sJB1M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?6PTN}gvmOD^Iql+>C{Wq-96$`B!;OP2c>(BbSA5a=xw9wd`TTP8R_9sxPn ze!NEQF&FDXu#8frD_|ZGJ__T{@TQnbiHb$_3W9g$h?T}=kCY%(0n(#gB+;PlwrHy? zHP)%*n9-XyQR$%`MD>S_qt@d?89v0fu4MURB)_UCkRJ=Ok#B+cZn<$pn#XQO+K?}VsCBSB{#`L4BRAZ&SdA=#Wvalg$p~THGfpR^2=b@4rZb)6ZLF6Q-bujRV1}Rh|aWA-wAhJjpqsr?LzxtmO zpcfm%K4{Vl;G~H+Xd;DT3wQRvAYW$(ZH?7y*1&z^?q~O}%*`(ha<CzcM#>Wz;oy zMN)P-5xbO~9^=v2t(b!>Uo71^Jay|&`0>cq8SSL~lj1w{GIFAeYelvdFh@Qk8^|8I zv0t+Bsr!|E62cDg-_ebBFUCJPUT%4FD+~vrmpk}x$8+w5?I>*i_&&eEo8%_QK!ad> zlakKG6Mag`{h0=1BE;1usfKHA;g1)p+Gsb*3RWA^A_>~Ma!_VNQE5}pIqI=-^XqTR zMLpUNx+2IbZC$46RIlN!gGO6TFLjbe%DtM^j~`IJjwzp&j4H}py1k*qwW@cj)73N8 H;#B^>YSDC4 literal 0 HcmV?d00001 diff --git a/src/performance/performance.py b/src/performance/performance.py new file mode 100644 index 0000000..091e685 --- /dev/null +++ b/src/performance/performance.py @@ -0,0 +1,23 @@ +from typing import Optional +import os +import numpy as np +import pandas as pd + +from roboter import RobotPerformance, TWC_Performance + +class PerformanceProcessor: + + def calc_performance(self, path, df): + robot = RobotPerformance() + TWC = TWC_Performance() + rob_df = robot.job(path) + TWC_df = TWC.job(df) + + + +if __name__ == "__main__": + path = "D:\downloads\Test2\TeslaTIME29_71_KRCIO.dat" + robot = RobotPerformance() + #TWC = TWC_Performance() + result = robot.job(path) + print (result) diff --git a/src/performance/roboter.py b/src/performance/roboter.py new file mode 100644 index 0000000..b9da7be --- /dev/null +++ b/src/performance/roboter.py @@ -0,0 +1,166 @@ +from __future__ import annotations +from abc import ABC, abstractmethod +from typing import Optional +import os +import numpy as np +import pandas as pd + + +class BasePerformanceFactory(ABC): + + @abstractmethod + def factory_method(self): + ... + + def job(self): + ... + + def _get_file_data(self, path) -> pd.DataFrame: + head, file = self._dat_parser(path) + self.dat_name = file[:-4] + path_r64 = os.path.dirname(path) + '\\' + file + time_axis, dataframe = self._r64_parser(path_r64, head) + dataframe = pd.concat([dataframe, time_axis], axis=1) + return dataframe + + def _dat_parser(self, path: str) -> list[dict, str]: + with open(path, 'r') as file: + head = {'channels': 0} + inside_channel = False + channels = 0 + for line in file: + line = line.strip() + if line == '#BEGINCHANNELHEADER' or line == "#BEGINGLOBALHEADER": + inside_channel = True + + elif line == '#ENDCHANNELHEADER' or line == "#ENDGLOBALHEADER": + inside_channel = False + pass + # Формирование словаря + elif inside_channel: + _, data = line.split(',') + match _: + case '102': + head['rob_id'] = data + case '200': + ch_name = data + if ch_name != 'Zeit': channels +=1 + head[ch_name] = {} + case '202': + head[ch_name]['unit'] = data + case '211': + file = data + case '220': + head[ch_name]['len'] = int(data) + case '221': + head[ch_name]['num'] = int(data) + case '241': + head[ch_name]['multiplyer'] = float(data) + head['channels'] = int(channels) + return head, file + + def _r64_parser(self, path: str, head: dict) -> Optional[list[pd.Series, pd.DataFrame]]: + ch = head['channels'] + keys = list(head.keys())[-ch:] + len_timestamps = head['Zeit']['len'] + t_step = head['Zeit']['multiplyer'] + time_axis = pd.Series(np.arange(0, len_timestamps*t_step, t_step)) + time_axis.name = 'time' + dataframe = pd.DataFrame({}) + with open(path, 'rb') as file: + data = file.read() + floats = np.frombuffer(data, dtype=' list[list[float], list[float]]: + stage_diff = np.diff(dataframe[signal]) + start_idx = np.where(stage_diff == 1) + finish_idx = np.where(stage_diff == -1) + return start_idx, finish_idx + + def operation(self, dataframe: pd.DataFrame) -> pd.DataFrame: + all_idx = np.array([]) + for signal in self._signals: + start_idx, finish_idx = np.array(self._find_indexes(signal, dataframe)) + all_idx = np.hstack([all_idx, start_idx[0], finish_idx[0]]) + all_idx = np.sort(np.array(all_idx, dtype="int64")) + result = dataframe.loc[all_idx, self._signals + ["time"]] + return result + + +class RobotPerformance(BasePerformanceFactory): + + def factory_method(self) -> BaseProduct: + return RobotDF() + + def job(self, path) -> pd.DataFrame: + product = self.factory_method() + dataframe = self._get_file_data(path) + rob_df = product.operation(dataframe) + in_point, in_moving, in_dialog = False, False, False + for index, row in rob_df.iterrows(): + if row["$OUT3012"] == 1: + if not in_point: + in_point = True + start_point = row["time"] + else: + in_point = False + time_in_point = row["time"] - start_point + + + + + return rob_df + + + +class TWC_Performance(BasePerformanceFactory): + + def factory_method(self) -> BaseProduct: + return TWC_DF() + + def job(self, TWC_DF: pd.DataFrame) -> pd.DataFrame: + product = self.factory_method() + result = product.operation(TWC_DF) + return result + + +class RobotDF(BaseProduct): + def __init__(self): + self._signals = [ + "$OUT3012", + "$IN3003", + "$OUT3003" + ] + + +class TWC_DF(BaseProduct): + def __init__(self): + self._signals = [ + "Closing", + "Squeeze", + "Welding", + "Relief" + ] + + + + + + + + + + diff --git a/src/utils/base/base.py b/src/utils/base/base.py index ee0fd86..53d353e 100644 --- a/src/utils/base/base.py +++ b/src/utils/base/base.py @@ -335,4 +335,6 @@ class BaseMainWindow(QWidget): font-weight: bold; font-family: "Segoe UI", sans-serif; } - """) \ No newline at end of file + """) + + \ No newline at end of file