From 647f137d33e36b859270778b2054a6c514e8035a Mon Sep 17 00:00:00 2001 From: Andrew Date: Mon, 16 Dec 2024 10:26:13 +0300 Subject: [PATCH] =?UTF-8?q?fix:=20=D0=B7=D0=B0=D0=BC=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D0=BB=20=D0=B1=D0=B8=D0=B1=D0=BB=D0=B8=D0=BE=D1=82=D0=B5=D0=BA?= =?UTF-8?q?=D1=83=20intervaltree=20=D0=BD=D0=B0=20pandas?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- params/operator_params.json | 4 +- params/system_params.json | 2 +- src/performance/performance.py | 29 +++--------- src/performance/roboter.py | 87 ++++++++++++++++++++-------------- 4 files changed, 61 insertions(+), 61 deletions(-) diff --git a/params/operator_params.json b/params/operator_params.json index 3086843..5ed6bea 100644 --- a/params/operator_params.json +++ b/params/operator_params.json @@ -176,7 +176,7 @@ 0.5 ], "object_thickness": [ - 0.0045, + 0.0, 0.0045, 0.0045, 0.0045, @@ -192,7 +192,7 @@ 0.0045 ], "force_target": [ - 4000.0, + 5000.0, 5000.0, 5000.0, 5000.0, diff --git a/params/system_params.json b/params/system_params.json index 1328fb2..1ac1dfc 100644 --- a/params/system_params.json +++ b/params/system_params.json @@ -42,7 +42,7 @@ 1.0 ], "position_start_1": [ - 0.0175 + 0.02 ], "position_start_2": [ 0.081 diff --git a/src/performance/performance.py b/src/performance/performance.py index c97271c..c7bde03 100644 --- a/src/performance/performance.py +++ b/src/performance/performance.py @@ -2,29 +2,17 @@ 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 +from roboter import Performance class PerformanceProcessor: - def calc_performance(self, path, df): - robot = RobotPerformance() - TWC = TWC_Performance() - 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 + def calc_performance(self, path:str, TWC_raw:pd.DataFrame): + factory = Performance() + comm_df, rob_df, TWC_df = factory.job(path, TWC_raw) - relief_inPoint = point_tree & relief_tree - relief_inMovement = movement_tree & relief_tree + + @@ -35,8 +23,3 @@ class PerformanceProcessor: if __name__ == "__main__": path = "D:\downloads\Test2\TeslaTIME29_71_KRCIO.dat" - robot = RobotPerformance() - #TWC = TWC_Performance() - result = robot.job(path) - print (result[0]) - print (result[1]) diff --git a/src/performance/roboter.py b/src/performance/roboter.py index 7d805bc..7119c40 100644 --- a/src/performance/roboter.py +++ b/src/performance/roboter.py @@ -5,7 +5,6 @@ import os import numpy as np import pandas as pd -from intervaltree import Interval, IntervalTree class BasePerformanceFactory(ABC): @@ -108,74 +107,92 @@ class BaseProduct(ABC): def _form_intervals(self, start: pd.Series, - end: pd.Series) -> IntervalTree: + end: pd.Series) -> dict: 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 + intervals = {'start':start.tolist, 'end':end.tolist} + return intervals @abstractmethod def operation(self): ... -class RobotPerformance(BasePerformanceFactory): +class Performance(BasePerformanceFactory): - def factory_method(self) -> BaseProduct: - return RobotDF() + def robot_method(self) -> BaseProduct: + return RobotData() - def job(self, path) -> list[pd.DataFrame]: - product = self.factory_method() + def TWC_method(self) -> BaseProduct: + return TWC_Data() + + def comm_method(self) -> BaseProduct: + return CommData() + + def job(self, path:str, TWC_raw:pd.DataFrame) -> list[pd.DataFrame, list[pd.DataFrame], list[pd.DataFrame]]: + robot = self.robot_method() + TWC = self.TWC_method() + comm=self.comm_method() dataframe = self._get_file_data(path) - rob_df = product.operation(dataframe) - return rob_df - -class TWC_Performance(BasePerformanceFactory): - - def factory_method(self) -> BaseProduct: - return TWC_DF() - - def job(self, TWC_DF: pd.DataFrame) -> list[pd.DataFrame]: - product = self.factory_method() - result = product.operation(TWC_DF) - return result + rob_comm, rob_df = robot.operation(dataframe) + TWC_comm, TWC_df = TWC.operation(TWC_raw) + comm_df = comm.operation(rob_comm, TWC_comm) + return comm_df, rob_df, TWC_df -class RobotDF(BaseProduct): +class RobotData(BaseProduct): def __init__(self): self._signals = [ "$OUT3012", "$IN3003", - "$OUT3003" + "$OUT3003", + "$OUT3244" ] - def operation(self, dataframe: pd.DataFrame) -> list[IntervalTree]: + def operation(self, dataframe: pd.DataFrame) -> list[dict, pd.DataFrame]: 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 + communication_sig = {'sent':events["$OUT3244"]["fall"], 'received':events[""][""]} + point_interval = self._form_intervals(start=events["$OUT3012"]["rise"], end=events["$OUT3012"]["fall"]) + movement_interval = self._form_intervals(start=events["$OUT3244"]["rise"], end=events["$OUT3244"]["fall"]) + return communication_sig, pd.DataFrame({'in_point':point_interval, + 'in_move':movement_interval}) -class TWC_DF(BaseProduct): +class TWC_Data(BaseProduct): def __init__(self): self._signals = [ "Closing", "Squeeze", "Welding", - "Relief" + "Relief", + "Oncoming" ] - def operation(self, dataframe: pd.DataFrame) -> list[IntervalTree]: + def operation(self, dataframe: pd.DataFrame) -> list[dict, pd.DataFrame]: 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 + communication_sig = {'sent':events[""][""], 'received':events[""][""]} #ситара что-то делает -конец сигнала + closing_interval = self._form_intervals(start=events["Closing"]["rise"], end=events["Closing"]["fall"]) + squeeze_interval = self._form_intervals(start=events["Squeeze"]["rise"], end=events["Squeeze"]["fall"]) + relief_interval = self._form_intervals(start=events["Relief"]["rise"], end=events["Relief"]["fall"]) + oncoming_interval = self._form_intervals(start=events["Oncoming"]["rise"], end=events["Oncoming"]["fall"]) + return communication_sig, pd.DataFrame({'in_closing':closing_interval, + 'in_squeeze':squeeze_interval, + 'in_relief':relief_interval, + 'in_oncoming':oncoming_interval}) +class CommData(BaseProduct): + """ + Определяет промежуток, в который происходит взаимодействие между нодами. + Подразумевается следующая структура: node: tuple(list, list) + node[0] - время отправки пакетов. node[1] - время приема пакетов. + """ + def operation(self, node1: dict, node2: dict) -> pd.DataFrame: + n1_to_n2 = self._form_intervals(start=node1['sent'], end=node2['received']) + n2_to_n1 = self._form_intervals(start=node2['sent'], end=node1['received']) + return pd.concat([pd.DataFrame(n1_to_n2), pd.DataFrame(n2_to_n1)])