From cee262939bb33dc2548c5a8acbddd19a349ac69b Mon Sep 17 00:00:00 2001 From: Andrew Date: Tue, 3 Dec 2024 12:03:52 +0300 Subject: [PATCH] =?UTF-8?q?chore:=20=D0=BB=D0=BE=D0=B3=D0=B8=D0=BA=D0=B0?= =?UTF-8?q?=20=D0=BF=D0=BE=D0=B8=D1=81=D0=BA=D0=B0=20=D0=B8=D0=BD=D1=82?= =?UTF-8?q?=D0=B5=D1=80=D0=B2=D0=B0=D0=BB=D0=BE=D0=B2=20=D0=BF=D0=B5=D1=80?= =?UTF-8?q?=D0=B5=D0=BD=D0=B5=D1=81=D0=B5=D0=BD=D0=B0=20=D0=BD=D0=B0=20?= =?UTF-8?q?=D0=B1=D0=BE=D0=BB=D0=B5=D0=B5=20=D1=8D=D1=84=D1=84=D0=B5=D0=BA?= =?UTF-8?q?=D1=82=D0=B8=D0=B2=D0=BD=D1=83=D1=8E=20=D0=B1=D0=B8=D0=B1=D0=BB?= =?UTF-8?q?=D0=B8=D0=BE=D1=82=D0=B5=D0=BA=D1=83=20intervaltree?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/gui/__pycache__/plotter.cpython-310.pyc | Bin 7770 -> 7787 bytes .../__pycache__/roboter.cpython-310.pyc | Bin 5318 -> 6470 bytes src/performance/performance.py | 25 ++++++- src/performance/roboter.py | 70 +++++++++++------- .../base/__pycache__/base.cpython-310.pyc | Bin 11502 -> 11502 bytes 5 files changed, 67 insertions(+), 28 deletions(-) diff --git a/src/gui/__pycache__/plotter.cpython-310.pyc b/src/gui/__pycache__/plotter.cpython-310.pyc index 8d2e0c64c065c668ea24e11e86d71948da016850..33158def9ef41b1670eca537db0c2047b9fb5b48 100644 GIT binary patch delta 577 zcmZ9JJ8aWX6ozx0*eMV@Ax)i_JcNWQ@hDJ~vOs|aA*e)XJC*QooY+oNY$rOnYSp?E zNNi;|3lakZ421=u&cNC~etv0m zf4x(s3~W#?bACEZM)D(oL?o}I@M0uIvMm`2Be9i^6k*N^qx>~NI+8+}{LCpsiKSo= zr|h2V#`4;-gH9|Duor~%CgU8+i)*x09`Z0oCG{yR(2g1kR<#STI9$@&pxhKA*q~3@ zN#!obTeO!w11?N zJf7-^_*%j)n;C%<5?P~H|a{cM78Q1Xw<9j F{{iocj_&{f delta 571 zcmYL`KTH!*9LM{6?Onz6+EPl}vqf15f5jLuCWJst&_rW_PEb&fYwsNtuSb2hxq!!J z;$#?pn}ZH6GMehZrh^U|B}^tax;nWqG5CHpDK~ubz0dvL_r1IOGaJlmJDPSeB(Gmy zar5}S#$q5a8M`s!E8Agl(`UY7F+HS*_M^Tk&A2q`f8$1d){I~)Hl9)f<~D+eRkQ6t z@wT|&cogG3N!c5Zq#%W(+5s%%k=B%)jL$%+U5i&hy)Oqu5l<3B>N>?mJWEW1fuF;D zIG0R7xxJV?4MPcUr(b}FKhpbGEt>1=f>YY;-li$lBwkY3Mz8<*L`B9!CTud(5~EDq zp`0Rgn!2lA;c&*#JDulSbf3P)H<=-D@Jr?yxOgkuuh32(a6N0N52@@Ce#%}NS(7mc zn~ozMkX#}xNUTLo%evd-bumY(h%9#2n>>TntF60~V4L|1J w!cQz0TCjx2h09|rR6qw769oEHf)S`e>`KsItv1CT&PQ{2ZQvegxHs_kAMfjnTL1t6 diff --git a/src/performance/__pycache__/roboter.cpython-310.pyc b/src/performance/__pycache__/roboter.cpython-310.pyc index 51c2cce662cd7b1f461c84f7bec8e25599881473..69dca3ea2da70ed3e3798adb72a2f800224435b3 100644 GIT binary patch delta 2876 zcmb7GUu+b|8QUC8Jg2@Z?n065(7eU{zykax$e=9>k&u&sF77>uRP1me_?bD%Y$cc~Sn= zI!Lz3udNj_djE=jo)lih-u(y%5MGl1aJKF*lhkDKN{fqw=)?iV7J%|VN*h5Gr}R2s ziNuKf&MCiq2s%Y|K`rTR@OxUI|c#DwEOg4bSUo_daVs!99aCQ-~VHI+B;Inl{A0 zN1n~jbP8m(^m9Mr=S0Ys=i~8OJ!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)4;|;gpCfi*&#^6;JSiz7b#C>^6fj|34(aY!Cnd diff --git a/src/performance/performance.py b/src/performance/performance.py index 091e685..c97271c 100644 --- a/src/performance/performance.py +++ b/src/performance/performance.py @@ -2,6 +2,7 @@ from typing import Optional import os import numpy as np import pandas as pd +from intervaltree import Interval, IntervalTree from roboter import RobotPerformance, TWC_Performance @@ -10,8 +11,25 @@ class PerformanceProcessor: def calc_performance(self, path, df): robot = RobotPerformance() TWC = TWC_Performance() - rob_df = robot.job(path) - TWC_df = TWC.job(df) + point_tree, movement_tree, dialog_tree = robot.job(path) + closing_tree, squeeze_tree, relief_tree = TWC.job(df) + + dialog_inPoint = point_tree & dialog_tree + dialog_inMovement = movement_tree & dialog_tree + + closing_inPoint = point_tree & closing_tree + closing_inMovement = movement_tree & closing_tree + + squeeze_inPoint = point_tree & squeeze_tree + squeeze_inMovement = movement_tree & squeeze_tree + + relief_inPoint = point_tree & relief_tree + relief_inMovement = movement_tree & relief_tree + + + + + @@ -20,4 +38,5 @@ if __name__ == "__main__": robot = RobotPerformance() #TWC = TWC_Performance() result = robot.job(path) - print (result) + print (result[0]) + print (result[1]) diff --git a/src/performance/roboter.py b/src/performance/roboter.py index b9da7be..7d805bc 100644 --- a/src/performance/roboter.py +++ b/src/performance/roboter.py @@ -5,6 +5,8 @@ import os import numpy as np import pandas as pd +from intervaltree import Interval, IntervalTree + class BasePerformanceFactory(ABC): @@ -88,16 +90,35 @@ class BaseProduct(ABC): 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 + return start_idx[0], finish_idx[0] - def operation(self, dataframe: pd.DataFrame) -> pd.DataFrame: - all_idx = np.array([]) - for signal in self._signals: + def _find_events(self, + dataframe: pd.DataFrame, + signals: list[str]) -> Optional[dict[dict[pd.Series]]]: + intervals = {} + end_time = 0 + for signal in 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 + start_series = dataframe.loc[start_idx, "time"].reset_index(drop=True) + end_series = dataframe.loc[finish_idx, "time"].reset_index(drop=True) + end_series.fillna(end_time) + intervals[signal] = {"rise": start_series, + "fall": end_series} + return intervals + + def _form_intervals(self, + start: pd.Series, + end: pd.Series) -> IntervalTree: + if len(start) != len(end): + for i in range(1, len(end)): + if end[i-1] > start[i]: + start = start.drop(i).reset_index(drop=True) + tree = IntervalTree(Interval(start[i], end[i], i) for i in range(len (start))) + return tree + + @abstractmethod + def operation(self): + ... class RobotPerformance(BasePerformanceFactory): @@ -105,33 +126,18 @@ class RobotPerformance(BasePerformanceFactory): def factory_method(self) -> BaseProduct: return RobotDF() - def job(self, path) -> pd.DataFrame: + def job(self, path) -> list[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: + def job(self, TWC_DF: pd.DataFrame) -> list[pd.DataFrame]: product = self.factory_method() result = product.operation(TWC_DF) return result @@ -145,6 +151,13 @@ class RobotDF(BaseProduct): "$OUT3003" ] + def operation(self, dataframe: pd.DataFrame) -> list[IntervalTree]: + events = self._find_events(dataframe, self._signals) + point_tree = self._form_intervals(start=events["$OUT3012"]["rise"], end=events["$OUT3012"]["fall"]) + movement_tree = self._form_intervals(start=events["$OUT3003"]["fall"], end=events["$OUT3012"]["rise"]) + dialog_tree = [] + return point_tree, movement_tree, dialog_tree + class TWC_DF(BaseProduct): def __init__(self): @@ -155,6 +168,13 @@ class TWC_DF(BaseProduct): "Relief" ] + def operation(self, dataframe: pd.DataFrame) -> list[IntervalTree]: + events = self._find_events(dataframe, self._signals) + closing_tree = self._form_intervals(start=events["Closing"]["rise"], end=events["Closing"]["fall"]) + squeeze_tree = self._form_intervals(start=events["Squeeze"]["rise"], end=events["Squeeze"]["fall"]) + relief_tree = self._form_intervals(start=events["Relief"]["rise"], end=events["Relief"]["fall"]) + return closing_tree, squeeze_tree, relief_tree + diff --git a/src/utils/base/__pycache__/base.cpython-310.pyc b/src/utils/base/__pycache__/base.cpython-310.pyc index 7c04d4658327e24e551e7c8710db3a2faed8d7ed..693491064eb82ed6e641ba1530512bc451d72ae7 100644 GIT binary patch delta 22 ccmaDC`7V+-pO=@50SG?s^iBV