Exemplo n.º 1
0
    def test_generate_race_a_car_has_a_position_assigned_always(self):
        client = mqtt.Client('test')
        race = Race(client, 't1', 't2')
        c1 = {'timestamp': 1, 'carIndex': 1, 'location': {'lat': 0, 'long': 0}}
        race.update_car_info(c1)

        assert len(race.get_participants().values()) == 1
        assert race.get_participants()[1].get_car_position() == 1
Exemplo n.º 2
0
    def get(self, id=None):
        data = ApiRace.parser.parse_args()
        races = Race(data['track'], data['day'])
        if not races.getRaces():
            external = FetchRaces(data['track'], data['day']).response()
            races.setRaces(external)

        return races.getRaces()['runs']
def select(id):
    # Bring the race in
    sql = "SELECT * from races WHERE id = %s"
    values = [id]
    result = run_sql(sql, values)[0]
    race = Race(result['title'], result['date'], result['distance'], result['elevation'], result['id'])
  
    return race
def update_race(id):
    title = request.form["title"]
    date = request.form["date"]
    distance = request.form["distance"]
    elevation = request.form["elevation"]
    new_race = Race(title, date, distance, elevation, id)
    race_repository.update(new_race)
    return redirect("/races")
Exemplo n.º 5
0
def connect_to_broker(broker, broker_port):
    mqtt.Client.connected_flag = False
    client = mqtt.Client("mat_app")
    client.on_connect = on_connect
    client.on_message = on_message
    client.connect(broker, port=broker_port)
    race = Race(client, 'carStatus', 'events')
    print(type(client))
    client.user_data_set(race)
    client.loop_forever()
def select_all():
    races = []
    sql = "SELECT * from races"

    results = run_sql(sql)

    for row in results:
        race = Race(row['title'], row['date'], row['distance'],row['elevation'], row['id'])
        races.append(race)
    return races
Exemplo n.º 7
0
    def test_generate_race_add_two_cars_both_have_positions(self):
        client = mqtt.Client('test')
        race = Race(client, 't1', 't2')
        c1 = {'timestamp': 1, 'carIndex': 1, 'location': {'lat': 0, 'long': 0}}
        race.update_car_info(c1)
        c2 = {'timestamp': 1, 'carIndex': 2, 'location': {'lat': 0, 'long': 0}}
        race.update_car_info(c2)

        assert len(race.get_participants().values()) == 2
        assert race.get_participants()[1].get_car_position() == 1
        assert race.get_participants()[2].get_car_position() == 2
Exemplo n.º 8
0
def races(runner):
    races = []
    sql = "SELECT * from races WHERE runner_id = %s"
    values = [runner.id]
    results = run_sql(sql, values)

    for row in results:
        race = Race(row['title'], row['distance'], row['elevation'],
                    row['runner_id'], row['id'])
        races.append(race)
    return races
Exemplo n.º 9
0
    def test_generate_race_add_two_cars_and_update_one_makes_him_leader(self):
        client = mqtt.Client('test')
        race = Race(client, 't1', 't2')
        c1 = {'timestamp': 1, 'carIndex': 1, 'location': {'lat': 0, 'long': 0}}
        race.update_car_info(c1)
        c2 = {'timestamp': 1, 'carIndex': 2, 'location': {'lat': 0, 'long': 0}}
        race.update_car_info(c2)
        c2['timestamp'] = 3
        c2['location'] = {'lat': 0.1, 'long': 0.1}
        race.update_car_info(c2)

        assert len(race.get_participants().values()) == 2
        assert race.get_participants()[2].get_car_position() == 1
Exemplo n.º 10
0
 def test_generate_race_update_with_invalid_json_does_not_change(self):
     client = mqtt.Client('test')
     race = Race(client, 't1', 't2')
     car_coords = {
         #'timestamp': 1, Incorrect car_coords
         'carIndex': 1,
         'location': {
             'lat': 0,
             'long': 0
         }
     }
     race.update_car_info(car_coords)
     assert len(race.get_participants().values()) == 0
Exemplo n.º 11
0
 def test_generate_race_and_add_car_correctly(self):
     client = mqtt.Client('test')
     race = Race(client, 't1', 't2')
     car_coords = {
         'timestamp': 1,
         'carIndex': 1,
         'location': {
             'lat': 0,
             'long': 0
         }
     }
     race.update_car_info(car_coords)
     assert len(race.get_participants().values()) == 1
Exemplo n.º 12
0
def get_test_race(
        status_value="in_progress", version=1, entrants_count=2,
        started_at=datetime.now(timezone.utc),
        start_delay=timedelta(seconds=-15),
        opened_at=datetime.now(timezone.utc), ended_at=None,
        cancelled_at: datetime = None, entrants: List[Entrant] = None,
        opened_by: User = None
        ) -> Race:
    entrant_count_finished = list.count(
            (list((x.status.value == "finished" for x in entrants))), True)
    test_race = Race(name="tested-raceroom-0420",
                     status=Status(value=status_value,
                                   verbose_value="", help_text=""),
                     category=get_test_race_category(),
                     goal=Goal("", False),
                     info="A test race",
                     url="",
                     data_url="",
                     websocket_url="",
                     websocket_bot_url="",
                     websocket_oauth_url="",
                     entrants_count=entrants_count,
                     entrants_count_inactive=0,
                     entrants_count_finished=entrant_count_finished,
                     entrants=entrants,
                     version=version,
                     started_at=started_at,
                     start_delay=start_delay,
                     ended_at=ended_at,
                     cancelled_at=cancelled_at,
                     unlisted=False,
                     time_limit=timedelta(days=1),
                     streaming_required=True,
                     auto_start=True,
                     opened_by=opened_by,
                     opened_at=opened_at,
                     monitors=[],
                     recordable=True,
                     recorded=False,
                     recorded_by=None,
                     allow_comments=True,
                     hide_comments=False,
                     allow_midrace_chat=True
                     )
    return test_race
Exemplo n.º 13
0
 def test_generate_race_returns_empty_cars(self):
     race = Race(None, '', '')
     assert race.get_participants() == {}
Exemplo n.º 14
0
 def test_generate_race_returns_zero_distance(self):
     race = Race(None, '', '')
     assert race.get_race_distance() == 0
Exemplo n.º 15
0
runner_3 = Runner("Vito", "Corleone")
runner_repository.save(runner_3)
runner_4 = Runner("Malcolm", "Tucker")
runner_repository.save(runner_4)
runner_5 = Runner("Jimmy", "Garroppolo")
runner_repository.save(runner_5)
runner_6 = Runner("Eddie", "Vedder")
runner_repository.save(runner_6)
runner_7 = Runner("Sabrina", "Pace")
runner_repository.save(runner_7)
runner_8 = Runner("Jasmine", "Paris")
runner_repository.save(runner_8)
runner_9 = Runner("Emilie", "Forsberg")
runner_repository.save(runner_9)

race_1 = Race("Dumyat Dash", '2020-08-28', 6.2, 457)
race_repository.save(race_1)
race_2 = Race("Cockelroy", '2020-01-01', 3.4, 132)
race_repository.save(race_2)
race_3 = Race("Ochil 2000s", '2020-11-28', 33.0, 1200)
race_repository.save(race_3)
race_4 = Race("EPIC Trail 10K", '2021-01-30', 10, 421)
race_repository.save(race_4)

# race_time_1 = Race_time(race_1, runner_1, 32)
# race_time_repository.save(race_time_1)

race_result_1 = Race_result(race_1, runner_2, 42)
race_result_repository.save(race_result_1)
race_result_2 = Race_result(race_1, runner_1, 43)
race_result_repository.save(race_result_2)
Exemplo n.º 16
0
    'description':
    'The Zerg Swarm is a terrifying and ruthless amalgamation of biologically advanced, arthropodal aliens. Dedicated to the pursuit of genetic perfection, the zerg relentlessly hunt down and assimilate advanced species across the galaxy, incorporating useful genetic code into their own. They are named "the Swarm" per their ability to rapidly create strains, and the relentless assaults they employ to overwhelm their foes.'
}, {
    'name':
    'Terran',
    'description':
    'The terrans are a young species with psionic potential. The terrans of the Koprulu sector descend from the survivors of a disastrous 23rd century colonization mission from Earth.[1] Compared to the protoss and zerg, the terrans are highly factionalized and endure frequent wars amongst themselves in addition to the more recent conflicts with their alien neighbors. Nevertheless, terrans stand as one of the three dominant species of the galaxy.'
}, {
    'name':
    'Protoss',
    'description':
    'The protoss, a.k.a. the Firstborn, are a sapient humanoid race native to Aiur. Their advanced technology complements and enhances their psionic mastery.'
}]

for race in races:
    new_race = Race(name=race['name'], description=race['description'])
    session.add(new_race)
    session.commit()
    race_ids[race['name']] = new_race.id

print race_ids
'''
Units
'''
race_units = {
    'Zerg': [{
        'name': 'Mutalisk',
        'description':
        'The mutalisk\'s attack strikes three targets in succession, dealing 9 damage to the first, 3 to the second, and 1 to the last.',
        'mineral_cost': 100,
        'vespene_cost': 100,
Exemplo n.º 17
0
 def test_generate_race_with_null_client_returns_null_client(self):
     race = Race(None, '', '')
     assert race.get_client() is None