Commit 1c68e143 authored by Tommy Olofsson's avatar Tommy Olofsson
Browse files

Added single trigger mode to the CSV tool and gave it sane defaults.

parent e98e0702
...@@ -56,7 +56,7 @@ def flatten(sample, _type): ...@@ -56,7 +56,7 @@ def flatten(sample, _type):
elif isinstance(_type, labcomm.primitive): elif isinstance(_type, labcomm.primitive):
print "%s," % sample, print "%s," % sample,
else: else:
raise Exception("Unhandled type.") raise Exception("Unhandled type. " + str(type(type_)) + " " + str(type_))
def flatten_labels(_type, prefix=""): def flatten_labels(_type, prefix=""):
...@@ -76,7 +76,7 @@ def flatten_labels(_type, prefix=""): ...@@ -76,7 +76,7 @@ def flatten_labels(_type, prefix=""):
elif isinstance(_type, labcomm.primitive): elif isinstance(_type, labcomm.primitive):
print '"%s",' % prefix, print '"%s",' % prefix,
else: else:
raise Exception("Unhandled type.") raise Exception("Unhandled type. " + str(type(type_)) + " " + str(type_))
def default(type_): def default(type_):
...@@ -98,8 +98,10 @@ def default(type_): ...@@ -98,8 +98,10 @@ def default(type_):
elif (isinstance(type_, labcomm.FLOAT) or elif (isinstance(type_, labcomm.FLOAT) or
isinstance(type_, labcomm.DOUBLE)): isinstance(type_, labcomm.DOUBLE)):
return float('NaN') return float('NaN')
elif isinstance(type_, labcomm.primitive): elif (isinstance(type_, labcomm.BYTE) or
# Must be int type. isinstance(type_, labcomm.SHORT) or
isinstance(type_, labcomm.INTEGER) or
isinstance(type_, labcomm.LONG)):
return 0 return 0
else: else:
raise Exception("Unhandled type. " + str(type(type_)) + " " + str(type_)) raise Exception("Unhandled type. " + str(type(type_)) + " " + str(type_))
...@@ -137,14 +139,18 @@ def main(main_args): ...@@ -137,14 +139,18 @@ def main(main_args):
parser.add_argument('-t', '--timeout', action="store", type=float, parser.add_argument('-t', '--timeout', action="store", type=float,
help="timeout to terminate when no changes are detected. " help="timeout to terminate when no changes are detected. "
"Requires -f.") "Requires -f.")
parser.add_argument('-d', '--default-columns', action="store_true", parser.add_argument('-w', '--no-default-columns', action="store_true",
help="Fill columns for which there has not come any " help="Do not fill columns for which there is no "
"data with default values. Useful for getting output " "data with default values. Wait instead until at least "
"even if not all registered types ara actually encoded.") "one sample has arrived for each registration.")
parser.add_argument('-a', '--trigger-all', action="store_true",
help="Output one line for each sample instead of for "
"each sample of the registration that has arrived with "
"the highest frequency.")
args = parser.parse_args(main_args) args = parser.parse_args(main_args)
seen = {} n_samples = {} # The number of received samples for each sample reg.
current = {} current = {} # The most recent sample for each sample reg.
type_ = {} type_ = {} # The type (declaration) of each sample reg.
file_ = open(args.elc) file_ = open(args.elc)
if args.follow: if args.follow:
reader = FollowingReader(file_, args.interval, args.timeout) reader = FollowingReader(file_, args.interval, args.timeout)
...@@ -155,26 +161,32 @@ def main(main_args): ...@@ -155,26 +161,32 @@ def main(main_args):
try: try:
o, t = d.decode() o, t = d.decode()
if o is None: if o is None:
seen[t.name] = 0 n_samples[t.name] = 0
type_[t.name] = t type_[t.name] = t
else: else:
n_samples[t.name] += 1
current[t.name] = o current[t.name] = o
break break
except EOFError: except EOFError:
break break
dump_labels(type_) dump_labels(type_)
if args.default_columns: if not args.no_default_columns:
defaults(current, type_) defaults(current, type_)
n_rows = 0
while True: while True:
try: try:
o, t = d.decode() o, t = d.decode()
if o is not None: if o is None:
current[t.name] = o continue
if len(current) == len(type_): current[t.name] = o
# TODO: Figure out what to trigger on... n_samples[t.name] += 1
# Assume that samples arrive at different rates. if len(current) < len(type_):
# Trigger on everything once we have a value for continue
# each column. if args.trigger_all:
dump(current, type_)
else:
if n_samples[t.name] > n_rows:
n_rows = n_samples[t.name]
dump(current, type_) dump(current, type_)
except EOFError: except EOFError:
break break
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment