def translation_frenchword(username): username = User.query.filter_by(username=username).first_or_404() user_id = current_user.get_id() user_status = check_teacher_student(user_id) new_words = list( filter(lambda x: x[1] == 'new' and x[6] is not None, process_user_frenchdict_index(username))) new_words_number = len(new_words) if new_words_number: new_words_for_other_words_sampling = list( filter(lambda x: x[1] == 'new', process_user_frenchdict_index(username))) guess_word = choice(new_words) other_words = [ word[0].word_itself for word in new_words_for_other_words_sampling if word != guess_word ] other_words = sample(other_words, 4) other_words.append(guess_word[0].word_itself) mixture = sorted(other_words, key=lambda x: random()) return render_template('exercises/translation_frenchword.html', guess_word=guess_word[0].translation_rus, new_words_number=new_words_number, mixture=mixture, user_status=user_status) return render_template('exercises/translation_frenchword.html', user_status=user_status)
def user_frenchdict_index(username): username = User.query.filter_by(username=username).first_or_404() search_form = FrenchDictionarySearchForm() title = 'Ваш французский словарь' french_list = process_user_frenchdict_index(username) french_words_sum = len(french_list) user_id = current_user.get_id() user_status = check_teacher_student(user_id) return render_template('dictionary/user_frenchdict_index.html', page_title=title, french_list=french_list, french_list_len=french_words_sum, form=search_form, user=username.username, user_status=user_status)
def remember_frenchword(username): username = User.query.filter_by(username=username).first_or_404() user_id = current_user.get_id() user_status = check_teacher_student(user_id) new_words = list( filter(lambda x: x[1] == 'new' and x[9] is not None, process_user_frenchdict_index(username))) new_words_number = len(new_words) if new_words_number: guess_word = choice(new_words) return render_template('exercises/remember_frenchword.html', guess_word=guess_word[0].word_itself, new_words_number=new_words_number, user_status=user_status) return render_template('exercises/remember_frenchword.html', user_status=user_status)
def insert_frenchword(username): username = User.query.filter_by(username=username).first_or_404() user_id = current_user.get_id() user_status = check_teacher_student(user_id) new_words = list( filter(lambda x: x[1] == 'new' and x[7] is not None, process_user_frenchdict_index(username))) new_words_number = len(new_words) form = InsertWordForm() if new_words_number: guess_word = choice(new_words) return render_template('exercises/insert_frenchword.html', guess_word=guess_word[0].translation_rus, new_words_number=new_words_number, form=form, user_status=user_status) return render_template('exercises/insert_frenchword.html', user_status=user_status)
def difficult_frenchwords_catplot(username): username = User.query.filter_by(username=username).first_or_404() userdict = process_user_frenchdict_index(username) failure_dict = {'слова': [], 'неудачные попытки': []} if userdict: for word in userdict: failures = 0 if word[5]: failures += word[5] if word[6]: failures += word[6] if word[7]: failures += word[7] if word[8]: failures += word[8] if word[9]: failures += word[9] if failures: failure_dict['слова'].append(word[0].word_itself) failure_dict['неудачные попытки'].append(failures) df = pd.DataFrame(failure_dict) df = df.sort_values('неудачные попытки') df = df.tail(20) sns.set(style="ticks", palette="colorblind", font="Arial") difficult_frenchwords = sns.catplot(x="слова", y="неудачные попытки", kind="bar", data=df, height=6, aspect=1) difficult_frenchwords.fig.autofmt_xdate() difficult_frenchwords.set_xticklabels(rotation=90, horizontalalignment='center') plt.savefig( f'webapp/static/progress/difficult_frenchwords_{username.username}.png' ) return f'progress/difficult_frenchwords_{username.username}.png' return None
def frenchword_dataframe(username): username = User.query.filter_by(username=username).first_or_404() userdict = process_user_frenchdict_index(username) if userdict: first_date = userdict[-1][2] today = datetime.now() delta = today - first_date add_data = { 'дни': [], 'добавленные слова за день': [], 'добавленные слова': [], 'изученные слова за день': [], 'изученные слова': [] } for day in range(delta.days + 2): next_day = first_date + timedelta(days=day) date = next_day.strftime('%d.%m.%Y') add_data['дни'].append(next_day) words_der_day, familiar_words_per_day = 0, 0 for word in userdict: if word[2].strftime('%d.%m.%Y') == date: words_der_day += 1 if word[4]: if word[4].strftime('%d.%m.%Y') == date: familiar_words_per_day += 1 add_data['добавленные слова за день'].append(words_der_day) accumulated_words_added = sum( add_data['добавленные слова за день']) add_data['добавленные слова'].append(accumulated_words_added) add_data['изученные слова за день'].append(familiar_words_per_day) accumulated_familiar_words_per_day = sum( add_data['изученные слова за день']) add_data['изученные слова'].append( accumulated_familiar_words_per_day) return (add_data) return {}