From db6f35e4dd20de5b48f49ff38af5b2626df6c024 Mon Sep 17 00:00:00 2001 From: Bdale Garbee Date: Tue, 27 May 2025 21:02:41 -0600 Subject: [PATCH] generation of a plotly.html file is working on the server --- ui/app.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/ui/app.py b/ui/app.py index a4b5fde..447424d 100755 --- a/ui/app.py +++ b/ui/app.py @@ -12,6 +12,8 @@ from gpiod.line import Direction, Value import iio import json import os +import pandas +import plotly.express as px import shutil import shlex import signal @@ -224,6 +226,15 @@ class App: else: return "Method not allowed", 405 + # end point for fetching plotly output + @cherrypy.expose + def plotly(self): + global test_path + if cherrypy.request.method == 'GET': + plotly_path = test_path + "/plotly.html" + with open(plotly_path, 'r') as plot_file: + return plot_file.read() + # end point for arming the system @cherrypy.expose @cherrypy.tools.json_in() @@ -241,6 +252,7 @@ class App: @cherrypy.expose def starttest(self): global test_path + global test_time if cherrypy.request.method == 'GET': # create a directory name for this test t = time.localtime() @@ -333,6 +345,7 @@ def endatest(): global loggertask global pyrotask global test_path + global test_time cherrypy.log("setting shutdown_flag for each thread") # stop logging data by telling the thread to exit @@ -349,6 +362,7 @@ def endatest(): status = "idle" # post-process the data we just collected + # first, let's create a CSV file from the raw data rawfile_path = test_path + "/rawdata" csvfile_path = test_path + "/data.csv" with open(rawfile_path, 'rb') as rawfile: @@ -370,6 +384,15 @@ def endatest(): value7 = '%.3f'%((float(rawdata[i+15] * 256 + rawdata[i+14]) + float(OFFSET)) * float(SCALE) / 1000) csvwriter.writerow([value0, value1, value2, value3, value4, value5, value6, value7]) + # next, let's create a plotly html object from the csv file + df = pandas.read_csv(csvfile_path) + plot_title = "Results of test " + test_time + fig = px.line(df, title=plot_title) + html_data = fig.to_html(full_html=False) + plotfile_path = test_path + "/plotly.html" + with open(plotfile_path, 'w') as plotfile: + plotfile.write(html_data) + if __name__ == '__main__': # initialize hardware set_line_values( -- 2.47.2