Esempio n. 1
0
def get_net_links(rows, grid_field, units):
    """Parse a quality grid and return dictionary with information.""" 
    def get_quality(lst):
        s = "".join(lst).strip()
        return (int(s) if s else None)
    def clean_node(node):
        items = dict((k, v) for (k, v) in node.iteritems() if not k.startswith("#"))
        return lib.Struct("Node", **items)
    
    for nrow, row in enumerate(rows[:-1]):
        qualities = map(get_quality, lib.grouper(3, row[grid_field][3:], ''))
        for npeer_row, quality in enumerate(qualities):
            if not quality or nrow >= npeer_row:
                continue
            peer_row = rows[npeer_row]
            node1, node2 = map(clean_node, [row, peer_row])
            location1 = units[node1.net_members].location
            location2 = units[node2.net_members].location
            distance = get_distance_between_locations(location1, location2)
             
            link = {            
                "quality": quality,
                "node1": node1,
                "node2": node2,
                "distance": distance,
            }
            yield link
Esempio n. 2
0
def parse_report(filename):
    """
    Read and parse a Radiomobile report.txt file.
    
    >>> report = parse_report("report.txt")
    >>> report.nets
    >>> report.systems
    >>> report.units
    """
    lines = open(filename).read().splitlines()
    splitted_lines = list(
        lib.split_iter(lines, lambda s: s.startswith("---"), skip_sep=True))
    generated_on = parse_header(splitted_lines[0])
    sections = dict((lib.keyify(key[0]), val)
                    for (key, val) in lib.grouper(2, splitted_lines[1:]))

    units = parse_active_units(sections["active_units_information"])
    report = lib.Struct("RadioMobileReport",
                        generated_on=generated_on,
                        general_information=sections["general_information"],
                        units=units,
                        systems=parse_systems(sections["systems"]),
                        nets=parse_active_nets(
                            sections["active_nets_information"], units))
    return report
Esempio n. 3
0
def get_net_links(rows, grid_field, units):
    """Parse a quality grid and return dictionary with information."""
    def get_quality(lst):
        s = "".join(lst).strip()
        return (int(s) if s else None)

    def clean_node(node):
        items = dict(
            (k, v) for (k, v) in node.iteritems() if not k.startswith("#"))
        return lib.Struct("Node", **items)

    for nrow, row in enumerate(rows[:-1]):
        qualities = map(get_quality, lib.grouper(3, row[grid_field][3:], ''))
        for npeer_row, quality in enumerate(qualities):
            if not quality or nrow >= npeer_row:
                continue
            peer_row = rows[npeer_row]
            node1, node2 = map(clean_node, [row, peer_row])
            location1 = units[node1.net_members].location
            location2 = units[node2.net_members].location
            distance = get_distance_between_locations(location1, location2)

            link = {
                "quality": quality,
                "node1": node1,
                "node2": node2,
                "distance": distance,
            }
            yield link
Esempio n. 4
0
def parse_report(filename):
    """
    Read and parse a Radiomobile report.txt file.
    
    >>> report = parse_report("report.txt")
    >>> report.nets
    >>> report.systems
    >>> report.units
    """
    lines = open(filename).read().splitlines()
    splitted_lines = list(lib.split_iter(lines, 
      lambda s: s.startswith("---"), skip_sep=True))
    generated_on = parse_header(splitted_lines[0])
    sections = dict((lib.keyify(key[0]), val) for (key, val) in 
      lib.grouper(2, splitted_lines[1:]))
    
    units = parse_active_units(sections["active_units_information"])
    report = lib.Struct("RadioMobileReport",
        generated_on=generated_on,
        general_information=sections["general_information"],
        units=units,
        systems=parse_systems(sections["systems"]),
        nets=parse_active_nets(sections["active_nets_information"], units))
    return report
Esempio n. 5
0
 def test_grouper(self):
     s = "abcd1234"
     groups = list(lib.grouper(3, s, 'x'))
     self.assertEqual(groups[0], tuple("abc"))
     self.assertEqual(groups[1], tuple("d12"))
Esempio n. 6
0
 def test_grouper(self):
     s = "abcd1234"
     groups = list(lib.grouper(3, s, "x"))
     self.assertEqual(groups[0], tuple("abc"))
     self.assertEqual(groups[1], tuple("d12"))