예제 #1
0
def registration():
    if request.method == 'GET':
        return render_template('registration.html')
    if request.method == 'POST':
        content = request.form
        json_content = json.dumps(content)
        connector = Connector()
        try:
            connector.send_post(json_content, 'registration/')
        except:
            return render_template('registration.html', error=True)
        return redirect('/')
class TelemetryBroadcast(object):
    """ Cette classe est la classe principale du broadcast de la télémétrie de SONIA. 
        Elle orchestre le pont entre ROSBridge et la télémétrie. 
    """
    def __init__(self):
        self.__view = View(self)
        self.__ros_connector = RosConnector(self)
        self.__host = '0.0.0.0'
        self.__port = 9090

        self.__connector = None

        self.__run()

    def __run(self):
        self.__ros_connector.connection_to_rosbridge(self.__host, self.__port)
        if self.__ros_connector.is_connected():
            self.__ros_connector.subscribe_all()
            self.__connection_to_connector()
        try:
            while self.__ros_connector.is_connected():
                self.__view.print_console("Ok")
                time.sleep(0.5)
            self.__ros_connector.deconnection_to_rosbridge()
        except KeyboardInterrupt:
            self.__ros_connector.deconnection_to_rosbridge()

    def __connection_to_connector(self):
        if not self.__connector:
            self.__connector = Connector(self)
            self.__connector.daemon = True
            self.__connector.start()

    def send_msg_to_network(self, msg):
        self.__connector.send_msg(msg)

    def publish(self, topic, message_type, message):
        self.__ros_connector.publish(topic, message_type, message)

    def print_console(self, message):
        """ Cette fonction permet d'afficher à la console. """
        self.__view.print_console(message)

    def test_publish():
        self.publish('/mission_manager/mission_name_msg',
                     'mission_manager/MissionNameMsg', {'name': 'Example'})
예제 #3
0
def prepare_competition_page(id):
    connector = Connector()
    json_matches = connector.send_get('competitions/{}/matches/'.format(id))
    matches = json.loads(json_matches)
    json_teams = connector.send_get('competitions/{}/teams/'.format(id))
    teams = json.loads(json_teams)
    proper_teams = []
    [proper_teams.append(Team(team['id'], team['name'])) for team in teams]
    for match in matches:
        if match['status'] in ['scheduled', 'in_play']:
            continue
        team_indexes = []
        for i, team in enumerate(proper_teams):
            if team.id == get_team_id_from_match(match, 0):
                team_indexes.append(i)
        for i, team in enumerate(proper_teams):
            if team.id == get_team_id_from_match(match, 1):
                team_indexes.append(i)
        for i, index in enumerate(team_indexes):
            proper_teams[index].played_matches += 1
            proper_teams[team_indexes[i]].scored += match['teams'][i]['goals']
            proper_teams[team_indexes[i]].conceded += match['teams'][
                (i + 1) % 2]['goals']

        if match['teams'][0]['goals'] > match['teams'][1]['goals']:
            proper_teams[team_indexes[0]].points += 3
            proper_teams[team_indexes[0]].won += 1
            proper_teams[team_indexes[1]].lost += 1
        elif match['teams'][0]['goals'] == match['teams'][1]['goals']:
            for index in team_indexes:
                proper_teams[index].points += 1
                proper_teams[index].drawn += 1
        else:
            proper_teams[team_indexes[1]].points += 3
            proper_teams[team_indexes[1]].won += 1
            proper_teams[team_indexes[0]].lost += 1

    proper_teams.sort(key=lambda x: x.points, reverse=True)

    return render_template('competition.html',
                           competition_id=id,
                           matches=matches,
                           teams=proper_teams)
예제 #4
0
def competition_matches(id):
    connector = Connector()
    json_matches = connector.send_get('competitions/{}/matches/'.format(id))
    json_teams = connector.send_get('competitions/{}/teams/'.format(id))
    matches = json.loads(json_matches)
    teams = json.loads(json_teams)
    matches_to_display = []
    for i in range(0, len(matches)):
        team1 = get_team_by_id(get_team_id(matches[i]['teams'][0]), teams)
        team2 = get_team_by_id(get_team_id(matches[i]['teams'][1]), teams)
        if matches[i]['teams'][0]['is_host']:
            home_team = TeamInMatch(matches[i]['teams'][0], team1)
            away_team = TeamInMatch(matches[i]['teams'][1], team2)
        else:
            home_team = TeamInMatch(matches[i]['teams'][0], team2)
            away_team = TeamInMatch(matches[i]['teams'][1], team1)
        matches_to_display.append(Match(matches[i], home_team, away_team))

    return render_template('matches.html',
                           competition_id=id,
                           matches=matches_to_display)
예제 #5
0
def competition_match(competition_id, match_id):
    connector = Connector()
    json_match = connector.send_get('competitions/{}/matches/{}/'.format(
        competition_id, match_id))
    json_teams = connector.send_get(
        'competitions/{}/teams/'.format(competition_id))
    match = json.loads(json_match)
    teams = json.loads(json_teams)
    team1 = get_team_by_id(get_team_id(match['teams'][0]), teams)
    team2 = get_team_by_id(get_team_id(match['teams'][1]), teams)
    if match['teams'][0]['is_host']:
        home_team = TeamInMatch(match['teams'][0], team1)
        away_team = TeamInMatch(match['teams'][1], team2)
    else:
        home_team = TeamInMatch(match['teams'][0], team2)
        away_team = TeamInMatch(match['teams'][1], team1)
    match_to_display = Match(match, home_team, away_team)

    return render_template('match.html',
                           match=match_to_display,
                           competition_id=competition_id)
예제 #6
0
def prepare_index_page():
    todays_date = datetime.now().strftime('%d-%m-%Y')
    connector = Connector()
    json_matches = connector.send_get('matches/today/')
    json_teams = connector.send_get('teams/')
    matches = json.loads(json_matches)
    teams = json.loads(json_teams)
    matches_to_display = []
    for i in range(0, len(matches)):
        team1 = get_team_by_id(get_team_id(matches[i]['teams'][0]), teams)
        team2 = get_team_by_id(get_team_id(matches[i]['teams'][1]), teams)
        if matches[i]['teams'][0]['is_host']:
            home_team = TeamInMatch(matches[i]['teams'][0], team1)
            away_team = TeamInMatch(matches[i]['teams'][1], team2)
        else:
            home_team = TeamInMatch(matches[i]['teams'][0], team2)
            away_team = TeamInMatch(matches[i]['teams'][1], team1)
        matches_to_display.append(Match(matches[i], home_team, away_team))

    return render_template('index.html',
                           date=todays_date,
                           matches=matches_to_display)
예제 #7
0
def team(id):
    connector = Connector()
    json_team = connector.send_get('teams/{}/'.format(id))
    team = json.loads(json_team)
    json_people = connector.send_get('people/')
    people = json.loads(json_people)
    proper_players = []
    for player in team['players']:
        for person in people:
            if get_id_from_url(player['person']) == person['id']:
                proper_player = Player(id=person['id'],
                                       name=person['name'],
                                       position=player['position'],
                                       birth_date=person['birth_date'],
                                       shirt_number=player['shirt_number'],
                                       nationality=person['nationality'])
                proper_players.append(proper_player)

    decks_amount = math.ceil(len(proper_players) / 3)

    return render_template('team.html',
                           team=team,
                           players=proper_players,
                           decks_amount=decks_amount)
 def __connection_to_connector(self):
     if not self.__connector:
         self.__connector = Connector(self)
         self.__connector.daemon = True
         self.__connector.start()
예제 #9
0
def competitions():
    connector = Connector()
    json_competitions = connector.send_get('competitions/')
    competitions = json.loads(json_competitions)
    return render_template('competitions.html', competitions=competitions)