def add_com(args): """ Add a single question and answer """ deck = Deck(args.word_file) deck.add_card(args.q, args.ans) print("Question {0} added to {1}".format(args.q, args.word_file))
def test_com(args): files = args.files n_words = args.nwords test_words = get_test_words(args.word_file, files, n_words) save_selected_words = do_test(test_words) deck = Deck(args.word_file) deck.save_words(save_selected_words)
def get_test_words(test_file, files, n_words): test_words = Deck(test_file).get_active_cards() wl = [] for afile in files: wordslist = Deck(afile).cards sl = np.random.choice(wordslist, size=n_words, replace=False) wl.extend(sl) test_words = get_unique_words(wl, test_words) print("{} words selected for test".format(len(test_words))) return test_words
def check_next_active(fname, num=2): if not is_time_to_add_words(fname): return deck = Deck(fname) selected_word = deck.get_inactive_cards() if len(selected_word) > num: selected_word = selected_word[:num] for word in selected_word: word.toggle_active() word.reset_date() deck.save_words(selected_word)
def study_com(args): """ Study command to study n number of words """ deck = Deck(args.word_file) # selected_word = [word for word in wordslist if word.active is False] selected_word = deck.get_inactive_cards() if selected_word: for word in selected_word[:args.nwords]: word.toggle_active() word.reset_date() question = _change_question(word.question) print("\n", word.question) _say(question, 3) print("\t\t", word.answer.upper()) _say(word.answer, 2) deck.save_words(selected_word)
def print_next_review_day(fname): next_due_date = Deck(fname).get_next_review_day() text_msg = "Next review in {}".format( format_timedelta(next_due_date - datetime.now())) print(text_msg) if "-" not in text_msg: _say(text_msg) else: _say("Next Review is Now.") review_words(fname)
def _launch_app(fname, mode="write"): global deckapp eel.init(get_webpath()) fname = Path(fname).resolve() deckapp = Deck(fname) mode_val = "different.html" win_size = (620, 550) if mode.lower() == "read": mode_val = "flipbook.html" win_size = (350, 500) try: eel.start(mode_val, size=win_size, close_callback=handle_exit) except (SystemExit, MemoryError, KeyboardInterrupt): # We can do something here if needed # But if we don't catch these safely, the script will crash pass print('This is printed when the window is closed!')
def review_words(word_file, nmax=30): deck = Deck(word_file) sel_words = deck.get_due_cards() no_words = len(sel_words) # if more than 15 words, show only 10-15 words if no_words > nmax: sel_words = sel_words[:np.random.randint(int(nmax / 2), nmax - 1)] if sel_words: try: words_done = do_review(sel_words) deck.save_words(words_done) check_next_active(word_file) except Exception as ex: print(ex) deck.save_words(sel_words) raise print_next_review_day(word_file) else: check_next_active(word_file) print_next_review_day(word_file)
# self.selected_words.append(i) # np.random.shuffle(self.selected_words) # return self.data[self.selected_words] # def save_words(self, jdeck): # words = [] # for a in jdeck: # words.append([a["sound"], a["picture"], str(a["num"]), str(a["active"])]) # for word in words: # for d in self.data: # if word[0] == d[0]: # d[2] = int(word[2]) # header="question,answer,num,active" # np.savetxt(self.fname, self.data, fmt="%s,%s,%i,%s",header=header, comments="") deckapp = Deck("words.csv") def selectwords(data): rdata = [] for d in data: rdata.append([d.question, d.answer, d.num, d.active]) random.shuffle(rdata) return rdata @eel.expose def handle_exit(ar1, ar2): import sys sys.exit(0)
import argparse from fill_in.deck_cards import Deck import numpy as np import datetime import os parser = argparse.ArgumentParser(description="Take test") parser.add_argument("fname", type=str) parser.add_argument("-n", "--nwords", type=int, default=10) args = parser.parse_args() deck = Deck(args.fname) cards = deck.cards words = np.random.choice(cards, size=args.nwords, replace=False) fname = "Hindi_test_{}.txt".format( datetime.datetime.strftime(datetime.datetime.now(), '%d_%m_%y_%H_%M')) with open(fname, "w") as fout: fout.write("Answer the following questions\n") for i, aword in enumerate(words, 1): fout.write("{0}. {1}\n".format(i, aword.question)) fout.write(" \n" * 20) fout.write("Answers\n") for i, aword in enumerate(words, 1): fout.write("{0}. {1}\n".format(i, aword.answer)) os.system("open {}".format(fname))
import eel import numpy as np import io import json from fill_in.deck_cards import Deck, Card eel.init("web") deckapp = Deck("german.csv") def selectwords(data): rdata = [] for d in data: rdata.append([d.question, d.answer, d.num, d.active]) np.random.shuffle(rdata) return rdata @eel.expose def handle_exit(ar1, ar2): import sys sys.exit(0) @eel.expose def get_words(): ddata = deckapp.get_due_cards() print("{} words selected".format(len(ddata))) deckapp.ddata = ddata data = selectwords(ddata)
def get_no_of_words(args): # wordslist = get_words(args.word_file) sw = Deck(args.word_file).get_due_cards() n_words = len(sw) if n_words: notify(n_words, args.word_file)
def is_time_to_add_words(fname): next_due_date = Deck(fname).get_next_review_day() seconds_to_next_review = next_due_date - datetime.now() # check if the time has past 5 hours return seconds_to_next_review.seconds >= 60 * 60 * 5
def import_com(args): deck = Deck(args.word_file) deck.import_cards(args.text_file)