def get_netinfo_from_report(report): """Return a netinfo (dictionary) from a Radio Mobile report struct.""" output = {} units = {} for unit_name, unit in report.units.iteritems(): transform_properties = { "elevation": ("elevation", None), "location_meters": ("location", lambda loc: list(loc)), } units[unit_name] = dict(transform(vars(unit), transform_properties)) output["units"] = units networks = {} for net_name, net in report.nets.iteritems(): short_net_name, smode = bracket_split(net_name) if smode.startswith("wifi"): mode = dict(standard="wifi", wifi_mode=smode) elif smode.startswith("wimax"): sp = smode.split("-") standard = "wimax" scheduler = ("simple" if len(sp) < 2 else sp[1]) mode = dict(standard="wimax", wimax_scheduler=scheduler) nodes, terminals = lib.partition(net.net_members.items(), lambda (name, member): member.role.lower() in ("node", "master")) assert len(nodes) == 1 def _get_info(name, obj): short_system_name, wimax_mode = bracket_split(obj.system) d = dict(name=name, system=short_system_name, wimax_mode=wimax_mode) return dict((k, v) for (k, v) in d.items() if v) network_info = { "mode": mode, "node": _get_info(*nodes[0]), "terminals": [_get_info(*terminal) for terminal in terminals], } networks[short_net_name] = network_info output["networks"] = networks return output
def test_partition(self): lst = range(10) lst_true, lst_false = lib.partition(lst, lambda x: x % 2 == 0) self.assertEqual(lst_true, [0, 2, 4, 6, 8]) self.assertEqual(lst_false, [1, 3, 5, 7, 9])