def test_rand_member(self): rand_guy = self.calc.rand_member() self.assertIsNotNone(rand_guy) self.assertIn(str(rand_guy), self.calc) empty_set = Group("Empty", exec_key=self.exec_key) rand_guy = empty_set.rand_member() self.assertIsNone(rand_guy)
def group_edit(request, cn): attrs = ['cn', 'description', 'gidNumber', 'memberUid','owner'] group = Group.get_by_cn(cn, attrs) kwargs = {} memberuid = [] # fuellt formular mit vorhanden daten aus LDAP #form = GroupForm() for key in attrs: kwargs[key] = getattr(group,key) if key == 'memberUid': for member in kwargs[key]: # haengt mitglieder der gruppe an liste an #memberuid.append((member, member)) memberuid.append(member) else: pass form = GroupForm(initial=kwargs) #form.fields['memberUid'].initial = ['leumer', 'mmuench', 'schmidt'] form_msg = '' old = {} new = {} wert = ['Hallo', 'ich', 'bin', 'Paul'] typ = type(wert) if request.method == 'POST': form = GroupForm(request.POST) if form.is_valid(): for key, value in request.POST.items(): if str(key) in attrs: if str(key) == 'memberUid': #if type(form[str(key)].value) == type(list()): new[str(key)] = [string.encode('utf-8') for string in form.cleaned_data.get(str(key))] else: new[str(key)] = form.cleaned_data.get(str(key)).encode('utf-8') old[str(key)] = getattr(group, str(key)) if old[str(key)] != new[str(key)]: Group.write_ldif(cn, old, new) form_msg = 'Formular gueltig.' else: form_msg = 'Es wurde nichts geaendert!' else: pass #errorhandling else: form_msg = 'Formular NICHT gueltig!' #form = GroupForm() context = { 'form' : form, 'form_msg' : form_msg, 'cn' : cn, 'new' : new, 'old' : old, 'memberuid' : memberuid, 'typ' : typ, } return render(request, 'iapp_group/edit.html', context )
def get_x_hood(self, agent, width=1, pred=None, include_self=False, save_neighbors=False): """ Takes in an agent and returns a Group of its x neighbors. For example, if the agent is located at (0, 0), get_x_hood would return (-1, 0) and (1, 0). """ if agent is not None: x_hood = Group("x neighbors") agent_x, agent_y, neighbor_x_coords \ = fill_neighbor_coords(agent, width, include_self) for i in neighbor_x_coords: neighbor_x = agent_x + i if not out_of_bounds(neighbor_x, agent_y, 0, 0, self.width, self.height): x_hood += self.get_agent_at(neighbor_x, agent_y) if save_neighbors: agent.neighbors = x_hood return x_hood
def get_y_hood(self, agent, height=1, pred=None, include_self=False, save_neighbors=False): """ Takes in an agent and returns a Group of its y neighbors. For example, if the agent is located at (0, 0), get_y_hood would return agents at (0, 2) and (0, 1). """ y_hood = Group("y neighbors") agent_x, agent_y, neighbor_y_coords \ = fill_neighbor_coords(agent, height, include_self) for i in neighbor_y_coords: neighbor_y = agent_y + i if not out_of_bounds(agent_x, neighbor_y, 0, 0, self.width, self.height): y_hood += (self.get_agent_at(agent_x, neighbor_y)) if save_neighbors: agent.neighbors = y_hood return y_hood
def mission(required_physical, required_mental, required_tactical): for members in combinations(Member.members, 4): (Group(members, base_physical, base_mental, base_tactical).calculate_missing(required_physical, required_mental, required_tactical)) Group.sort_groups() print("Stat: | PHY | MEN | TAC | Members") print("----------|-----|-----|-----|--------") print(" | ".join(("required:", str(required_physical), str(required_mental), str(required_tactical))) + " |") print("----------|-----|-----|-----|--------") for group in Group.groups[:10]: print(" | ".join((" " * 9, str(group.physical), str(group.mental), str(group.tactical), str(group))))
def __json_to_object(self, serial_obj, exec_key): """ Takes a serial JSON object back into a live Python object. """ restored_obj = dict() restored_groups = [] model_deserialized = False for obj_name in serial_obj: should_restore_object = isinstance(serial_obj[obj_name], dict) and "type" in serial_obj[ obj_name] if should_restore_object: if serial_obj[obj_name]["type"] == "TestUser": restored_obj[obj_name] = TermUser(name=obj_name, serial_obj=serial_obj[ obj_name], exec_key=exec_key) if serial_obj[obj_name]["type"] == "APIUser": restored_obj[obj_name] = APIUser(name=obj_name, serial_obj=serial_obj[ obj_name], exec_key=exec_key) if serial_obj[obj_name]["type"] == "Agent": restored_obj[obj_name] = Agent(name=obj_name, serial_obj=serial_obj[ obj_name], exec_key=exec_key) elif serial_obj[obj_name]["type"] == "Model": from lib.model import Model print(f'restoring model for key {exec_key}') restored_obj[obj_name] = Model(exec_key=exec_key, serial_obj=serial_obj[ obj_name]) model_deserialized = True elif serial_obj[obj_name]["type"] == "Group": from lib.group import Group restored_obj[obj_name] = Group(exec_key=exec_key, serial_obj=serial_obj[ obj_name], name=serial_obj[obj_name][ 'name']) restored_groups.append(restored_obj[obj_name]) elif serial_obj[obj_name]["type"] == "Env": restored_obj[obj_name] = Env(exec_key=exec_key, serial_obj=serial_obj[ obj_name], name=serial_obj[obj_name][ 'name']) else: restored_obj[obj_name] = serial_obj[obj_name] self.registries[exec_key][obj_name] = restored_obj[obj_name] if model_deserialized: restored_obj['model'].groups = restored_groups restored_obj['model'].env = restored_obj['env'] self.registries[exec_key]['model'] = restored_obj['model'] return restored_obj
def get_moore_hood(self, agent, pred=None, save_neighbors=False, include_self=False, hood_size=1): """ Takes in an agent and returns a Group of its Moore neighbors. Should call the region_factory! """ region = region_factory(space=self, center=(agent.get_x(), agent.get_y()), size=hood_size, agents_move=not save_neighbors) members = region.get_agents(exclude_self=not include_self, pred=pred) return Group("Moore neighbors", members=members)
def __call__(self, args): self._args = args try: with open(self._args.config_file) as f: self._settings = yaml.load(f, yaml.SafeLoader) except Exception as e: self._parser.error( "Failed in loading the settings.yml file:{}".format(e)) self._logger = Logger(self._settings["logs_locations"]) self._database = Database(self._settings, self._parser, self._logger) self._user = User(self._settings["okta_token"], self._settings["okta_organization_url"]) self._group = Group(self._settings["okta_token"], self._settings["okta_organization_url"]) self._change_policy = ChangePolicy(self._settings, self._user, self._group) self._run_risk_score_monitor()
def _populate_from_json(self): """Ugly mash up to force the Github JSON data to the class structure""" self._log.info("Setting teams") data_dict = read_json_to_attrdict(self.data_file) for team_data in data_dict.teams: team = Team() team.init_from_json(team_data) self.teams[team.id] = team self._log.info("Setting groups") for group_id in data_dict.groups: group_data = AttrDict(data_dict.groups[group_id]) group = Group() group.init_from_json(group_data, self._settings.naming.group_prefix) for game_data in group_data.matches: game = GroupGame() game.init_from_json(game_data, self.teams) game.set_group(group) self.games[game.id] = game # maybe redundant group.add_game(game) group.add_teams(game.home_team, game.away_team) self.groups[group.id] = group self._sort_groups() self._log.info("Settings playoff") for id_ in data_dict.knockout: round_data = AttrDict(data_dict.knockout[id_]) round_ = Round(id_) for game_data in round_data.matches: game = PlayoffGame() game.init_from_json(game_data, self.teams) game.set_order(round_.order) self.games[game.id] = game round_.add_game(game) self.playoff.rounds.append(round_) self.playoff.sort()
def create_groups(self): """ Override this method in your model to create all of your groups. In general, you shouldn't need to: fill in the grp_struct instead. """ self.groups = [] grps = self.grp_struct for grp_nm in grps: grp = grps[grp_nm] num_mbrs = grp_val(grp, NUM_MBRS) if NUM_MBRS_PROP in grp: num_mbrs = self.props.get(grp[NUM_MBRS_PROP], num_mbrs) self.groups.append( Group(grp_nm, action=grp_val(grp, GRP_ACTION), color=grp_val(grp, COLOR), num_mbrs=num_mbrs, mbr_creator=grp_val(grp, MBR_CREATOR), mbr_action=grp_val(grp, MBR_ACTION), exec_key=self.exec_key)) return self.groups
def test_plot_data(self): """ Test the construction of scatter plot data. """ global travis travis = os.getenv("TRAVIS") if not travis: our_grp = Group(GRP1, members=[self.newton], exec_key=self.exec_key) self.env = Env("Test env", members=[our_grp], exec_key=self.exec_key) ret = self.env.plot_data() (x, y) = self.newton.pos self.assertEqual( ret, {GRP1: { X: [x], Y: [y], 'color': None, 'marker': None }})
def group(request, cn, sort_by='sn'): group = Group.get_by_cn(cn, ['cn', 'description', 'gidNumber', 'memberUid', 'owner']) members = [] owner = group.owner.split(',')[0][4:] description = group.description for memberUid in group.memberUid: user = User.get_by_uid(memberUid, ['uid', 'givenName', 'sn']) if not user: kwargs = {} kwargs['uid'] = memberUid kwargs['givenName'] = '' kwargs['sn'] = '' kwargs['former_member'] = True user = User(**kwargs) members.append(user) sorted_members = sorted(members, key=attrgetter(sort_by)) context = { 'description' : description, 'group': group, 'members': sorted_members, 'owner' : owner, } return render(request, 'iapp_group/details.html', context)
def test_str(self): name = "Ramanujan" c = Group(name, exec_key=self.exec_key) self.assertEqual(name, str(c))
def create_mathgrp(exec_key, members): return Group("Math groups", members=members, exec_key=exec_key)
def create_cambguys2(exec_key): return Group("Other Cambridge guys", members=[create_littlewood(), create_ramsey()], exec_key=exec_key)
def create_cambguys(exec_key): return Group("Cambridge guys", members=[create_hardy(), create_ramanujan()], exec_key=exec_key)
def create_calcguys(exec_key, members): return Group(CALC_GUYS, members=members, exec_key=exec_key)
def index(request): all_group = Group.all(['cn', 'gidNumber']) sorted_all_group = sorted(all_group, key=attrgetter('cn')) context = {'all_group' : sorted_all_group} return render(request, 'iapp_group/index.html', context)