def delete_participants(): """ Deletes all participants, startlists and results. Categories stay. Function is called by a javascript/jquery """ ParticipantModel.delete_all_rows() StartlistModel.delete_all_rows() StartlistNameModel.delete_all_rows() message = "Deleted all participants, startlists and results" return jsonify(result=message)
def delete_all(): """ Deletes all participants, startlists and results and categories Function is called by a javascript/jquery """ ParticipantModel.delete_all_rows() StartlistModel.delete_all_rows() StartlistNameModel.delete_all_rows() CategoryModel.delete_all_rows() message = "Deleted all data from the Database" return jsonify(result=message)
def wizard_start(): # clearing session counter clearsession() startlist_display = [(st.id, st.name) for st in StartlistNameModel.list_all() if not st.measured_flag] return render_template('startlist/create_new_wizard.html', data=startlist_display)
def create_startlist_classification(): # TODO pass number of athletes in each finished startlist to the template. startlist_finished = [(stlist.id, stlist.name) for stlist in StartlistNameModel.list_measured_all()] return render_template('startlist/create_new_list_classification.html', startlist_finished=startlist_finished)
def rename_startlist_by_id(startlist_id, startlist_new_name): try: startlist_db_object = StartlistNameModel.get_by_id(startlist_id) startlist_db_object.name = startlist_new_name startlist_db_object.save_to_db() return True except: return False
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'))
def startlist_one_delete(): startlist_id = request.form['startlist_select'] startlist_name = StartlistNameModel.get_name_by_id(startlist_id) deleted = startlist_processing.delete_startlist_by_id(startlist_id) startlist_all = [(stlist.id, stlist.name) for stlist in StartlistNameModel.list_all()] if deleted: return render_template( 'startlist/startlist_one_menu_delete_success.html', data=startlist_all, startlist_name=startlist_name) return render_template('startlist/startlist_one_menu_delete_fail.html', data=startlist_all, startlist_name=startlist_name)
def results_specific_startlist(): startlist_id = request.form['startlist_select'] startlist_instance = StartlistNameModel.get_by_id(startlist_id) output_list = startlist_processing.result_list_generate(startlist_id) return render_template('startlist/results_specific_startlist.html', startlist_name=startlist_instance.name, data=output_list)
def results_final(): results = {} startlists_finished = [ (stlist.id, stlist.name) for stlist in StartlistNameModel.list_measured_and_not_final_all() ] for startlist_id, startlist_name in startlists_finished: results[startlist_name] = result_list_generate(startlist_id) return collections.OrderedDict(sorted(results.items()))
def startlist_one(): startlist_id = request.form['startlist_select'] startlist_instance = StartlistNameModel.get_by_id(startlist_id) output_list = startlist_processing.startlist_generate(startlist_id) output_length = startlist_processing.startlist_generate_length( startlist_id) return render_template('startlist/startlist_one.html', startlist_name=startlist_instance.name, data=output_list, length=output_length)
def startlist_one_rename(): startlist_id = request.form['startlist_select'] # for startlist_one_edit_save() session['startlist_id'] = startlist_id # get the startlist name # render form to enter its new name startlist_name = StartlistNameModel.get_name_by_id(startlist_id) return render_template('startlist/startlist_one_rename.html', startlist_name=startlist_name)
def delete_startlist_by_id(startlist_id): try: startlist_records = StartlistModel.get_by_startlist_id(startlist_id) for r in startlist_records: r.delete_from_db() startlist_db_object = StartlistNameModel.get_by_id(startlist_id) startlist_db_object.delete_from_db() # find all instances of the startlistmodel in startlist table # delete them one by one # delete the instance in the startlist model return True except: return False
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'))
def startlist_one_rename_save(): startlist_id = session['startlist_id'] new_startlist_name = request.form['new_startlist_name'] renamed = startlist_processing.rename_startlist_by_id( startlist_id, new_startlist_name) startlist_all = [(stlist.id, stlist.name) for stlist in StartlistNameModel.list_all()] if renamed: return render_template( 'startlist/startlist_one_menu_rename_success.html', data=startlist_all, startlist_name=new_startlist_name) return render_template('startlist/startlist_one_menu_rename_fail.html', data=startlist_all, startlist_name=new_startlist_name)
def startlist_one_edit(): startlist_id = request.form['startlist_select'] # for startlist_one_edit_save() session['startlist_id'] = startlist_id startlist_instance = StartlistNameModel.get_by_id(startlist_id) output_list = startlist_processing.startlist_generate(startlist_id) output_length = startlist_processing.startlist_generate_length( startlist_id) rounds, line_count = startlist_processing.startlist_get_rounds_lines( startlist_id) return render_template('startlist/startlist_one_edit.html', startlist_name=startlist_instance.name, data=output_list, length=output_length, rounds=rounds, line_count=line_count)
def results(): startlist_finished = [(stlist.id, stlist.name) for stlist in StartlistNameModel.list_measured_all()] return render_template('startlist/results_finished_startlists_menu.html', data=startlist_finished)
def startlist_get_rounds_lines(startlist_id): startlist_instance = StartlistNameModel.get_by_id(startlist_id).json() return startlist_instance['startlist_rounds'], startlist_instance[ 'startline_count']
def get_startlist_instances_not_round1(): return [ startlist_def for startlist_def in StartlistNameModel.list_not_round1_all() ]
def get_startlist_instances(): return [startlist_def for startlist_def in StartlistNameModel.list_all()]
def startlist_menu_delete(): startlist_all = [(stlist.id, stlist.name) for stlist in StartlistNameModel.list_all()] return render_template('startlist/startlist_one_menu_delete.html', data=startlist_all)
def wizard(): if request.method == 'POST': try: session['startlist_selected'] = request.form['startlist_select'] except: print("error - method wizard") try: startlist_selected = session['startlist_selected'] except KeyError: return redirect(url_for('.wizard_start')) startlist_instance = StartlistNameModel.get_by_id(startlist_selected) # it does nothing if session['counter'] already exists init_session_counter() if session['counter'] > startlist_instance.startlist_rounds: # indicates that there are times stored in this startlist startlist_instance.measured_flag = True startlist_instance.save_to_db() return redirect(url_for('.wizard_start')) found_records = [ record for record in StartlistModel.get_records_by_startlist_id_and_round_number( startlist_selected, session['counter']) ] startlist_round = [] for stm, ptm in found_records: record = (ptm.last_name, ptm.first_name, stm.start_position, stm.start_round, stm.id) startlist_round.append(record) # to easily receive startlist_id in the next_round() session['startlist_round'] = startlist_round startlist_lines = len(startlist_round) # not used at the moment # random_times = time_random(startlist_lines) # loading of the times from old database # db_times = [str(item.time_measured)[2:-4] for item in TimeDbModel.list_all()][-startlist_lines:] # session['random_times'] = db_times # loading of the times from the external database db_times_ext = [ str(item.time_measured)[2:-4] for item in TimyDbModel.list_all() ][-startlist_lines:] session['random_times'] = db_times_ext progress_now = session[ 'counter'] * 100 / startlist_instance.startlist_rounds progress_now_int = int(round(progress_now)) # Note: Verification if the site has been reloaded due to wrong assignment of startlines by user. # redirected from next_round() function. try: if session['wrong_entry'] == 1: session['wrong_entry'] = 0 return render_template( 'startlist/wizard_wrong_lines_assigned.html', name=startlist_instance.name, startlist=startlist_round, progress_now=progress_now_int, startlist_lines=startlist_lines, random_times=db_times_ext, rounds_count=startlist_instance.startlist_rounds) if session['wrong_entry'] == 2: session['wrong_entry'] = 0 return render_template( 'startlist/wizard_wrong_time_entered.html', name=startlist_instance.name, startlist=startlist_round, progress_now=progress_now_int, startlist_lines=startlist_lines, random_times=db_times_ext, rounds_count=startlist_instance.startlist_rounds) except KeyError: pass return render_template('startlist/wizard.html', name=startlist_instance.name, startlist=startlist_round, progress_now=progress_now_int, startlist_lines=startlist_lines, random_times=db_times_ext, rounds_count=startlist_instance.startlist_rounds)