def _parse_formation_html(self, html): soup = BeautifulSoup(html) formations = soup.find('div', {'class': 'formations'}) home, away = formations.findAll('div', recursive=False) return { 'home': Formation(self._process_formation(home, True)), 'away': Formation(self._process_formation(away)) }
def __init__(self, team, parent=None): super(editTeamDialog, self).__init__(parent) self.team = team self.setupUi(self) self.setWindowTitle("Edit Team") managerNameLabel = QLabel() managerNameLabel.setText("<b>{0}</b>".format(team.manager)) self.teamUserInfoLayout.addWidget(managerNameLabel, 0, 1) self.teamNameEdit.setText(team.team_name) if team.email: self.emailEdit.setText(team.email) self.type = team.team_type self.formation = Formation(team.formation) self.formationRadioButtons[str(team.formation)].setChecked(True) self.total_cost = 0 self.team_players = [ s.player for s in self.team.squad.current_players() ] self.setupSelections() self.setCurrentPlayers()
def test_saveFormationToEtcd(self): logger = logging.getLogger() stream = logging.StreamHandler(sys.stdout) stream.setLevel(logging.DEBUG) formatter = logging.Formatter( '%(asctime)s - %(name)s - %(levelname)s - %(message)s') stream.setFormatter(formatter) logger.addHandler(stream) manager = Manager(logger) expected_text = '[{"username": "******", "cpu-shares": 102, '\ '"ram": 100, "hostname": "app01", "ports": [{"host_port": 8080, '\ '"container_port": 8080}], "host_server": "dlceph02"}]' username = '******' formation_name = 'test_formation' f = Formation(username, formation_name) f.add_app(username, 'app01', 102, 100, [{ "host_port": 8080, "container_port": 8080 }], 'dlceph02') manager.save_formation_to_etcd(f) etcd_ret = manager.etcd.get_key('{username}/{hostname}'.format( username=username, hostname=formation_name)) logger.debug("Etcd_ret: %s" % etcd_ret) logger.debug("Expected text: %s" % expected_text) self.assertEquals(etcd_ret, expected_text)
def formationChanged(self, formation): if formation != str(self.formation): newFormation = Formation(formation) form = changeFormationDialog(self.playerSelections(), self.formation, newFormation, self) if form.exec_(): newPlayers = [] j = 0 oldPlayers = self.playerSelections() for p, q in zip(self.formation.list(), newFormation - self.formation): players = [] for i in range(p): player = oldPlayers.pop(0) if player not in form.playersOut: players.append(player) if q > 0: for i in range(q): players.append(None) newPlayers.extend(players) self.formation = newFormation self.setupSelections() self.setCurrentPlayers(newPlayers) else: self.formationRadioButtons[str( self.formation)].setChecked(True)
def load_formation_from_etcd(self, username, formation_name): f = Formation(username, formation_name) app_list = json.loads( json.loads( self.etcd.get_key( '/formations/{username}/{formation_name}'.format( username=username, formation_name=formation_name)))) for app in app_list: # If our host doesn't support swapping we're going to get some garbage # message in here if "WARNING" in app['container_id']: app['container_id'] = app['container_id'].replace("WARNING: Your "\ "kernel does not support memory swap capabilities. Limitation discarded.\n","") #Message changed in docker 0.8.0 app['container_id'] = app['container_id'].replace("WARNING: WARNING:"\ "Your kernel does not support swap limit capabilities. Limitation "\ "discarded.\n","") app['container_id'].strip('\n') # Set volumes if needed volumes = None if app['volumes']: self.logger.info("Setting volumes to: " + ''.join(app['volumes'])) volumes = app['volumes'] f.add_app(app['container_id'], app['hostname'], app['cpu_shares'], app['ram'], app['port_list'], app['ssh_port'], 22, app['host_server'], volumes) # Return fully parsed and populated formation object return f
def __init__(self, name, formation_type): self.name = name self.common_image_dir = constant.BATTLE_COMMON_IMAGE_DIR self.war_dir = os.path.join(constant.WARS_DIR, self.name) self.war_image_dir = os.path.join(self.war_dir, 'image') self.inventory = Inventory() self.restore = Restore() self.formation = Formation(formation_type)
def __init__(self, arg): super(FormationPosition, self).__init__() self.arg = arg self._position self._formation = Formation() self._x self._y self._caption
def __init__(self, network, algorithm=None, single=True, interval=0.05, duration=0.1): threading.Thread.__init__(self) self.daemon = True self.network = network self.near = [] self.critical = [] self.teammate = [] # Used for formation algorithm self.algorithm = algorithm self.in_session = False self.context = None self.interval = interval # send velocity interval self.duration = duration # send velocity duration self.formation = Formation(self.network) self.single = single # For one UAV in formation self.update_proc = Process(target=self.update_drone_list) self.priority_proc = Process(target=self.give_priorities)
100, seed=25, obstacle_density=0.35) game_map = Map(map_data) start = Point(2, 2) end = Point(25, 65) rel_pos = [ Point(-1, 1), Point(1, 1), Point(0, 0), Point(-1, -1), Point(1, -1), ] units_pos = [start + pos for pos in rel_pos] units = [] for i, unit_pos in enumerate(units_pos): unit = FORMATION.copy(start + rel_pos[i]) unit.add_to_formation( Formation(i, rel_pos, start, units_pos, game_map.is_valid_point), i == 2) # 2nd index unit is leader unit.set_dest(end) unit.game_map = game_map units.append(unit) game_map = Map(map_data) game_map.active = units anim = animate_game_state(game_map, frames=200) anim.save('run_game.gif', writer='imagemagick', fps=10)
from formation import Formation MAX_COST = 50.0 MAX_SUBS = 8 FORMATION = Formation("4-4-2")
def create_containers(self, user, number, formation_name, cpu_shares, ram, port_list, hostname_scheme, volume_list, docker_image, force_host_server=None): f = Formation(user, formation_name) # Convert ram to bytes from MB ram = ram * 1024 * 1024 # Get the cluster machines on each creation cluster_list = self.get_docker_cluster() circular_cluster_list = CircularList( self.order_cluster_by_load(cluster_list)) # Loop for the requested amount of containers to be created for i in range(1, number + 1): # [{"host_port":ssh_host_port, "container_port":ssh_container_port}] ssh_host_port = 9022 + i ssh_container_port = 22 host_server = circular_cluster_list[i].hostname hostname = '{hostname}{number}'.format(hostname=hostname_scheme, number=str(i).zfill(3)) # First check if we can add this host to salt. If not exit with -1 if self.check_salt_key_used(hostname): self.logger.error( 'Salt key is already taken for {hostname}'.format( hostname=hostname)) sys.exit(-1) # We are being asked to overwrite this if force_host_server: host_server = force_host_server validated_ports = [] while self.check_port_used(host_server, ssh_host_port): ssh_host_port = ssh_host_port + 1 for port in port_list: self.logger.info( "Checking if port {port} on {host} is in use".format( port=port, host=host_server)) if ':' in port: ports = port.split(':') # Only check if the host port is free. The container port should be free while self.check_port_used(host_server, ports[0]): ports[0] = int(ports[0]) + 1 # Add this to the validated port list validated_ports.append( '{host_port}:{container_port}'.format( host_port=str(ports[0]), container_port=str(ports[1]))) else: while self.check_port_used(host_server, port): port = int(port) + 1 validated_ports.append(str(port)) self.logger.info( 'Adding app to formation {formation_name}: {hostname} cpu_shares={cpu} ' 'ram={ram} ports={ports} host_server={host_server} docker_image={docker_image}' .format(formation_name=formation_name, hostname=hostname, cpu=cpu_shares, ram=ram, ports=validated_ports, host_server=host_server, docker_image=docker_image)) f.add_app(None, '{hostname}'.format(hostname=hostname), cpu_shares, ram, validated_ports, ssh_host_port, ssh_container_port, host_server, docker_image, volume_list) # Lets get this party started for app in f.application_list: self.start_application(app) #self.logger.info("Sleeping 2 seconds while the container starts") #time.sleep(2) #self.bootstrap_application(app) self.logger.info("Saving the formation to ETCD") self.save_formation_to_etcd(f)
def startPlot(self): self.c = pyqtSignal() planeNum = self.checkedNum #飞机数量 # 随机产生飞机初始坐标 x = Plane.random.uniform(1000 * self.num, 5000 * self.num) y = Plane.random.uniform(1000 * self.num, 5000 * self.num) z = Plane.random.uniform(5000, 15000) if self.sig1 == 0: #输入自定义坐标,则使用输入的坐标 if self.lineEdit.text() != '': x = int(self.lineEdit.text()) if self.lineEdit_2.text() != '': y = int(self.lineEdit_2.text()) if self.lineEdit_3.text() != '': z = int(self.lineEdit_3.text()) #飞机初始位置数据 p0 = [ x, y, z, Plane.random.uniform(0, math.pi), 0, Plane.random.uniform(150, 200), 0, 0 ] x2 = Plane.random.uniform(1000 * self.num, 5000 * self.num) y2 = Plane.random.uniform(1000 * self.num, 5000 * self.num) if self.sig2 == 0: #航母初始位置自定义 if self.lineEdit_4.text() != '': x2 = int(self.lineEdit_4.text()) if self.lineEdit_5.text() != '': y2 = int(self.lineEdit_5.text()) #航母初始位置数据 p1 = [x2, y2, 0, Plane.random.uniform(0, math.pi), 10, 0, 0, 0] planedata = [] shipdata = [] transdata = [] #航母数据生成 if len(self.shipActionArray) > 0: ship = Ship(self.shipActionArray, self.destroyer, self.frigate, p1) ship.creatrad() shipdata = copy.deepcopy(ship.Q_all) #飞机数据生成 if len(self.actionArray) > 0 and planeNum > 0: data = Plane.datac(self.actionArray, self.planetype.currentText(), p0, self.num) data.trackall() form = Formation() gap = self.planeGap #飞机间间隔 #判断编队方式 if self.formation.currentText() == "跟随编队": planedata = form.linearFormation(data.Q, planeNum, gap) if self.formation.currentText() == "菱形编队": planedata = form.diamondFormation(data.Q, planeNum, gap) if len(planedata) != 0: transdata = copy.deepcopy(self.F.dtransf(planedata)) #飞机数据转换 self.planedata.append(transdata) #把当前生成的数据加入到数组中,保存 self.shipdata.append(shipdata) #更新图像 self.gridlayout2.removeWidget(self.F) sip.delete(self.F) self.F = matplot.MyFigure([], []) self.F.plot(self.planedata, self.shipdata) self.gridlayout2.addWidget(self.F, 0, 1) #飞机的雷达数据 if len(transdata) != 0: radatai = [] for kk in range(len(transdata)): #遍历每一架飞机 distance = [x[3] for x in transdata[kk]] ##当前飞机对我方的距离 rad = Radar.datac(self.planetype.currentText(), len(transdata[kk])) rad.eledata(distance) radatai.append(rad.Q) self.raddata.append(radatai) #将雷达数据加入到数组保存 self.num = self.num + 1 #计数加一