def __fetch_to_object(self, fetchresult, return_one=False): """ fetch[0]: id_championnat fetch[1]: id_equipe fetch[2]: id_equipe_exterieur fetch[3]: id_match fetch[4]: date_match fetch[5]: commentaire_match fetch[6]: isplayed_match :param fetchresult: :param return_one: :return: """ liste = [] try: if len(fetchresult) > 0: for fetch in fetchresult: obj = Match(fetch[1], fetch[2], fetch[4], fetch[5], fetch[6]) obj.id = fetch[3] liste.append(obj) return liste if not return_one else liste[0] else: return None except Exception as ex: DAOException(self, ex)
def prepare_flow_specifications(measurement_rates=None, tests_duration=None): flow_specs = [] flow_match = Match(is_wildcard=True) flow_match["ethernet_type"] = 0x0800 switch_hosts = ["7e", "e5", "66", "38"] configured_rate = 50 # for src_host, dst_host in permutations(switch_hosts, 2): # for src_host, dst_host in [("7e", "38"), # ("38", "7e"), # ("66", "e5"), # ("e5", "66")]: # for src_host, dst_host in [("e5", "7e"), ("7e", "e5")]: if src_host == dst_host: continue # measurement_rates = [] fs = FlowSpecification(src_host_id=src_host, dst_host_id=dst_host, configured_rate=configured_rate, flow_match=flow_match, measurement_rates=measurement_rates, tests_duration=tests_duration, delay_budget=None) flow_specs.append(fs) return flow_specs
def push_loop_preventing_drop_rules(self, sw, table_number): for h_id in self.network_graph.host_ids: # Get concerned only with hosts that are directly connected to this sw h_obj = self.network_graph.get_node_object(h_id) if h_obj.sw.node_id != sw: continue # Get a vanilla flow flow = self.create_base_flow(sw, table_number, 100) action_list = [] # Compile match with in_port and destination mac address if self.network_graph.controller == "ryu": flow["match"]["in_port"] = h_obj.switch_port.port_number flow["match"]["eth_dst"] = h_obj.mac_addr elif self.network_graph.controller == "onos": flow_match = Match(is_wildcard=True) flow_match["ethernet_type"] = 0x0800 mac_int = int(h_obj.mac_addr.replace(":", ""), 16) flow_match["ethernet_destination"] = int(mac_int) flow_match["in_port"] = int(h_obj.switch_port.port_number) flow["selector"]["criteria"] = flow_match.generate_match_raw( self.network_graph.controller, flow["selector"]["criteria"]) # Make and push the flow self.populate_flow_action_instruction(flow, action_list, True) self.push_flow(sw, flow)
def push_host_vlan_tagged_packets_drop_rules(self, sw, host_vlan_tagged_drop_table): for h_id in self.network_graph.host_ids: # Get concerned only with hosts that are directly connected to this sw h_obj = self.network_graph.get_node_object(h_id) if h_obj.sw.node_id != sw: continue # Get a vanilla flow flow = self.create_base_flow(sw, host_vlan_tagged_drop_table, 100) action_list = [] if self.network_graph.controller == "ryu": flow["match"]["in_port"] = h_obj.switch_port.port_number flow["match"]["vlan_vid"] = self.network_graph.graph.node[sw][ "sw"].synthesis_tag elif self.network_graph.controller == "onos": flow_match = Match(is_wildcard=True) flow_match["ethernet_type"] = 0x0800 flow_match["in_port"] = int(h_obj.switch_port.port_number) flow_match["vlan_id"] = self.network_graph.graph.node[sw][ "sw"].synthesis_tag flow["selector"]["criteria"] = flow_match.generate_match_raw( self.network_graph.controller, flow["selector"]["criteria"]) # Make and push the flow self.populate_flow_action_instruction(flow, action_list, True) self.push_flow(sw, flow)
def get_new(id_team_home, id_team_outside, datetime=None, comment=None, isplayed=False): obj = Match(id_team_home, id_team_outside, datetime, comment, isplayed) return obj
def create_match(message): app.logger.info("TRYING TO CREATE A NEW MATCH") match = Match(server_config, message['whites'], message['blacks'], message['wt'], message['bt'], message['wi'], message['bi']) manager.add(match) emit('receive-new-match', match.get_reduced_status(), room=accountant.get_cpanel())
def new(): if request.method == 'GET': return make_response(render_template('Theme/form_component.html')) elif request.method == 'POST': app.logger.info("CREATING MATCH FOR W:" + request.json['white_name'] + " B:" + request.json['black_name']) match = Match(server_config, request.json['white_name'], request.json['black_name']) manager.add(match) return json.dumps(match.get_reduced_status())
def round_deserializer(reloaded_round): reload_round = Round(reloaded_round["round_number"], reloaded_round["start_time"], reloaded_round["end_time"]) for match in reloaded_round["matches"]: player1 = player_deserializer(match["player1"]) player2 = player_deserializer(match["player2"]) reload_match = Match(player1, player2) reload_match.score_player1 = match["score_player1"] reload_match.score_player2 = match["score_player2"] reload_round.add_reload_match(reload_match) return reload_round
def deserializer(name): db = TinyDB("db_tournament.json", indent=4) tournaments = db.table("Tournaments") tournament = Query() tournament = tournaments.search(tournament.name == name)[0] reload_tournament = Tournament( tournament["name"], tournament["time control"], tournament["place"], tournament["date"], tournament["description"], ) for player in tournament["players"]: reload_player = Player( player["first name"], player["last name"], player["elo"], player["date of birth"], player["player's gender"], player["score"], player["opponent list"], ) reload_tournament.add_player(reload_player) for round in tournament["rounds"]: reload_round = Round(round["number"]) for match in round["matchs"]: player1 = Player( match["player1"]["first name"], match["player1"]["last name"], match["player1"]["elo"], match["player1"]["date of birth"], match["player1"]["player's gender"], match["player1"]["score"], match["player1"]["opponent list"], ) player2 = Player( match["player2"]["first name"], match["player2"]["last name"], match["player2"]["elo"], match["player2"]["date of birth"], match["player2"]["player's gender"], match["player2"]["score"], match["player2"]["opponent list"], ) reload_match = Match(player1, player2, match["score player 1"], match["Score player 2"]) reload_round.add_reload_match(reload_match) reload_tournament.add_round(reload_round) return reload_tournament
def instanciation_matchs(self, i): """ Fonction qui instancie les matchs du tournoi à partir du .json """ round_table = self.tournament_progress.serialized_rounds[i] round_matchs = round_table["Round Matchs"] for s_match in round_matchs: print(s_match) m = Match( player1=s_match["Player1"], player2=s_match["Player2"], score1=s_match["Score1"], score2=s_match["Score2"], ) self.tournament_progress.rounds[i].add_match(m.player1, m.player2)
def prepare_flow_specifications(measurement_rates, tests_duration, delay_budget): flow_specs = [] flow_match = Match(is_wildcard=True) flow_match["ethernet_type"] = 0x0800 h1s2_to_h1s1 = FlowSpecification(src_host_id="h1s2", dst_host_id="h1s1", configured_rate=50, flow_match=flow_match, measurement_rates=measurement_rates, tests_duration=tests_duration, delay_budget=delay_budget) h2s2_to_h2s1 = FlowSpecification(src_host_id="h2s2", dst_host_id="h2s1", configured_rate=50, flow_match=flow_match, measurement_rates=measurement_rates, tests_duration=tests_duration, delay_budget=delay_budget) h1s1_to_h1s2 = FlowSpecification(src_host_id="h1s1", dst_host_id="h1s2", configured_rate=50, flow_match=flow_match, measurement_rates=[], tests_duration=tests_duration, delay_budget=delay_budget) h2s1_to_h2s2 = FlowSpecification(src_host_id="h2s1", dst_host_id="h2s2", configured_rate=50, flow_match=flow_match, measurement_rates=[], tests_duration=tests_duration, delay_budget=delay_budget) flow_specs.append(h1s2_to_h1s1) flow_specs.append(h2s2_to_h2s1) flow_specs.append(h1s1_to_h1s2) flow_specs.append(h2s1_to_h2s2) return flow_specs
def prepare_flow_specifications(measurement_rates, tests_duration, number_of_switches, hps, number_of_RT_flows, number_of_BE_flows, delay_budget, cap_rate): flow_specs = [] flow_match = Match(is_wildcard=True) flow_match["ethernet_type"] = 0x0800 flowlist = list(itertools.product(range(1, number_of_switches+1), range(1, hps+1))) # for real-time flows # if unique number (e.g. unique flow-per host) required # index_list = random.sample(range(len(flowlist)), number_of_RT_flows + 1) # for real-time flows # generate random indices (#of_RT_flows) index_list = [random.randint(0, len(flowlist) - 1) for i in range(number_of_RT_flows)] for i in range(number_of_RT_flows): indx = flowlist[index_list[i]] rnd = range(1, indx[0]) + range(indx[0]+1, number_of_switches+1) nxtindx = (random.choice(rnd), random.randint(1, hps)) #nxtindx = flowlist[index_list[i+1]] forward_flow, reverse_flow = get_forward_reverse_flow(measurement_rates, cap_rate, indx, nxtindx, flow_match, delay_budget, tests_duration, "real-time") flow_specs.append(forward_flow) flow_specs.append(reverse_flow) # for best-effort flows index_list = random.sample(range(len(flowlist)), number_of_BE_flows + 1) # for best-effort flows for i in range(number_of_BE_flows): indx = flowlist[index_list[i]] rnd = range(1, indx[0]) + range(indx[0] + 1, number_of_switches + 1) nxtindx = (random.choice(rnd), random.randint(1, hps)) #nxtindx = flowlist[index_list[i + 1]] forward_flow, reverse_flow = get_forward_reverse_flow(measurement_rates, cap_rate, indx, nxtindx, flow_match, delay_budget, tests_duration, "best-effort") flow_specs.append(forward_flow) flow_specs.append(reverse_flow) return flow_specs
def matching(list_sort, turn, tournament): """ Cette fonction fait correspondre le joueur 1 avec le jouer 2 le joueur 3 avec le joueur 4, et ainsi de suite. Si le joueur 1 a déjà joué contre le joueur 2, elle l'associe plutôt au joueur 3. """ matches = 0 while matches < 4: player = list_sort[0] for opponent in list_sort[1:]: current_match = Match(player, opponent) if current_match in tournament.matches_list: continue tournament.add_matches(current_match) turn.matches_list.append(current_match) list_sort.remove(opponent) list_sort.remove(player) break matches += 1
def create_match_players(user_id_from, user_id_to): user_from = User.query.get(user_id_from) user_to = User.query.get(user_id_to) if not user_from or not user_to: response_object = { 'status': 'fail', 'message': 'Usuario no encontrado' } return response_object, 404 match = Match(user_from_id=user_id_from, user_to_id=user_id_to) save_changes(match) response_object = { 'status': 'success', 'message': 'Match enviado correctamente.' } return response_object, 200
def synthesize_node_pairs(self, src_hosts, dst_hosts, dst_port=None): print "Synthesizing backup paths between host pairs..." for i in xrange(len(src_hosts)): src_h_obj = self.network_graph.get_node_object(src_hosts[i]) dst_h_obj = self.network_graph.get_node_object(dst_hosts[i]) # Ignore installation of paths between switches on the same switch if src_h_obj.sw.node_id == dst_h_obj.sw.node_id: continue print "-----------------------------------------------------------------------------------------------" print 'Synthesizing primary and backup paths from', src_hosts[ i], 'to', dst_hosts[i] print "-----------------------------------------------------------------------------------------------" flow_match = Match(is_wildcard=True) flow_match["ethernet_type"] = 0x0800 if dst_port: flow_match["ip_protocol"] = 6 flow_match["tcp_destination_port"] = dst_port self.synthesize_flow(src_h_obj, dst_h_obj, flow_match) print "-----------------------------------------------------------------------------------------------" self._identify_reverse_and_balking_intents() self.push_switch_changes() if "mac_acl" in self.params: if self.params["mac_acl"]: self.push_mac_acls() self.synthesis_lib.save_synthesized_paths( self.network_configuration.conf_path)
def get_match(players): """ Erstellt ein neues Match, setzt es für die Spieler müsste auch die Spieler erzeugen? :rtype : Match """ MatchBuilder.f_random.seed() world_width = Consts.WORLD_WIDTH player_order = range(len(players)) MatchBuilder.f_random.shuffle(player_order) ordered_players = [] for i in player_order: ordered_players += [players[i]] match = Match( ordered_players, world_width, MatchBuilder.__get_new_horizon_skeleton(world_width), MatchBuilder.__get_new_player_x_positions(players, world_width)) for player in players: player.setMatch(match) return match
def load_file(file_name): """ Load game data from a file. Do not forget to drop the collection before re-importing a same file! :param file_name: path to the file """ circuit = "" schedules = dict() with open(file_name, mode="r", encoding="utf-8-sig") as file: for line_number, line in enumerate(file): line = line[:-1] cells = line.split(properties.LIST_SEPARATOR) game = Game() if line_number == 0: circuit = cells[0] continue if line_number == 1: for i in range(3, len(cells), 2): schedules[i] = (cells[i]) continue game.number = int(cells[0]) game.hash = hashlib.sha1("Baden {} Battle".format( cells[0]).encode()).hexdigest() game.name = cells[1] game.leader = cells[2] game.circuit = circuit for i in range(3, len(cells), 2): match = Match() match.time = (i - 1) / 2 match.schedule = schedules[i] match.game_number = int(cells[0]) match.players_number.append(int(cells[i])) match.players_number.append(int(cells[i + 1])) match.save() game.matches.append(match) game.save()
def matches(): if request.method == 'POST': teams = get_teams_db() match = Match(request.form['team_home'], request.form['team_away']) match_id = insert_match_db(match) stadiums = get_stadiums_db() stadium_id = get_stad_id_with_stad_name(request.form['stadium_name']) appointment = Appointment(request.form['appointment_name'], match_id, stadium_id, request.form['start_time'], request.form['end_time'], request.form['match_date']) if not request.form['appointment_name']: matchs = get_appointments_db() return render_template("matches.html", matchs=matchs, teams=teams, stadiums=stadiums, error="Appointment name can not be empty!") try: insert_appointments_db(appointment) flash("Appointment successfully created!") matchs = get_appointments_db() except psycopg2.errors.UniqueViolation: matchs = get_appointments_db() return render_template("matches.html", matchs=matchs, teams=teams, stadiums=stadiums, error="Appointment name already exists!") return render_template("matches.html", matchs=matchs, teams=teams, stadiums=stadiums) if request.method == 'GET': teams = get_teams_db() matchs = get_appointments_db() stadiums = get_stadiums_db() return render_template("matches.html", matchs=matchs, teams=teams, stadiums=stadiums)
def trigger_synthesis(self, synthesis_setup_gap, flow_specs): if self.synthesis_name == "DijkstraSynthesis": self.synthesis.network_graph = self.ng self.synthesis.network_configuration = self self.synthesis.synthesis_lib = SynthesisLib("localhost", "8181", self.ng, self) if flow_specs: self.synthesis.synthesize_node_pairs(flow_specs["src_hosts"], flow_specs["dst_hosts"]) else: self.synthesis.synthesize_all_node_pairs() elif self.synthesis_name == "AboresceneSynthesis": self.synthesis.network_graph = self.ng self.synthesis.network_configuration = self self.synthesis.synthesis_lib = SynthesisLib("localhost", "8181", self.ng, self) flow_match = Match(is_wildcard=True) flow_match["ethernet_type"] = 0x0800 self.synthesis.synthesize_all_switches(flow_match) if synthesis_setup_gap: time.sleep(synthesis_setup_gap) if self.mininet_obj: pass
# Déroulement d'un match round_number = current_tournament.turn_number counter = round_number - 1 sort_list = sorted(players_list, key=attrgetter("player_ranking")) half_length = len(sort_list) // 2 # premier tour # création d'une instance round view.show("Round", round_number - counter) current_round = Round("Round {}".format(round_number - counter)) for k in range(len(sort_list) // 2): current_tournament.add_matches( Match(sort_list[k], sort_list[half_length])) current_round.add_matches( Match(sort_list[k], sort_list[half_length])) half_length += 1 controller.enter_matches_score(current_round.matches_list) # determiner la date et leur de fin du tour current_round.end_date = datetime.datetime.now().strftime( "%d/%m/%Y %H:%M:%S") # Sauvegarde des matchs dans la base de données controller.save_match(current_round.matches_list) matches_id_list = controller.get_matches_id( len(current_round.matches_list)) current_round.matches_index_list = matches_id_list
def add_match(self, player1, player2): """ Méthode qui ajoute un match au round """ match = Match(player1, player2) self.matchs.append(match)
def add_match(self, player1, player2): match = Match(player1, player2) self.matches.append(match)
def add_match(self, player1, player2): # 1 match = Match(player1, player2) self.matchs.append(match) player1.add_opponent(player2.get_elo()) player2.add_opponent(player1.get_elo())