def predQ3(update: Update, context: CallbackContext): group_ans = [] diff = [] stan = [] user = update.message.from_user logger.info("Pred Q3 to %s", user.first_name) reply_keyboard = [['다음']] info_file = open('info.csv', 'r', encoding='utf-8', newline='') reader = csv.reader(info_file) for line in reader: if (int(line[0]) == update.effective_chat.id): [age, gender, job] = line[1:4] temp_list = list(map(int, line[-1][1:-1].split(', '))) compQ = temp_list[2] Q = dilemma.q_out(temp_list[5]) break info_file.close() data_file_name = 'answers/' + age + '_' + gender + '_' + job + '.csv' data_file = open(data_file_name, 'r', encoding='utf-8', newline='') reader = csv.reader(data_file) for line in reader: if (int(line[0]) == compQ): if (int(line[1]) == update.effective_chat.id): diff.append(int(line[2])) continue else: stan.append(int(line[2])) continue if ((int(line[0]) == temp_list[5]) and (int(line[1]) != update.effective_chat.id)): group_ans.append(int(line[2])) continue data_file.close() if ((len(group_ans) == 0) or (len(stan) == 0)): Q += '\n\n아직 ' + age + ' ' + gender + ' ' + job + '의 답변이 충분하지 않아 점수 예측을 제공하지 못하고 있습니다. 감사합니다.' else: difference = (sum(stan) / len(stan)) - (sum(diff) / len(diff)) group_avg = sum(group_ans) / len(group_ans) pred = group_avg - difference if (pred < 1): pred = 1.00 elif (pred > 5): pred = 5.00 else: pred = round(pred, 2) Q += '\n\n이 문제에 대한 당신의 예상 답변은 ' + str(pred) + '점입니다.' update.message.reply_text(Q, reply_markup=ReplyKeyboardMarkup( reply_keyboard, one_time_keyboard=True)) return ENDTEST
def askQ1(update: Update, context: CallbackContext): reply_keyboard = [['1', '2', '3', '4', '5']] user = update.message.from_user logger.info("Q1 to %s", user.first_name) info_file = open('info.csv', 'r', encoding='utf-8', newline='') reader = csv.reader(info_file) lines = [] for line in reader: if (int(line[0]) == update.effective_chat.id): line.append(dilemma.ran_qlist()) Q = dilemma.q_out(line[-1][0]) lines.append(line) info_file.close() info_file = open('info.csv', 'w', encoding='utf-8', newline='') writer = csv.writer(info_file) writer.writerows(lines) info_file.close() update.message.reply_text(Q, reply_markup=ReplyKeyboardMarkup( reply_keyboard, one_time_keyboard=True)) return ASKQ2
def askQ3(update: Update, context: CallbackContext): ans = [] user = update.message.from_user logger.info("Q3 to %s", user.first_name) reply_keyboard = [['1', '2', '3', '4', '5']] info_file = open('info.csv', 'r', encoding='utf-8', newline='') reader = csv.reader(info_file) for line in reader: if (int(line[0]) == update.effective_chat.id): [age, gender, job] = line[1:4] temp_list = list(map(int, line[-1][1:-1].split(', '))) preQ = temp_list[1] Q = dilemma.q_out(temp_list[2]) break info_file.close() data_file_name = 'answers/' + age + '_' + gender + '_' + job + '.csv' data_file = open(data_file_name, 'r', encoding='utf-8', newline='') reader = csv.reader(data_file) for line in reader: if ((int(line[0]) == preQ) and (int(line[1]) != update.effective_chat.id)): ans.append(int(line[2])) data_file.close() data_file = open(data_file_name, 'a', encoding='utf-8', newline='') csv.writer(data_file).writerow( [temp_list[1], update.effective_chat.id, update.message.text]) data_file.close() if (len(ans) != 0): avg = round(sum(ans) / len(ans), 2) reply_text = '앞선 문제에 대한 ' + age + ' ' + gender + ' ' + job + '의 평균 답변은 ' + str( avg) + '점이었습니다.' else: reply_text = '아직 앞선 문제에 대한 ' + age + ' ' + gender + ' ' + job + '의 답변이 충분하지 않아 평균 점수를 제공하지 못하고 있습니다. 감사합니다.' update.message.reply_text(reply_text) update.message.reply_text(Q, reply_markup=ReplyKeyboardMarkup( reply_keyboard, one_time_keyboard=True)) return PREDQ1