From dbd5240a1a99928b07b82f77f2c607fb4ccfefb8 Mon Sep 17 00:00:00 2001 From: Rance4396 <2437708352@qq.com> Date: Tue, 17 May 2022 16:50:49 +0800 Subject: [PATCH] =?UTF-8?q?Changes:=E5=A2=9E=E5=8A=A0=E4=BA=86=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E7=94=9F=E6=88=90=E4=BF=AE=E6=94=B9=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E5=8F=98csv=E7=9A=84=E6=A0=BC=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cycle.py | 3 ++- cycle_test_csv.py | 14 +++++++++----- excursion.py | 3 ++- ray_example.py | 18 ++++++++++++++++++ step.py | 3 ++- step_test.py | 17 ++++++++++------- white_noise.py | 3 ++- 7 files changed, 45 insertions(+), 16 deletions(-) create mode 100644 ray_example.py diff --git a/cycle.py b/cycle.py index 32a23f0..188a445 100644 --- a/cycle.py +++ b/cycle.py @@ -1,8 +1,9 @@ from algorithm import algorithm import json import math +import ray - +@ray.remote class cycle(algorithm): def __init__(self): self.config_dict_ = None diff --git a/cycle_test_csv.py b/cycle_test_csv.py index 8f4c6d8..0062b53 100644 --- a/cycle_test_csv.py +++ b/cycle_test_csv.py @@ -1,25 +1,29 @@ import pandas as pd from cycle import cycle +import ray +ray.init() filepath = "D:/python_project_data/1.csv" origin_data = pd.read_csv(filepath) row_len = origin_data.shape[0] cow_len = origin_data.shape[1] disturb_data = origin_data -algorithm_step = cycle() +algorithm_step = cycle.remote() cow_name = "G1.TTXD1_3" contrast_data = pd.DataFrame() contrast_data[cow_name+'_origin'] = origin_data[cow_name] -algorithm_step.set_config('{"CYCLE_AMPLITUDE_BASE": 200 , "CYCLE_TIME_BASE": 5 ,"CYCLE_START_ANGLE_BASE": 3.14}') +algorithm_step.set_config.remote('{"CYCLE_AMPLITUDE_BASE": 200 , "CYCLE_TIME_BASE": 5 ,"CYCLE_START_ANGLE_BASE": 3.14}') # algorithm_step.set_config('{"CYCLE_TIME_BASE": 5 }') for i in range(0,row_len): - disturb_data.loc[i,cow_name]=algorithm_step.eval(origin_data.loc[i,cow_name],i) -print(disturb_data) + futures=algorithm_step.eval.remote(origin_data.loc[i,cow_name],i) + disturb_data.loc[i,cow_name]=ray.get(futures) + +print(disturb_data.loc[:,cow_name]) contrast_data[cow_name+'_disturb'] = disturb_data[cow_name] disturb_data.to_csv("D:/python_project_data/1_disturb.csv", index=False) contrast_data.to_csv("D:/python_project_data/contrast_data.csv", index=False) # 以下均为测试性能用 -print(algorithm_step.config_) \ No newline at end of file +# print(algorithm_step.config_) \ No newline at end of file diff --git a/excursion.py b/excursion.py index 27c81c9..99a3a01 100644 --- a/excursion.py +++ b/excursion.py @@ -1,7 +1,8 @@ from algorithm import algorithm import json +import ray - +@ray.remote class excursion(algorithm): def __init__(self): self.config_dict_ = None diff --git a/ray_example.py b/ray_example.py new file mode 100644 index 0000000..1a34564 --- /dev/null +++ b/ray_example.py @@ -0,0 +1,18 @@ +import ray +ray.init() + +@ray.remote +class Counter(object): + def __init__(self): + self.n = 0 + + def increment(self): + self.n += 1 + + def read(self): + return self.n + +counters = [Counter.remote() for i in range(4)] +[c.increment.remote() for c in counters] +futures = [c.read.remote() for c in counters] +print(ray.get(futures)) diff --git a/step.py b/step.py index fc7e5a8..f1f863c 100644 --- a/step.py +++ b/step.py @@ -1,7 +1,8 @@ from algorithm import algorithm import json +import ray - +@ray.remote class step(algorithm): def __init__(self): self.config_dict_ = None diff --git a/step_test.py b/step_test.py index 9f4900b..25ae4d4 100644 --- a/step_test.py +++ b/step_test.py @@ -1,14 +1,17 @@ import pandas as pd from step import step +import ray +ray.init() -filepath = "D:/python_project/TurbineExhaustTemperatureTheromcouple-FourWorkingCondition.xlsx" -origin_data = pd.read_excel(filepath,sheet_name='s4_ttxd') +filepath = "D:/python_project_data/1.csv" +origin_data = pd.read_csv(filepath) row_len = origin_data.shape[0] cow_len = origin_data.shape[1] disturb_data = origin_data -algorithm_step = step() -cow_name = "ttxd_12_1" -algorithm_step.set_config('{"STEP_AMPLITUDE_BASE": 1.3}') +algorithm_step = step.remote() +cow_name = "G1.TTXD1_3" +algorithm_step.set_config.remote('{"STEP_AMPLITUDE_BASE": 1.3}') for i in range(0,row_len): - disturb_data.loc[i,cow_name]=algorithm_step.eval(origin_data.loc[i,cow_name]) -print(disturb_data) \ No newline at end of file + futures=algorithm_step.eval.remote(origin_data.loc[i,cow_name]) + disturb_data.loc[i, cow_name] = ray.get(futures) +print(disturb_data.loc[:,cow_name]) \ No newline at end of file diff --git a/white_noise.py b/white_noise.py index 0831132..0f6fcfb 100644 --- a/white_noise.py +++ b/white_noise.py @@ -2,8 +2,9 @@ from random import random import numpy as np from algorithm import algorithm import json +import ray - +@ray.remote class white_noise(algorithm): def __init__(self): self.config_dict_ = None