]> git.gag.com Git - fw/quantimotor/commitdiff
generation of a plotly.html file is working on the server
authorBdale Garbee <bdale@gag.com>
Wed, 28 May 2025 03:02:41 +0000 (21:02 -0600)
committerBdale Garbee <bdale@gag.com>
Wed, 28 May 2025 03:02:41 +0000 (21:02 -0600)
ui/app.py

index a4b5fdeb1f1ea80038bba7da154ba8366230743e..447424dd3dab53319d5e52bea93b3dbbd9fb231b 100755 (executable)
--- 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(