Example #1
0
        logger.log(logging.DEBUG, 'map_parser({})({})'.format(fn,data))
        result =  map(fn, data)
        logger.log(logging.DEBUG, 'result: {}'.format(result))
        return result
    return inner

# 0R5,Th=25.4242C,Vh=12.4242N,Vs=15.4242V
parse_match = re.compile(r'^0R[1-3],(.*)$')
# Th=25.4242C,Vh=12.4242N,Vs=15.4242V
parsers = [split_parser(',')]
# [ 'Th=25.4242C', 'Vh=12.4242N', 'Vs=15.4242V' ]
value_sep = re.compile(r'(?:=|([a-zA-Z/]+))') # split on a single , or = and strings of one or more letters. group the latter.
# [ '', 'Th', '', None, '25.4242', 'C', 
parsers.append(map_parser(split_parser(value_sep)))
# [ [ 'Th', '25.4242', 'C' ], [ 'Vh', '12.4242', 'N' ], [ 'Vs', '15.4242', 'V' ] ]
fields = [ (ig_float(1), metric_getter(0), unit_getter(0,2)) ]
parsers.append(map_parser(field_parser(fields, container=False)))
# [ [measurement], [measurement], [measurement] ]
parsers.append(flatten)
parsers.reverse()

def parser(args, **kwargs):
    return { parse_match: compose(*parsers) }

class WeatherStation(Instrument):
    __name__ = 'weather_station'
    ## let's just use the output of the sensor to determine metrics: one parser to rule them all.
    parsers = parser([]) 

    def start(self):
        pass
Example #2
0
    return inner


# 0R5,Th=25.4242C,Vh=12.4242N,Vs=15.4242V
parse_match = re.compile(r'^0R[1-3],(.*)$')
# Th=25.4242C,Vh=12.4242N,Vs=15.4242V
parsers = [split_parser(',')]
# [ 'Th=25.4242C', 'Vh=12.4242N', 'Vs=15.4242V' ]
value_sep = re.compile(
    r'(?:=|([a-zA-Z/]+))'
)  # split on a single , or = and strings of one or more letters. group the latter.
# [ '', 'Th', '', None, '25.4242', 'C',
parsers.append(map_parser(split_parser(value_sep)))
# [ [ 'Th', '25.4242', 'C' ], [ 'Vh', '12.4242', 'N' ], [ 'Vs', '15.4242', 'V' ] ]
fields = [(ig_float(1), metric_getter(0), unit_getter(0, 2))]
parsers.append(map_parser(field_parser(fields, container=False)))
# [ [measurement], [measurement], [measurement] ]
parsers.append(flatten)
parsers.reverse()


def parser(args, **kwargs):
    return {parse_match: compose(*parsers)}


class WeatherStation(Instrument):
    __name__ = 'weather_station'
    ## let's just use the output of the sensor to determine metrics: one parser to rule them all.
    parsers = parser([])
Example #3
0
#    UnitParser(int, ('time', 'minute'), None),
#    UnitParser(int, ('time', 'second'), None),

# or will each one be passed a grouped item?
# parsing change
start_parsers = []
start_line = r'^[2-9][0-9]{3}\s+[0-9]{2}\s+[0-9]{2}\s+[0-9]{2}\s+[0-9]{2}\s+[0-9]{2}\s+(([0-9\.\-]+\s+){24}[0-9\.\-]+)'
start_re = re.compile(start_line)
#start_parsers.append(split_parser(start_re))
# this will match start line returning everything past the time
# then we split on whitespace
start_parsers.append(split_parser())  # default is to split on whitespace
# we now have a list of numbers

fields = [
    (ig_float(0, stderr=3), ('water', 'downstream velocity'), 'cm/s'),
    (ig_float(1, stderr=4), ('water', 'lateral velocity'), 'cm/s'),
    (ig_float(2, stderr=5), ('water', 'depth'), 'm'),
    (ig_float(6), ('beam', 'signal strength 1'), 'counts'),
    (ig_float(7), ('beam', 'signal strength 2'), 'counts'),
    (ig_float(8), ('beam', 'signal strength 3'), 'counts'),
    #    (float, 'pings', 'good', None),
    #    (stderr_float, 'package', 'heading', None),
    #    (stderr_float, 'package', 'pitch', None),
    #    (stderr_float, 'package', 'roll', None),
    (ig_float(16), ('water', 'temperature'), 'C'),
    #    (stderr_float, 'water', 'pressure', None),
    (ig_float(19), ('battery', 'voltage'), 'V'),
    (ig_float(20), ('beam', 'vertical sample start'), 'm'),
    (ig_float(21), ('beam', 'vertical sample end'), 'm'),
    (ig_float(22), ('beam', 'noise level 1'), 'counts'),
Example #4
0
#    UnitParser(int, ('time', 'minute'), None),
#    UnitParser(int, ('time', 'second'), None),

# or will each one be passed a grouped item?
# parsing change
start_parsers = []
start_line = r"^[2-9][0-9]{3}\s+[0-9]{2}\s+[0-9]{2}\s+[0-9]{2}\s+[0-9]{2}\s+[0-9]{2}\s+(([0-9\.\-]+\s+){24}[0-9\.\-]+)"
start_re = re.compile(start_line)
# start_parsers.append(split_parser(start_re))
# this will match start line returning everything past the time
# then we split on whitespace
start_parsers.append(split_parser())  # default is to split on whitespace
# we now have a list of numbers

fields = [
    (ig_float(0, stderr=3), ("water", "downstream velocity"), "cm/s"),
    (ig_float(1, stderr=4), ("water", "lateral velocity"), "cm/s"),
    (ig_float(2, stderr=5), ("water", "depth"), "m"),
    (ig_float(6), ("beam", "signal strength 1"), "counts"),
    (ig_float(7), ("beam", "signal strength 2"), "counts"),
    (ig_float(8), ("beam", "signal strength 3"), "counts"),
    #    (float, 'pings', 'good', None),
    #    (stderr_float, 'package', 'heading', None),
    #    (stderr_float, 'package', 'pitch', None),
    #    (stderr_float, 'package', 'roll', None),
    (ig_float(16), ("water", "temperature"), "C"),
    #    (stderr_float, 'water', 'pressure', None),
    (ig_float(19), ("battery", "voltage"), "V"),
    (ig_float(20), ("beam", "vertical sample start"), "m"),
    (ig_float(21), ("beam", "vertical sample end"), "m"),
    (ig_float(22), ("beam", "noise level 1"), "counts"),