Exemple #1
0
def parser(args, **kwargs):
    token_sep = re.compile('(?:([{}])\s*|\s+)'.format(''.join(decorations.keys())))
    parsers = [ split_parser(token_sep, compact=False) ]
    fields = list(starmap(parser_from_header, enumerate(args.header))) # starmap(fn, iterable) ~ [ fn(*args) for args in iterable ]
    parsers.append(field_parser(fields))
    parsers.append(lambda m: filter(lambda n: n.unit, m)) # get rid of mesaurements without unit set, in this case, the time field
    parsers.reverse()

    return compose(*parsers)
        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
        
Exemple #3
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([])

    def start(self):
Exemple #4
0
    (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'),
    (ig_float(23), ('beam', 'noise level 2'), 'counts'),
    (ig_float(24), ('beam', 'noise level 3'), 'counts'),
]

start_parsers.append(field_parser(fields))

# Cell parsing
# an integer, followed by 4 floating points, followed by 2 integers
cell_re = re.compile(
    r'^\s?([1-9][0-9]?\s+(?:-?[0-9]+(?:\.[0-9]+)?\s+){4}[1-9][0-9]{0,2}\s+[1-9][0-9]{0,2})\s*$'
)

# split by whitespace
cell_parsers = [split_parser()]


def cell_offset(idx):
    return lambda data: ('cell', data[idx])

Exemple #5
0
    (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"),
    (ig_float(23), ("beam", "noise level 2"), "counts"),
    (ig_float(24), ("beam", "noise level 3"), "counts"),
]

start_parsers.append(field_parser(fields))

# Cell parsing
# an integer, followed by 4 floating points, followed by 2 integers
cell_re = re.compile(r"^\s?([1-9][0-9]?\s+(?:-?[0-9]+(?:\.[0-9]+)?\s+){4}[1-9][0-9]{0,2}\s+[1-9][0-9]{0,2})\s*$")

# split by whitespace
cell_parsers = [split_parser()]


def cell_offset(idx):
    return lambda data: ("cell", data[idx])


co = cell_offset(0)