Add headers to recorded data
This commit is contained in:
parent
3315eed1da
commit
42994a7dd7
|
@ -5,6 +5,7 @@ from datetime import datetime
|
|||
import serial, time, json
|
||||
import serial.tools.list_ports
|
||||
import numpy as np
|
||||
import csv
|
||||
|
||||
# constant settings
|
||||
SENSORS_MAX = 4 # maximum sensor ports
|
||||
|
@ -27,6 +28,13 @@ def read():
|
|||
raise ValueError("Port range is 0-3!")
|
||||
if "- No Device -" in port:
|
||||
# generate random value
|
||||
|
||||
# open the file and add a line of header to it, then close
|
||||
f = open(file_name, "a", newline="", encoding="utf-8")
|
||||
writer = csv.writer(f)
|
||||
header = ['Time', 'Resistance']
|
||||
writer.writerow(header)
|
||||
f.close()
|
||||
while True:
|
||||
dat_list = np.random.randint(0, v_in * 1000, SENSORS_MAX) # create a randomized voltage data
|
||||
# take only the nonzero indices, and truncated to two decimal places to "filter" out some hardware errors
|
||||
|
|
|
@ -5,6 +5,7 @@ import numpy as np
|
|||
import matplotlib
|
||||
import matplotlib.pyplot as plt
|
||||
import decimal
|
||||
from itertools import islice
|
||||
matplotlib.use("WXAgg") # for JetBrains IDE to force use wxPython as backend UI for plotting
|
||||
|
||||
|
||||
|
@ -55,7 +56,7 @@ class SerialPlotter:
|
|||
plt.cla() # clear previous frame
|
||||
# read the last line from the .csv file, the data start from the second column so omit index #0
|
||||
file = open(self.settings["file_name"], "r")
|
||||
ndata = np.array([np.asarray(line.split(", ")[1:], dtype=np.float32) for line in file])
|
||||
ndata = np.array([np.asarray(line.split(", ")[1:], dtype=np.float32) for line in islice(file, 1, None)])#read from the second row of the file ignoring headers
|
||||
if len(ndata) > 0:
|
||||
row = ndata[-1]
|
||||
i = 0
|
||||
|
|
Loading…
Reference in New Issue