kopia lustrzana https://github.com/jbruce12000/kiln-controller
add stdout option
rodzic
d0cc3ebc53
commit
2dfb4ed61e
|
@ -5,6 +5,7 @@ import json
|
||||||
import time
|
import time
|
||||||
import csv
|
import csv
|
||||||
import argparse
|
import argparse
|
||||||
|
import sys
|
||||||
|
|
||||||
|
|
||||||
STD_HEADER = [
|
STD_HEADER = [
|
||||||
|
@ -37,7 +38,7 @@ PID_HEADER = [
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
def logger(hostname, csvfile, noprofilestats, pidstats):
|
def logger(hostname, csvfile, noprofilestats, pidstats, stdout):
|
||||||
status_ws = websocket.WebSocket()
|
status_ws = websocket.WebSocket()
|
||||||
|
|
||||||
csv_fields = []
|
csv_fields = []
|
||||||
|
@ -50,6 +51,12 @@ def logger(hostname, csvfile, noprofilestats, pidstats):
|
||||||
csv_out = csv.DictWriter(out, csv_fields, extrasaction='ignore')
|
csv_out = csv.DictWriter(out, csv_fields, extrasaction='ignore')
|
||||||
csv_out.writeheader()
|
csv_out.writeheader()
|
||||||
|
|
||||||
|
if stdout:
|
||||||
|
csv_stdout = csv.DictWriter(sys.stdout, csv_fields, extrasaction='ignore', delimiter='\t')
|
||||||
|
csv_stdout.writeheader()
|
||||||
|
else:
|
||||||
|
csv_stdout = None
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
msg = json.loads(status_ws.recv())
|
msg = json.loads(status_ws.recv())
|
||||||
|
@ -74,6 +81,14 @@ def logger(hostname, csvfile, noprofilestats, pidstats):
|
||||||
csv_out.writerow(msg)
|
csv_out.writerow(msg)
|
||||||
out.flush()
|
out.flush()
|
||||||
|
|
||||||
|
if stdout:
|
||||||
|
for k in list(msg.keys()):
|
||||||
|
v = msg[k]
|
||||||
|
if isinstance(v, float):
|
||||||
|
msg[k] = round(v, 3)
|
||||||
|
csv_stdout.writerow(msg)
|
||||||
|
sys.stdout.flush()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
parser = argparse.ArgumentParser(description='Log kiln data for analysis.')
|
parser = argparse.ArgumentParser(description='Log kiln data for analysis.')
|
||||||
|
@ -81,6 +96,7 @@ if __name__ == "__main__":
|
||||||
parser.add_argument('--csvfile', type=str, default="/tmp/kilnstats.csv", help="Where to write the kiln stats to")
|
parser.add_argument('--csvfile', type=str, default="/tmp/kilnstats.csv", help="Where to write the kiln stats to")
|
||||||
parser.add_argument('--pidstats', action='store_true', help="Include PID stats")
|
parser.add_argument('--pidstats', action='store_true', help="Include PID stats")
|
||||||
parser.add_argument('--noprofilestats', action='store_true', help="Do not store profile stats (default is to store them)")
|
parser.add_argument('--noprofilestats', action='store_true', help="Do not store profile stats (default is to store them)")
|
||||||
|
parser.add_argument('--stdout', action='store_true', help="Also print to stdout")
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
logger(args.hostname, args.csvfile, args.noprofilestats, args.pidstats)
|
logger(args.hostname, args.csvfile, args.noprofilestats, args.pidstats, args.stdout)
|
||||||
|
|
Ładowanie…
Reference in New Issue