예제 #1
0
 def calculate_par_time(self, race: Race) -> timedelta:
     par_time = timedelta(microseconds=0)
     for i in range(1, self.qualifier_cutoff + 1):
         if race.get_entrant_by_place(i).finish_time is None:
             self.logger.error("error: qualifier finish time is None")
             return
         self.logger.debug(f"finish time for rank {i} is "
                           f"{race.get_entrant_by_place(i).finish_time}")
         par_time += race.get_entrant_by_place(i).finish_time
     par_time = par_time / self.qualifier_cutoff
     return par_time
예제 #2
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
예제 #3
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
예제 #4
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
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")
예제 #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
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
예제 #9
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()
예제 #10
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
예제 #11
0
 def race_updated(self, race: Race, entrant_name: str):
     # so the sound doesn't play when the user starts obs next time
     if self.last_session_race == race.name:
         return
     self.started_at = race.started_at
     for trigger in self.triggers:
         self.logger.debug(trigger)
         if trigger.check_trigger(race,
                                  race.get_entrant_by_name(entrant_name)):
             self.play_media_callback(trigger.media_file_path,
                                      self.monitoring_type)
             self.logger.debug("trigger fired")
예제 #12
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
예제 #13
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 new(self):
        """
        Creates a new race
        """
        parser = reqparse.RequestParser()
        parser.add_argument('name', required=True)
        parser.add_argument('description', required=True)
        parser.add_argument('restrictions', type=list)
        parser.add_argument('exclusive_skills', type=list)
        parse_result = parser.parse_args(req=self.request)

        # Document.from_json() gets a string as an argument,
        # so we need to use `json.dumps()` here
        rs = Race.from_json(dumps(parse_result)).save()

        return "{}".format(rs.id)
예제 #15
0
    def update_qualifier_text(self, race: Race, full_name: str):
        if not self.is_enabled():
            return
        entrant = race.get_entrant_by_name(full_name)
        self.logger.debug(entrant)

        self.par_text = " "
        self.entrant_score = " "
        if race.entrants_count_finished >= self.qualifier_cutoff:
            par_time = self.calculate_par_time(race)
            self.logger.debug(par_time)
            self.par_text = timer_to_str(par_time, self.decimals)

            if entrant and entrant.finish_time is not None:
                entrant_score = min(2 - (entrant.finish_time / par_time), 1.05)
                self.entrant_score = "{:04.2f}".format(entrant_score)
            self.logger.debug(self.entrant_score)
예제 #16
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
예제 #17
0
 def test_generate_race_with_null_client_returns_null_client(self):
     race = Race(None, '', '')
     assert race.get_client() is None
예제 #18
0
파일: seed.py 프로젝트: pranaya12/class
    '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,
예제 #19
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)
예제 #20
0
 def test_generate_race_returns_empty_cars(self):
     race = Race(None, '', '')
     assert race.get_participants() == {}
예제 #21
0
 def test_generate_race_returns_zero_distance(self):
     race = Race(None, '', '')
     assert race.get_race_distance() == 0