From 8b170c32643e67fed64fa1cf76d711fd1c878145 Mon Sep 17 00:00:00 2001 From: Nathan Cannon Date: Wed, 23 Dec 2015 23:16:26 +0000 Subject: [PATCH] Kanji and Vocab responses now have separate items for kana and meaning rather than both in one. --- static/quiz_item.coffee | 3 +-- static/quiz_item.js | 3 +-- wanikaniburned.py | 28 ++++++++++++++++------------ 3 files changed, 18 insertions(+), 16 deletions(-) diff --git a/static/quiz_item.coffee b/static/quiz_item.coffee index ed7d58d..df9c60d 100644 --- a/static/quiz_item.coffee +++ b/static/quiz_item.coffee @@ -23,9 +23,8 @@ refreshQuestion = () -> else document.body.style.backgroundColor = "darkviolet"; $("#question-area").text(selection['question']); - if(Math.random() >= 0.5) # Random chance of asking for the kana or meaning + if(selection['answer_type'] == 'romaji') $("#kana").attr("placeholder", "Meaning") - $('#answer').text(selection['answer_meaning']); wanakana.unbind(input_element); else $("#kana").attr("placeholder", "かな") diff --git a/static/quiz_item.js b/static/quiz_item.js index 34388c8..fbf2b26 100644 --- a/static/quiz_item.js +++ b/static/quiz_item.js @@ -30,9 +30,8 @@ document.body.style.backgroundColor = "darkviolet"; } $("#question-area").text(selection['question']); - if (Math.random() >= 0.5) { + if (selection['answer_type'] === 'romaji') { $("#kana").attr("placeholder", "Meaning"); - $('#answer').text(selection['answer_meaning']); return wanakana.unbind(input_element); } else { $("#kana").attr("placeholder", "かな"); diff --git a/wanikaniburned.py b/wanikaniburned.py index 2f2696d..310a927 100644 --- a/wanikaniburned.py +++ b/wanikaniburned.py @@ -118,25 +118,29 @@ def get_items_with_level_restriction(level_range, item_state, item_types): loads = json.loads if 'radical' in item_types: items.extend({'item_type': 'radical', 'answer': item['meaning'], 'question': item['image'] - if item['image'] else item['character']} for item in loads(current_user.radicals) + if item['image'] else item['character']} for item in loads(current_user.radicals) if item['user_specific'] and item['user_specific']['srs'] in item_state and item['level'] in level_range) radical_count = len(items) kanji_count = 0 if 'kanji' in item_types: - items.extend({'item_type': 'kanji', 'question': item['character'], - 'answer': combine_onyomi_and_kunyomi(item['onyomi'], item['kunyomi']), - 'answer_meaning': item['meaning']} for item in loads(current_user.kanji) - if item['user_specific'] and item['user_specific']['srs'] in item_state - and item['level'] in level_range) - kanji_count = len(items) - radical_count + for item in filter((lambda x: x['user_specific'] and x['user_specific']['srs'] in item_state + and x['level'] in level_range), loads(current_user.kanji)): + items.extend([{'item_type': 'kanji', 'question': item['character'], + 'answer': combine_onyomi_and_kunyomi(item['onyomi'], item['kunyomi']), + 'answer_type': 'kana'}, + {'item_type': 'kanji', 'question': item['character'], 'answer': item['meaning'], + 'answer_type': 'romaji'}]) + kanji_count = (len(items) - radical_count) / 2 vocabulary_count = 0 if 'vocab' in item_types: - items.extend({'item_type': 'vocabulary', 'question': item['character'], 'answer': item['kana'], - 'answer_meaning': item['meaning']} for item in loads(current_user.vocabulary) - if item['user_specific'] and item['user_specific']['srs'] in item_state - and item['level'] in level_range) - vocabulary_count = len(items) - (radical_count + kanji_count) + for item in filter((lambda x: x['user_specific'] and x['user_specific']['srs'] in item_state + and x['level'] in level_range), loads(current_user.vocabulary)): + items.extend([{'item_type': 'vocabulary', 'question': item['character'], 'answer': item['kana'], + 'answer_type': 'kana'}, + {'item_type': 'vocabulary', 'question': item['character'], + 'answer': item['meaning'], 'answer_type': 'romaji'}]) + vocabulary_count = (len(items) - (radical_count + kanji_count)) / 2 if not items: return flask.jsonify(error="No items within these filter parameters") else: