Skip to content

Commit 84fa10e

Browse files
temp_graph.py: added a --filter option
Use the --filter option to filter for a device name. Any device name containing the filtered string will remain. All other devices will be hidden. If this would hide an entire chart, that chart is removed entirely. Considerations: if more filters are desired, it may be easiest to instead rework the html report to include some scripted filter options. Signed-off-by: Liam Reynolds <liam.reynolds@candelatech.com>
1 parent 60cc256 commit 84fa10e

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

py-scripts/temp_graph.py

100644100755
Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ def main():
9696
default=False, action="store_true")
9797
parser.add_argument("-c", "--cutoff", default=20,
9898
help="max time in minutes between two table entries")
99+
parser.add_argument("-f", "--filter", default=None,
100+
help="only graph from sensors with names containing the filtered string")
99101
parser.add_argument("--help_summary", default=False, action="store_true")
100102

101103
args = parser.parse_args()
@@ -173,12 +175,20 @@ def main():
173175

174176
date_format = mdates.DateFormatter('%H:%M')
175177

178+
skip_tables = []
179+
176180
for file_num in range(len(out_tables)):
177181
file = out_tables[file_num]
178182
df = pd.read_csv(file.name)
183+
if args.filter:
184+
df = df[df['device'].str.contains(args.filter, case=False)]
185+
if (df.empty):
186+
print("A chart was hidden because it did not contain the filtered string")
187+
skip_tables.append(file_num)
188+
continue
179189
df['datetime'] = pd.to_datetime(df['datetime'],
180190
format="%Y-%m-%d %H:%M:%S")
181-
_, ax = plt.subplots()
191+
_, ax = plt.subplots(layout='constrained')
182192
min_temps = df.groupby('datetime')['temperature'].min()
183193
max_temps = df.groupby('datetime')['temperature'].max()
184194
mean_temps = df.groupby('datetime')['temperature'].mean()
@@ -216,6 +226,8 @@ def main():
216226
with open(_out_dir + _tstamp + '/report' + '.html', 'w') as f:
217227
f.write("<!DOCTYPE HTML> \n <html> \n <b>")
218228
for file_num in range(len(out_tables)):
229+
if file_num in skip_tables:
230+
continue
219231
f.write('<img src=\"' +
220232
_next_png_name(file_num) +
221233
'\" alt=\"graph 1\">')

0 commit comments

Comments
 (0)