Example #1
0
def generate_startlist_category():
    if request.method == 'POST':
        startlist_name = request.form['startlist_name'].strip()

        # startlist name must not be empty
        # this condition can be improved to be more user friendly
        if startlist_name == "":
            return redirect(url_for('.create_startlist_category'))

        startlist_lines = request.form['startlist_lines']
        startlist_category = request.form['startlist_category']

        # print(startlist_name)
        # print(startlist_lines)
        # print(startlist_category)

        new_startlist = StartlistNameModel(startlist_name,
                                           startlist_lines,
                                           round1_flag=True)
        new_startlist.save_to_db()

        # print("Startlist ID: {} - {} - {}".format(new_startlist.id, new_startlist.name, new_startlist.startline_count))

        new_startlist.startlist_rounds = startlist_processing.process(
            new_startlist.id, startlist_category, int(startlist_lines))
        new_startlist.save_to_db()

    return redirect(url_for('.create_startlist_category'))
Example #2
0
def generate_startlist_classfication():
    if request.method == 'POST':
        # print(request.form)

        startlist_finished_id = request.form['startlist_select']
        startlist_name = request.form['startlist_name'].strip()

        if startlist_name == "":
            return redirect(url_for('.create_startlist_classification'))

        startlist_top_times = int(request.form['startlist_top_times'])
        startlist_lines = request.form['startlist_lines']

        new_startlist = StartlistNameModel(startlist_name,
                                           startlist_lines,
                                           round1_flag=False)
        new_startlist.save_to_db()

        # Note: Not used at the moment
        # startlist_finished_instance = StartlistNameModel.get_by_id(startlist_finished_id)

        startlist_finished_results_ordered = \
            [result for result in StartlistModel.get_records_by_startlist_id_order_by_time(startlist_finished_id)]\
            [:startlist_top_times]

        print(startlist_finished_results_ordered)

        # removing Participant objects from a tuples
        # removing Participant objects from a tuples
        # and also ignoring Athletes with the time 59:59.59 - datetime.timedelta(0, 3599, 590000)
        # 59:59.59 means that an athletes is DNF. This form of time has been chosen for code simplicity.
        # At the UZE sprinter event, it is impossible that an athlete will have such a time
        startlist_finished_only_results_ordered = \
            [startlist_record for startlist_record, _ in startlist_finished_results_ordered
                if startlist_record.time_measured != datetime.timedelta(0, 3599, 590000)]

        # In case there is only one classification run, the records are re-ordered so that the fasterst
        # athletes are placed in the middle of the start field.
        if startlist_top_times <= int(startlist_lines):
            startlist_finished_only_results_ordered = startlist_alg.order_from_the_middle(
                startlist_finished_only_results_ordered)

        # generating new startlist record instances, startline numbers and rounds assignment
        new_startlist.startlist_rounds = startlist_processing.process_classification(
            new_startlist.id, startlist_finished_only_results_ordered,
            int(startlist_lines))
        new_startlist.save_to_db()

    return redirect(url_for('.create_startlist_classification'))