Example #1
0
def register_new_pilot(request):

    if not request.user.is_authenticated:
        return redirect('%s?next=%s' % ('sign_in', request.path))

    Utils.set_port_number(request.META['SERVER_PORT'])

    pilot_name = request.POST['pilotname']
    pilot_first_name = request.POST['pilotfirstname']
    pilot_fai_id = request.POST['pilotfaiid']
    pilot_national_id = request.POST['pilotnationalid']
    pilot_f3xvault_id = request.POST['pilotf3xvaultid']

    event_id = request.GET.get('event_id')
    event = EventDAO().get(event_id, fetch_competitors=True)

    pilot = Pilot(name=pilot_name,
                  first_name=pilot_first_name,
                  f3x_vault_id=pilot_f3xvault_id,
                  national_id=pilot_national_id,
                  fai_id=pilot_fai_id)

    bib_number = event.next_available_bib_number()

    competitor = event.register_pilot(pilot, bib_number)
    CompetitorDAO().insert(competitor)

    return HttpResponseRedirect('manage_event?event_id=' + event_id)
Example #2
0
 def get_list(self, event):
     sql = 'SELECT c.pilot_id, c.bib_number, c.team, p.name, p.first_name, c.present ' \
           'FROM competitor c ' \
           'LEFT JOIN pilot p ON c.pilot_id=p.pilot_id ' \
           'WHERE event_id=%s'
     query_result = self._execute_query(sql, event.id)
     result = {}
     for row in query_result:
         bib_number = row[1]
         team = row[2]
         pilot = Pilot(row[3], row[4], pilot_id=row[0])
         present = bool(row[5])
         result[bib_number] = Competitor.register_pilot(
             event, bib_number, pilot, team, present)
     return result
Example #3
0
 def get_list(self, round_group):
     sql = 'SELECT r.run_id, c.pilot_id, c.bib_number, c.team, p.name, p.first_name FROM run r ' \
           'LEFT JOIN competitor c ON r.competitor_id=c.pilot_id AND r.event_id=c.event_id ' \
           'LEFT JOIN pilot p ON c.pilot_id=p.pilot_id ' \
           'WHERE r.group_id=%s ORDER BY c.bib_number'
     query_result = self._execute_query(sql, round_group.group_id)
     result = []
     for row in query_result:
         f3f_run = Run()
         f3f_run.round_group = round_group
         pilot = Pilot(row[4], row[5], pilot_id=row[1])
         f3f_run.competitor = Competitor.register_pilot(
             round_group.round.event, row[2], pilot, row[3])
         f3f_run.id = row[0]
         result.append(f3f_run)
     return result
Example #4
0
    def get(self, run_id, round_group):
        from F3FChrono.data.Round import Round
        sql = 'SELECT r.run_id, c.pilot_id, c.bib_number, c.team, p.name, p.first_name, ' \
              'r.penalty, rg.round_number, rg.group_number, rg.event_id, ' \
              'r.valid, r.reason, ' \
              'ch.run_time, ch.min_wind_speed, ch.max_wind_speed, ch.mean_wind_speed, ch.wind_direction, ' \
              'ch.start_date, ch.end_date, ch.lap1, ch.lap2, ch.lap3, ch.lap4, ch.lap5, ch.lap6, ch.lap7, ch.lap8, ' \
              'ch.lap9, ch.lap10, ch.climbout_time, ch.chrono_id ' \
              'FROM run r ' \
              'LEFT JOIN roundgroup rg ON r.group_id=rg.group_id ' \
              'LEFT JOIN competitor c ON r.competitor_id=c.pilot_id AND r.event_id=c.event_id ' \
              'LEFT JOIN pilot p ON c.pilot_id=p.pilot_id ' \
              'LEFT JOIN chrono ch ON r.chrono_id=ch.chrono_id ' \
              'WHERE r.run_id=%s AND r.group_id=%s '
        query_result = self._execute_query(sql, run_id, round_group.group_id)
        f3f_run = Run()
        f3f_run.id = run_id
        for row in query_result:
            f3f_run.penalty = row[6]
            f3f_run.round_group = round_group
            f3f_round = Round()
            pilot = Pilot(row[4], row[5], pilot_id=row[1])
            f3f_run.competitor = Competitor.register_pilot(
                round_group.round.event, row[2], pilot, row[3])
            f3f_run.valid = row[10]
            f3f_run.penalty = row[6]
            f3f_run.reason = row[11]

            chrono = Chrono()
            chrono.run_time = row[12]
            chrono.min_wind_speed = row[13]
            chrono.max_wind_speed = row[14]
            chrono.mean_wind_speed = row[15]
            chrono.wind_direction = row[16]
            chrono.start_time = row[17]
            chrono.end_time = row[18]
            for i in range(19, 29):
                chrono.add_lap_time(row[i])
            chrono.climbout_time = row[29]
            chrono.id = row[30]

            f3f_run.chrono = chrono

        return f3f_run
Example #5
0
 def get(self, event, bib_number):
     sql = 'SELECT c.pilot_id, c.bib_number, c.team, c.present, ' \
           'p.name, p.first_name, p.fai_id, p.national_id, p.f3x_vault_id ' \
           'FROM competitor c ' \
           'LEFT JOIN pilot p  ON c.pilot_id=p.pilot_id ' \
           'WHERE event_id=%s AND bib_number=%s'
     query_result = self._execute_query(sql, event.id, bib_number)
     result = None
     #Query should return only one row
     for row in query_result:
         pilot = Pilot(row[4],
                       row[5],
                       pilot_id=row[0],
                       f3x_vault_id=row[8],
                       fai_id=row[6],
                       national_id=row[7])
         return Competitor.register_pilot(event, int(bib_number), pilot,
                                          row[2], bool(row[3]))
     return None
Example #6
0
    def from_csv(event_name, event_location, begin_date, end_date, csv_file):
        event = Event()

        event.name = event_name
        event.location = event_location

        event.begin_date = datetime.strptime(begin_date.strip('\"'),
                                             '%d/%m/%y')
        event.end_date = datetime.strptime(end_date.strip('\"'), '%d/%m/%y')

        file_data = csv_file.read().decode("utf-8")

        lines = file_data.split("\n")
        next_bib_number = 1
        for line in lines:
            splitted_line = line.split(',')
            if len(splitted_line) >= 2:
                pilot = Pilot(name=splitted_line[0].strip('\"'),
                              first_name=splitted_line[1].strip('\"'))
                event.register_pilot(pilot, next_bib_number)
                next_bib_number += 1

        return event
Example #7
0
    def from_f3x_vault(login, password, contest_id, max_rounds=None):
        """
        TODO: f3x_vault related stuff should be moved in specific class later
        :param login:
        :param password:
        :param contest_id:
        :return:
        """
        event = Event()

        #Getting general event info
        request_url = 'https://www.f3xvault.com/api.php?login='******'&password='******'&function=getEventInfo&event_id=' + str(contest_id)
        response = requests.post(request_url)
        splitted_response = response.text.split('\n')

        #Skip first line
        splitted_response.pop(0)

        splitted_line = splitted_response.pop(0).split(',')

        event.id = splitted_line[0].strip('\"')
        #dates have to be converted to datetime objects
        event.name = splitted_line[1].strip('\"')
        event.begin_date = datetime.strptime(splitted_line[3].strip('\"'),
                                             '%m/%d/%y')
        event.end_date = datetime.strptime(splitted_line[4].strip('\"'),
                                           '%m/%d/%y')
        event.location = splitted_line[2].strip('\"')
        event.f3x_vault_id = contest_id

        n_rounds = int(splitted_line[6].strip('\"'))

        #Skip pilots definition header
        splitted_response.pop(0)

        for line in splitted_response:
            splitted_line = line.split(',')
            if len(splitted_line) > 2:
                pilot = Pilot(name=splitted_line[3].strip('\"'),
                              first_name=splitted_line[2].strip('\"'),
                              f3x_vault_id=int(splitted_line[0].strip('\"')),
                              national_id=splitted_line[7].strip('\"'),
                              fai_id=splitted_line[6].strip('\"'))
                bib_number = int(splitted_line[1].strip('\"'))

                event.register_pilot(pilot, bib_number)

        if max_rounds is not None:
            n_rounds_to_get = min(max_rounds, n_rounds)
        else:
            n_rounds_to_get = n_rounds

        for round_id in range(1, n_rounds_to_get + 1):

            f3f_round = event.create_new_round()

            request_url = 'https://www.f3xvault.com/api.php?login='******'&password='******'&function=getEventRound&event_id=' + str(contest_id) + \
                          '&round_number=' + str(round_id)
            response = requests.post(request_url)
            df = pd.read_csv(StringIO(response.text), sep=",", header=1)

            f3x_vault_data = {}
            for index, row in df.iterrows():
                #First put data in a dictionary to sort it on bib numbers

                competitor = event.competitor_from_f3x_vault_id(
                    row['Pilot_id'])
                pilot_flight_time = row['seconds']
                pilot_penalty = row['penalty']
                pilot_flight_valid = (pilot_flight_time > 0.0)

                if competitor is not None:
                    pilot_chrono = Chrono()
                    pilot_chrono.run_time = pilot_flight_time
                    f3x_vault_data[competitor.bib_number] = {
                        'competitor': competitor,
                        'pilot_chrono': pilot_chrono,
                        'pilot_penalty': pilot_penalty,
                        'pilot_flight_valid': pilot_flight_valid
                    }

            for bib in sorted(f3x_vault_data):
                f3f_round.handle_terminated_flight(
                    f3x_vault_data[bib]['competitor'],
                    f3x_vault_data[bib]['pilot_chrono'],
                    f3x_vault_data[bib]['pilot_penalty'],
                    f3x_vault_data[bib]['pilot_flight_valid'])

            f3f_round.validate_round()

            print(f3f_round.to_string())

        return event