This is the code I worked on. I hesitated whether to include this as separate or not...Let's discuss where we want to put something like this or whether we want to cannibalize it for parts.
Because we have not fully decided on #7 , I'm not sure where we are calling this from. I wanted to have something that could read data saved to file and get the info we want to display.
I find a few issues we might want to discuss:
If reading from file (which is convenient, and it's the way it's done here) we will have a significant lag (we are writing to csv every 100 rows, we could write more often too...let's discuss options)
What is the script that runs all other scripts? Should this go into that one or be ran as separate? There's a while loop but it
import pandas as pd
import numpy as np
import os
import datetime
def absolute_file_paths(directory):
path = os.path.abspath(directory)
return [entry.path for entry in os.scandir(path) if entry.is_file()]
def read_data(file_list):
df_list = list()
for filename in file_list:
df_list.append(pd.read_csv(filename))
return df_list
def process_data(df_list):
# this is fake now for debugging
now = datetime.datetime.strptime("2021-03-21 15:03:10", "%Y-%m-%d %H:%M:%S")
# now = datetime.datetime.now()
last_hour = now - datetime.timedelta(hours=1)
#print(df_list)
for df in df_list:
df["datetime"] = pd.to_datetime(df['MM:DD:YYYY hh:mm:ss'])
subset_df = df[(df.datetime >= last_hour) & (df.datetime <= now)]
status = "active" # this should change when we get inputs from jammed devices
# get all the things we want
n_events = len(subset_df.index)
last_pellet_time = subset_df[(df.Event == "Pellet")].datetime.iloc[-1]
pellets_last_hour = len(subset_df[(df.Event == "Pellet")])
session_pellets = subset_df[(df.Event == "Pellet")].tail(1).Pellet_Count.iloc[-1]
out = [n_events, last_pellet_time, pellets_last_hour, session_pellets]
print(out)
#last_pellet =
if __name__ == '__main__':
file_list = absolute_file_paths("data")
all_data = read_data(file_list)
# something like this?
#while True:
# process_data(all_data)
# time.sleep(5)
# some sort of escape key?
process_data(all_data)
This is in line with the minimal info that we would like to display (at least for now).
Once we show this we have to add the FED device number and the status (whether it's active or jammed)
This is the code I worked on. I hesitated whether to include this as separate or not...Let's discuss where we want to put something like this or whether we want to cannibalize it for parts.
Because we have not fully decided on #7 , I'm not sure where we are calling this from. I wanted to have something that could read data saved to file and get the info we want to display.
I find a few issues we might want to discuss:
csv
every 100 rows, we could write more often too...let's discuss options)while
loop but itWith the sample data, this produces
This is in line with the minimal info that we would like to display (at least for now). Once we show this we have to add the FED device number and the status (whether it's active or jammed)