From d5324377fdaf045af414806705aab514d0cdb43d Mon Sep 17 00:00:00 2001 From: Max Nuding Date: Sun, 16 Jan 2022 09:29:43 +0100 Subject: [PATCH] automatically cleans up data before generating the graph --- .nova/Publishing/Phlaym.json | 3 +++ .nova/Tasks/Graph.json | 2 +- graph.py | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/.nova/Publishing/Phlaym.json b/.nova/Publishing/Phlaym.json index 7418bb8..abdfd91 100644 --- a/.nova/Publishing/Phlaym.json +++ b/.nova/Publishing/Phlaym.json @@ -1,5 +1,8 @@ { "identifier" : "65C0B698-D114-41B3-8F58-13D74F7D3E93", + "ignoredFilePatterns" : [ + "data.csv" + ], "remotePath" : "\/home\/phlaym\/jwst-plotter", "server" : "Phlaym", "usesPublishing" : true diff --git a/.nova/Tasks/Graph.json b/.nova/Tasks/Graph.json index 7be60c2..1350c34 100644 --- a/.nova/Tasks/Graph.json +++ b/.nova/Tasks/Graph.json @@ -6,5 +6,5 @@ } }, "identifier" : "EADBCF2F-F2FC-418C-9C08-EBAE9F98C8BD", - "openLogOnRun" : "fail" + "openLogOnRun" : "start" } diff --git a/graph.py b/graph.py index 2cf43cd..c94bfb9 100755 --- a/graph.py +++ b/graph.py @@ -13,8 +13,41 @@ FILTER_DEPLOYMENTS = True plt.rcParams["figure.autolayout"] = True plt.rcParams['figure.figsize'] = (16, 10) + data_frame = pd.read_csv("data.csv", delimiter=';') +# Filter rows, so that only the following will be kept: +# First and last rows, +# rows which have a different temperature than the one before, +# and rows which have a different temperature than the one after. +# +# Basically: If the temperatures don't change for a few rows, keep only the first +# and last of that run +last_row = None +timestamps_to_keep = [] +for row in data_frame.iterrows(): + # row is actually a tuple with index at 0 and the row data at 1. We care only about the row data + row = row[1] + # First row: Always keep it + if last_row is None: + last_row = row + timestamps_to_keep.append(row['timestamp']) + continue + # Any temp changed? + keep_row = (last_row['tempWarmSide1C'] != row['tempWarmSide1C'] or + last_row['tempWarmSide2C'] != row['tempWarmSide2C'] or + last_row['tempCoolSide1C'] != row['tempCoolSide1C'] or + last_row['tempCoolSide2C'] != row['tempCoolSide2C']) + # Keep this and the previous row + if keep_row: + timestamps_to_keep.append(last_row['timestamp']) + timestamps_to_keep.append(row['timestamp']) + last_row = row +# Always keep the last row +timestamps_to_keep.append(data_frame.iloc[-1:]['timestamp']) +# Filter rows by the timestamps we just saved +data_frame = data_frame[data_frame.timestamp.isin(timestamps_to_keep)] + # Subplot, to move legend next to plot # 1 row, 1 col, index: 1 plt.subplot(1, 1, 1)