Пример #1
0
def edit_run_time(request):

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

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

    flight_time = float(request.POST['flight_time'])

    event_id = int(request.GET.get('event_id'))
    round_number = int(request.GET.get('round_number'))
    bib_number = int(request.GET.get('bib_number'))

    event = EventDAO().get(event_id, fetch_competitors=True)
    f3f_round = RoundDAO().get_from_ids(event_id,
                                        round_number,
                                        fetch_runs=True)

    chrono = Chrono()
    chrono.run_time = flight_time

    run = Run()
    run.competitor = event.get_competitor(bib_number)
    run.penalty = 0
    run.chrono = chrono
    run.valid = True

    f3f_round.add_run_from_web(run)

    RoundDAO().update(f3f_round)

    return HttpResponseRedirect('manage_round?event_id=' + str(event_id) +
                                '&round_number=' + str(round_number))
Пример #2
0
def index(request):

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

    dao = EventDAO()

    events = dao.get_list()

    page = ResultPage(title='Events list')

    table = ResultTable(title='', css_id='ranking')

    header = Header(name=Cell('Name'))
    header.add_cell(Cell('Location'))
    header.add_cell(Cell('Begin date'))
    header.add_cell((Cell('End date')))
    table.set_header(header)

    for event in events:
        fetched_event = dao.get(event.id)
        row = Line(name=Link(fetched_event.name, 'event_view?event_id=' +
                             str(fetched_event.id)))
        row.add_cell(Cell(fetched_event.location))
        row.add_cell(Cell(str(fetched_event.begin_date)))
        row.add_cell(Cell(str(fetched_event.end_date)))
        table.add_line(row)

    page.add_table(table)

    return HttpResponse(page.to_html())
Пример #3
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)
Пример #4
0
def do_delete_event(request):

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

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

    event_id = request.GET.get('event_id')
    EventDAO().delete(EventDAO().get(event_id))

    return redirect('index')
Пример #5
0
def export_round_f3x_vault(request):
    if not request.user.is_authenticated:
        return redirect('%s?next=%s' % ('sign_in', request.path))

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

    event_id = request.GET.get('event_id')
    round_number = request.GET.get('round_number')

    if ('username' in request.POST) and ('password' in request.POST):

        f3x_username = request.POST["username"]
        f3x_password = request.POST["password"]

        #We must fetch full event to get correct valid round number
        event = EventDAO().get(event_id,
                               fetch_competitors=True,
                               fetch_rounds=True,
                               fetch_runs=True)
        requested_f3f_round = None
        for f3f_round in event.rounds:
            if f3f_round.round_number == int(round_number):
                requested_f3f_round = f3f_round

        if requested_f3f_round is not None:
            requested_f3f_round.export_to_f3x_vault(f3x_username, f3x_password)

    return HttpResponseRedirect('manage_event?event_id=' + event_id)
Пример #6
0
def download_csv(request):
    if not request.user.is_authenticated:
        return redirect('%s?next=%s' % ('sign_in', request.path))

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

    event_id = request.GET.get('event_id')
    round_number = request.GET.get('round_number')

    #We must fetch full event to get correct valid round number
    event = EventDAO().get(event_id,
                           fetch_competitors=True,
                           fetch_rounds=True,
                           fetch_runs=True)
    requested_f3f_round = None
    for f3f_round in event.rounds:
        if f3f_round.round_number == int(round_number):
            requested_f3f_round = f3f_round

    if requested_f3f_round is not None:
        # Create the HttpResponse object with the appropriate CSV header.
        response = HttpResponse(content_type='text/csv')
        response['Content-Disposition'] = 'attachment; filename="round'+\
                                          str(requested_f3f_round.valid_round_number)+'.csv"'

        csv_writer = csv.writer(response)

        requested_f3f_round.export_to_csv(csv_writer)

        return response
    else:
        return HttpResponse('Round not found')
Пример #7
0
def load_from_f3x_vault(request):
    if not request.user.is_authenticated:
        return redirect('%s?next=%s' % ('sign_in', request.path))

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

    if ('username' in request.POST) and ('password' in request.POST) and (
            'F3X_vault_id' in request.POST):

        f3x_username = request.POST["username"]
        f3x_password = request.POST["password"]

        f3x_event_id = request.POST["F3X_vault_id"]

        event = Event.from_f3x_vault(f3x_username, f3x_password, f3x_event_id)

        event.id = EventDAO().insert(event)

        for bib, competitor in event.get_competitors().items():
            CompetitorDAO().insert(competitor)

        for f3f_round in event.rounds:
            RoundDAO().insert(f3f_round)

        return redirect('index')

    else:

        return HttpResponse('<p>Invalid parameters !')
Пример #8
0
def give_penalty(request):
    if not request.user.is_authenticated:
        return redirect('%s?next=%s' % ('sign_in', request.path))

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

    event_id = request.GET.get('event_id')
    round_number = request.GET.get('round_number')
    bib_number = request.GET.get('bib_number')
    penalty = int(request.GET.get('penalty'))

    event = EventDAO().get(event_id, fetch_competitors=True)

    f3f_round = RoundDAO().get_from_ids(event.id,
                                        round_number,
                                        fetch_runs=True)

    competitor = event.competitors[int(bib_number)]

    f3f_round.give_penalty(competitor, penalty)

    RoundDAO().update(f3f_round)

    return HttpResponseRedirect('manage_round?event_id=' + event_id +
                                '&round_number=' + round_number)
Пример #9
0
def give_refly(request):
    if not request.user.is_authenticated:
        return redirect('%s?next=%s' % ('sign_in', request.path))

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

    event_id = request.GET.get('event_id')
    round_number = request.GET.get('round_number')
    bib_number = request.GET.get('bib_number')

    event = EventDAO().get(event_id, fetch_competitors=True)

    f3f_round = RoundDAO().get_from_ids(event.id,
                                        round_number,
                                        fetch_runs=True)

    competitor = event.competitors[int(bib_number)]

    f3f_run = f3f_round.get_valid_run(competitor)

    if f3f_run is not None:
        #If there is no valid flight, just add the pilot in the waiting list
        f3f_run.valid = False

    f3f_round.give_refly(competitor)

    return HttpResponseRedirect('manage_round?event_id=' + event_id +
                                '&round_number=' + round_number)
Пример #10
0
 def get_from_ids(self, event_id, round_number, fetch_runs=False):
     from F3FChrono.data.dao.EventDAO import EventDAO
     from F3FChrono.data.Round import Round
     event = EventDAO().get(event_id, fetch_competitors=fetch_runs)
     f3f_round = Round()
     f3f_round.event = event
     f3f_round.round_number = round_number
     return self.get(f3f_round, fetch_runs)
Пример #11
0
def remove_competitor(request):
    if not request.user.is_authenticated:
        return redirect('%s?next=%s' % ('sign_in', request.path))

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

    event_id = request.GET.get('event_id')
    bib_number = request.GET.get('bib_number')

    event = EventDAO().get(event_id, fetch_competitors=True)

    dao = CompetitorDAO()
    competitor = dao.get(event, bib_number)

    event.unregister_competitor(competitor, insert_database=True)

    return HttpResponseRedirect('manage_event?event_id=' + event_id)
Пример #12
0
def export_event_f3x_vault(request):
    if not request.user.is_authenticated:
        return redirect('%s?next=%s' % ('sign_in', request.path))

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

    event_id = request.GET.get('event_id')

    if ('username' in request.POST) and ('password' in request.POST):

        f3x_username = request.POST["username"]
        f3x_password = request.POST["password"]

        event = EventDAO().get(event_id,
                               fetch_competitors=True,
                               fetch_rounds=True,
                               fetch_runs=True)
        event.export_to_f3x_vault(f3x_username, f3x_password)

    return HttpResponseRedirect('manage_event?event_id=' + event_id)
Пример #13
0
def main():

    #logging.basicConfig (filename="runchrono.log", level=logging.DEBUG, format='%(asctime)s %(message)s', datefmt='%m/%d/%Y %I:%M:%S %p')
    if is_running_on_pi():
        print("warm-up 2 seconds...")
        time.sleep(2.0)

    webserver_process = None

    if ConfigReader.config.conf['run_webserver']:
        Utils.set_port_number(ConfigReader.config.conf['webserver_port'])
        if Utils.server_alive():
            print('Webserver already running.')
        else:
            print("Starting webserver ...")
            manage_py_path = os.path.realpath('F3FChrono/web')
            webserver_process = \
                subprocess.Popen(['python3', os.path.join(manage_py_path, 'manage.py'), 'runserver', '0.0.0.0:'
                                  +str(ConfigReader.config.conf['webserver_port'])],
                                 shell=False)

    print("...start")

    dao = EventDAO()
    chronodata = Chrono()

    app = QtWidgets.QApplication(sys.argv)
    ui = MainUiCtrl(dao,
                    chronodata,
                    rpi=is_running_on_pi(),
                    webserver_process=webserver_process)

    if not os.path.isfile('voltage_log.txt'):
        MainUiCtrl.startup_time = time.time()
    else:
        with open("voltage_log.txt", "r") as file:
            first_line = file.readline()
            MainUiCtrl.startup_time = float(first_line.split(',')[0])

    #launched simulate mode
    if (ConfigReader.config.conf['simulatemode']):
        ui_simulate = SimulateBase()
        ui_simulate.close_signal.connect(ui.MainWindow.close)
        ui.close_signal.connect(ui_simulate.MainWindow.close)

    try:
        sys.exit(app.exec_())

    except KeyboardInterrupt:
        pass
    finally:
        pass
Пример #14
0
def index(request):
    if not request.user.is_authenticated:
        return redirect('%s?next=%s' % ('sign_in', request.path))

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

    dao = EventDAO()

    events = dao.get_list()

    page = ResultPage(title='F3F RACE MNGT Administration',
                      authenticated=request.user.is_authenticated)

    table = ResultTable(title='', css_id='ranking')

    header = Header(name=Link('Create new event', 'create_new_event'))
    table.set_header(header)

    page.add_table(table)

    table = ResultTable(title='Manage existing event', css_id='ranking')

    header = Header(name=Cell('Event Name'))
    table.set_header(header)

    for event in events:
        fetched_event = dao.get(event.id)
        row = Line(name=Link(fetched_event.name, 'manage_event?event_id=' +
                             str(fetched_event.id)))
        row.add_cell(Cell(fetched_event.location))
        row.add_cell(Cell(str(fetched_event.begin_date)))
        row.add_cell(Cell(str(fetched_event.end_date)))
        table.add_line(row)

    page.add_table(table)

    return HttpResponse(page.to_html())
Пример #15
0
def set_competitor_presence(request):
    if not request.user.is_authenticated:
        return redirect('%s?next=%s' % ('sign_in', request.path))

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

    event_id = request.GET.get('event_id')
    bib_number = request.GET.get('bib_number')
    present = bool(int(request.GET.get('present')))

    event = EventDAO().get(event_id)

    dao = CompetitorDAO()

    competitor = dao.get(event, bib_number)

    competitor.present = present

    dao.update(competitor)

    return HttpResponseRedirect('manage_event?event_id=' + event_id)
Пример #16
0
def main():
    ConfigReader.init()
    ConfigReader.config = ConfigReader.Configuration('../../config.json')
    dao = EventDAO()
    chronodata = Chrono()
    app = QtWidgets.QApplication(sys.argv)
    ui = MainUiCtrl(dao, chronodata, "")

    # launched simulate mode
    if (ConfigReader.config.conf['simulate']):
        ui_simulate = SimulateBase()
        ui_simulate.close_signal.connect(ui.MainWindow.close)
        ui.close_signal.connect(ui_simulate.MainWindow.close)

    try:
        # writer.setupDecoder()
        print("lancement IHM")
        sys.exit(app.exec_())

    except KeyboardInterrupt:
        pass
    finally:
        pass
Пример #17
0
def load_from_scratch(request):
    if not request.user.is_authenticated:
        return redirect('%s?next=%s' % ('sign_in', request.path))

    Utils.set_port_number(request.META['SERVER_PORT'])
    try:
        csv_file = request.FILES["csv_file"]
        event_name = request.POST["eventname"]
        event_location = request.POST["eventlocation"]
        event_start_date = request.POST["startdate"]
        event_end_date = request.POST["enddate"]

        event = Event.from_csv(event_name, event_location, event_start_date,
                               event_end_date, csv_file)

        event.id = EventDAO().insert(event)

        for bib, competitor in event.get_competitors().items():
            CompetitorDAO().insert(competitor)

        return redirect('index')

    except Exception as e:
        return HttpResponse('<p>Invalid parameters !')
Пример #18
0
def event_view_html(event_id):

    event = EventDAO().get(event_id=event_id,
                           fetch_competitors=True,
                           fetch_rounds=True,
                           fetch_runs=True)

    page = ResultPage(title=event.name)

    if event.current_round is not None:
        table = ResultTable('Ongoing round :', css_id='ranking')
        header = Header(name=Link(
            'Round ' +
            str(len(event.valid_rounds) + 1), 'round_view?event_id=' +
            str(event_id) + '&round_number=' +
            str(event.get_current_round().round_number)))
        table.set_header(header)
        page.add_table(table)

    if len(event.valid_rounds) > 0:
        event.compute_ranking()

        warning = HTMLText(
            'WARNING : These results are not official. '
            'They are based on raw data and does not have been validated')

        page.add_text(warning)

        #Evolutive ranking table
        table = ResultTable(title='Evolutive ranking', css_id="ranking")
        header = Header(name=Cell('Rank'))
        header.add_cell(Cell('Bib'))
        header.add_cell(Cell('Points'))
        header.add_cell(Cell('Points / 1000'))
        header.add_cell(Cell('Name'))
        for f3f_round in event.valid_rounds:
            header.add_cell(
                Link(
                    f3f_round.display_name(),
                    'round_view?event_id=' + str(event_id) + '&round_number=' +
                    str(f3f_round.round_number)))
        table.set_header(header)

        best_score = None
        for competitor in sorted(
            [competitor for bib, competitor in event.competitors.items()],
                key=lambda c: c.rank):
            row = Line(name=Cell('{:2d}'.format(int(competitor.rank))))
            row.add_cell(Cell(str(competitor.bib_number)))
            competitor_score = competitor.score_with_jokers(
                len(event.valid_rounds))
            row.add_cell(Cell('{:6.2f}'.format(competitor_score)))
            if best_score is None:
                best_score = competitor_score
            row.add_cell(
                Cell('{:2d}'.format(int(competitor_score / best_score *
                                        1000))))
            row.add_cell(Cell(competitor.pilot.to_string()))
            for f3f_round in event.valid_rounds:
                competitor_rank = int(
                    competitor.evolutive_rank[f3f_round.valid_round_number -
                                              1])
                row.add_cell(
                    Cell('{:2d}'.format(competitor_rank),
                         css_id=get_cell_css_id(competitor_rank)))
            table.add_line(row)

        page.add_table(table)

        # Round scores table
        table = ResultTable(title='Round scores', css_id="ranking")
        header = Header(name=Cell('Bib'))
        header.add_cell(Cell('Name'))
        for f3f_round in event.rounds:
            if f3f_round.valid:
                header.add_cell(
                    Link(
                        f3f_round.display_name(),
                        'round_view?event_id=' + str(event_id) +
                        '&round_number=' + str(f3f_round.round_number)))
        table.set_header(header)

        for competitor in sorted(
            [competitor for bib, competitor in event.competitors.items()],
                key=lambda c: c.bib_number):
            row = Line(name=Cell(str(competitor.bib_number)))
            row.add_cell(Cell(competitor.pilot.to_string()))
            for f3f_round in event.valid_rounds:
                round_group = f3f_round.find_group(competitor)
                if round_group is not None:
                    run = round_group.get_valid_run(competitor)
                    if run is None:
                        score = 0
                    else:
                        score = run.score
                else:
                    score = 0
                winner = score >= 1000
                joker = (event.number_of_valid_rounds >= event.first_joker_round_number and
                         f3f_round.valid_round_number == competitor.first_joker_round_number) \
                        or \
                        (event.number_of_valid_rounds >= event.second_joker_round_number and
                         f3f_round.valid_round_number == competitor.second_joker_round_number)

                row.add_cell(
                    Cell('{:2d}'.format(int(score)),
                         joker=joker,
                         winner=winner))
            table.add_line(row)

        page.add_table(table)

    result = page.to_html()

    return result
Пример #19
0
from F3FChrono.data.Event import Event
from F3FChrono.data.dao.EventDAO import EventDAO
from F3FChrono.data.dao.CompetitorDAO import CompetitorDAO
from F3FChrono.data.dao.RoundDAO import RoundDAO

login = input('F3X Vault login : '******'F3X Vault password : '******'Import finished')
Пример #20
0
def manage_event(request):
    if not request.user.is_authenticated:
        return redirect('%s?next=%s' % ('sign_in', request.path))

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

    event_id = request.GET.get('event_id')

    event = EventDAO().get(event_id=event_id,
                           fetch_competitors=True,
                           fetch_rounds=True,
                           fetch_runs=True)

    page = ResultPage(title=event.name,
                      authenticated=request.user.is_authenticated)

    table = ResultTable(title='', css_id='ranking')

    header = Header(name=Link('Delete event', 'delete_event?event_id=' +
                              event_id))
    table.set_header(header)

    page.add_table(table)

    table = ResultTable(title='', css_id='ranking')

    header = Header(name=Link(
        'Export to F3X Vault', 'login_to_export_event_f3x_vault?event_id=' +
        event_id))
    table.set_header(header)

    page.add_table(table)

    table = ResultTable(title='Pilots', css_id="ranking")
    header = Header(name=Cell('Bib'))
    header.add_cell(Cell('Name'))
    header.add_cell(Cell(''))
    header.add_cell(Cell(''))
    table.set_header(header)

    for competitor in sorted(
        [competitor for bib, competitor in event.competitors.items()],
            key=lambda c: c.bib_number):
        row = Line(name=Cell(str(competitor.bib_number)))
        row.add_cell(Cell(competitor.display_name()))
        if not event.has_run_competitor(competitor):
            row.add_cell(
                Link(
                    'Remove', 'remove_competitor?event_id=' + str(event.id) +
                    '&bib_number=' + str(competitor.bib_number)))
        else:
            row.add_cell(Cell(''))
        if competitor.present:
            row.add_cell(
                Link(
                    'Set not present', 'set_competitor_presence?event_id=' +
                    str(event.id) + '&bib_number=' +
                    str(competitor.bib_number) + '&present=0'))
        else:
            row.add_cell(
                Link(
                    'Set present', 'set_competitor_presence?event_id=' +
                    str(event.id) + '&bib_number=' +
                    str(competitor.bib_number) + '&present=1'))
        table.add_line(row)
    page.add_table(table)

    table = ResultTable(title='', css_id='ranking')

    header = Header(name=Link('Add new pilot', 'new_pilot_input?event_id=' +
                              event_id))
    table.set_header(header)

    page.add_table(table)

    table = ResultTable(title='Rounds', css_id="ranking")
    header = Header(name=Cell('Round number'))
    header.add_cell(Cell(''))
    header.add_cell(Cell(''))
    table.set_header(header)

    for f3f_round in event.rounds:
        row = Line(name=Link(str(f3f_round.display_name()),
                             'manage_round?event_id=' + str(event.id) +
                             '&round_number=' + str(f3f_round.round_number),
                             new_tab=True))
        row.add_cell(
            Link(
                'Export to csv', 'download_csv?event_id=' + str(event.id) +
                '&round_number=' + str(f3f_round.round_number)))
        row.add_cell(
            Link(
                'Export to F3XVault',
                'login_to_export_round_f3x_vault?event_id=' + str(event.id) +
                '&round_number=' + str(f3f_round.round_number)))
        if f3f_round.valid:
            row.add_cell(
                Link(
                    'Cancel Round', 'cancel_round?event_id=' + str(event.id) +
                    '&round_number=' + str(f3f_round.round_number)))
        else:
            row.add_cell(
                Link(
                    'Validate Round',
                    'validate_round?event_id=' + str(event.id) +
                    '&round_number=' + str(f3f_round.round_number)))
        table.add_line(row)
    page.add_table(table)

    return HttpResponse(page.to_html())