def insertUserChoices(): time_diff = time.time() - session.get( 'start_time_choosing', 0) # user time in the page (including time in other websites) chosen_vacation_id = request.args.get( 'id') # the chosen vacation id number chosen_vacation = getVacationAccordingID( chosen_vacation_id) # can't insert to DB because it's a tuple print("chosenVacID:", chosen_vacation_id) print("chosen_vacation: ", chosen_vacation) recomm_list = session['recomm_list'] vacation_list = session['vacation_list'] choseOptimal = False if session['optimal_id'] == int(chosen_vacation_id): choseOptimal = True # the user chose the optimal vacation vacIndex = -2 # the place of the chosen vacation in the set is_recomm = False # did the user choose one of the recommendations? if chosen_vacation in recomm_list: vacIndex = recomm_list.index(chosen_vacation) is_recomm = True elif chosen_vacation in vacation_list: vacIndex = vacation_list.index(chosen_vacation) vacIndex = vacIndex + 1 # because it starts in 0 print("index: ", vacIndex) print("recomm: ", is_recomm) query = """UPDATE "users" SET "chosen_vac_id" = '%s', "chosen_vac_index" = '%s', "is_optimal" = '%s', "is_recomm" = '%s', "choose_time" = '%s' WHERE "id" = '%s'""" \ % (chosen_vacation_id, vacIndex, choseOptimal, is_recomm, time_diff, session['code']) interact_db(query=query, query_type='commit') return
def insertRanks1(): rank1 = request.args.get('rank1') rank2 = request.args.get('rank2') rank3 = request.args.get('rank3') changeRank = request.args.get('changed') # transferring rank1, rank2, rank3 to each criteria rank # instead of rank2=Sleeping Arrangement, we recieve sleepRank = 2 continentRank = 3 typeRank = 3 sleepRank = 3 if rank1 == "Continent": continentRank = 1 elif rank2 == "Continent": continentRank = 2 if rank1 == "Vacation Type": typeRank = 1 elif rank2 == "Vacation Type": typeRank = 2 if rank1 == "Sleeping Arrangement": sleepRank = 1 elif rank2 == "Sleeping Arrangement": sleepRank = 2 query = """INSERT INTO users(id, "continent_rank", "type_rank", "sleep_rank", "change_rank") VALUES ('%s', '%s', '%s', '%s', '%s') """ \ % (session['code'], continentRank, typeRank, sleepRank, changeRank) interact_db(query=query, query_type='commit') return #no need for render_template or redirect - it doesnt work because of ajax
def user_answer_modal(): if request.method == 'POST': num_of_recomm = request.form['num_of_recomm'] query = """UPDATE "users" SET "user_test_recomm" = '%s' WHERE "id" = '%s'""" % (num_of_recomm, session['code']) interact_db(query=query, query_type='commit') return render_template('questions_1.html', showModal="false") return render_template('questions_1.html', showModal="true")
def insertRanks2(): continentOption = request.args.get('rank1') typeOption = request.args.get('rank2') sleepOption = request.args.get('rank3') query = """UPDATE "users" SET "continent_option" = '%s', "type_option" = '%s', "sleep_option" = '%s' WHERE "id" = '%s'""" % (continentOption, typeOption, sleepOption, session['code']) interact_db(query=query, query_type='commit') return
def end2(): all_time = time.time() - session.get('start_time_experiment', 0) query = """UPDATE "users" SET "exp_time" = '%s' WHERE "id" = '%s'""" \ % (all_time, session['code']) interact_db(query=query, query_type='commit') code = session.get('code', 0) amazon_code = int(code) + 3000 #amazon_code = 1234 return render_template('end.html', amazon_code=amazon_code)
def algo_data1(): if request.method == 'POST': last_vac = request.form['last_vac'] vacs_in_three = request.form['vacs_in_three'] advance_book = request.form['book'] plan = request.form['plan'] query = """UPDATE "users" SET "algo_last_vac" = '%s', "algo_vacs_three" = '%s', "algo_book" = '%s', "algo_plan" = '%s' WHERE "id" = '%s'""" % (last_vac, vacs_in_three, advance_book, plan, session['code']) interact_db(query=query, query_type='commit') return redirect('/ranking_2') return render_template('algo_data.html')
def questions_12(): if request.method == 'POST': age = request.form['age'] gender = request.form['gender'] exp = request.form['experience'] device = request.form['device'] query = """UPDATE "users" SET "age" = '%s', "gender" = '%s', "experience" = '%s', "device" = '%s' WHERE "id" = '%s'""" % (age, gender, exp, device, session['code']) interact_db(query=query, query_type='commit') return redirect('/questions_2') return render_template('questions_1.html', showModal="true")
def questions_22(): if request.method == 'POST': q1 = request.form['q1'] q2 = request.form['q2'] q3 = request.form['q3'] q4 = request.form['q4'] q5 = request.form['q5'] query = """UPDATE "users" SET "q1" = '%s', "q2" = '%s', "q3" = '%s', "q4" = '%s', "q5" = '%s' WHERE "id" = '%s'""" % (q1, q2, q3, q4, q5, session['code']) interact_db(query=query, query_type='commit') return redirect('/end') return render_template('questions_2.html')
def baseFunction(): query = "SELECT * FROM curr_codes" # choose the device for current user - mobile/pc query_result = interact_db(query=query, query_type='fetch') curr_pc_code = query_result[0][0] curr_mobile_code = query_result[0][1] if curr_pc_code - 1000 > curr_mobile_code - 2000: # chosen device: mobile #1000 and 2000 - for start points... curr_code = curr_mobile_code + 1 query = """UPDATE "curr_codes" SET "currMobileCode" = '%s' WHERE "currMobileCode" = '%s'""" % ( curr_mobile_code + 1, curr_mobile_code) interact_db(query=query, query_type='commit') else: # chosen device: pc curr_code = curr_pc_code + 1 query = """UPDATE "curr_codes" SET "currPcCode" = '%s' WHERE "currMobileCode" = '%s'""" % ( curr_pc_code + 1, curr_mobile_code) interact_db(query=query, query_type='commit') curr_code = 1063 ######################## DELEEEEEEEEEEEEETEEEEEEEEEEEEEEEEEEEEE print(curr_code) return render_template("/code", code=curr_code)
def code2(): query = "SELECT * FROM curr_codes" # choose the device for current user - mobile/pc query_result = interact_db(query=query, query_type='fetch') curr_pc_code = query_result[0][0] curr_mobile_code = query_result[0][1] if curr_pc_code - 1000 > curr_mobile_code - 2000: # chosen device: mobile #1000 and 2000 - for start points... curr_code = curr_mobile_code + 1 query = """UPDATE "curr_codes" SET "currMobileCode" = '%s' WHERE "currMobileCode" = '%s'""" % ( curr_mobile_code + 1, curr_mobile_code) interact_db(query=query, query_type='commit') else: # chosen device: pc curr_code = curr_pc_code + 1 query = """UPDATE "curr_codes" SET "currPcCode" = '%s' WHERE "currMobileCode" = '%s'""" % ( curr_pc_code + 1, curr_mobile_code) interact_db(query=query, query_type='commit') print(curr_code) device = "smartphone" if curr_code < 2000: #1000-1999 it's pc user device = "computer" return render_template('code.html', device=device, code=curr_code)
def choosing2(): session['start_time_choosing'] = time.time() print("start_time_choosing:", session['start_time_choosing']) autonomy_lvl = generateAutonomyLvl() query_rec = """SELECT "continent_rank", "type_rank", "sleep_rank", "continent_option", "type_option", "sleep_option" FROM users WHERE "id" = '%s'""" % ( session['code']) user_ranking = interact_db(query=query_rec, query_type='fetch') user_ranking = user_ranking[0] print("user_ranking:", user_ranking, "autonomy level:", autonomy_lvl) if autonomy_lvl == 'low': recomm_list = recommForLowAutonomy(user_ranking) addsIdToVacation else: # autonomy_lvl == 'high' recomm_list = recommForHighAutonomy(user_ranking) vacation_list = createVacationSet(user_ranking, recomm_list) print("vacation list", vacation_list) print("recomm", recomm_list) session['vacation_list'] = vacation_list session['recomm_list'] = recomm_list return render_template('choosing.html', vacation_list=vacation_list, recomm_list=recomm_list)
def addsIdToVacation(vacation): query = """SELECT "vac_id", "continent", "type", "sleep" FROM vacations WHERE "continent" = '%s' AND "type" = '%s' AND "sleep" = '%s'""" % ( vacation[0], vacation[1], vacation[2]) vacationWithId = interact_db(query=query, query_type='fetch') return vacationWithId
def getVacationAccordingID(id): query = """SELECT * FROM vacations WHERE "vac_id" = '%s'""" % (id) vacation = interact_db(query=query, query_type='fetch') return vacation[0]
def generateAutonomyLvl(): currAutonomy = random.choice(['high', 'low']) query = """UPDATE "users" SET "autonomy_lvl" = '%s' WHERE "id" = '%s'""" % (currAutonomy, session['code']) interact_db(query=query, query_type='commit') return currAutonomy
def createVacationSet(user_ranking, recomm_list): set = [] optimal = OptimalVacation(user_ranking) #with id num optimal = optimal[0] set.append(optimal) session['optimal_id'] = optimal[0] query = """SELECT * FROM vacations""" all_vacations = interact_db(query=query, query_type='fetch') random.shuffle(all_vacations) recomm_1 = 1 recomm_2 = 1 recomm_3 = 1 recomm_4 = 1 for vacation in all_vacations: if vacation in recomm_list: all_vacations.remove(vacation) all_vacations_temp = all_vacations.copy() for vacation in all_vacations_temp: if recomm_3 > 5: # 5 recomm that differ in the first and second criterion = same in the third break if validVacationSameInOneElement(user_ranking, vacation, 3): set.append(vacation) all_vacations.remove(vacation) print(" differ in the first and second:", vacation) recomm_3 = recomm_3 + 1 all_vacations_temp = all_vacations.copy() for vacation in all_vacations_temp: if recomm_4 > 5: # 5 recomm that differ in the first and third criterion = same in the second break if validVacationSameInOneElement(user_ranking, vacation, 2): recomm_4 = recomm_4 + 1 set.append(vacation) all_vacations.remove(vacation) print(" differ in the first and third:", vacation) all_vacations_temp = all_vacations.copy() for vacation in all_vacations_temp: if recomm_2 > 5: # 5 recomm that differ in the second and third criterion = same in the first break if validVacationSameInOneElement(user_ranking, vacation, 1): recomm_2 = recomm_2 + 1 set.append(vacation) all_vacations.remove(vacation) print(" differ in the second and third:", vacation) all_vacations_temp = all_vacations.copy() for vacation in all_vacations_temp: if recomm_1 > 2: # 2 recomm that differ in the first criteria break if validVacationDifferInOneElement(user_ranking, vacation, 1): recomm_1 = recomm_1 + 1 set.append(vacation) all_vacations.remove(vacation) print(" differ in the first:", vacation) random.shuffle(set) return set