def performWithJSON(self, masteryId, json=None, user=None): """ Create an answer for the mastery """ result = self.grade(json) mastery = Mastery.query.filter_by(id=masteryId).first() mastery.addAnswer(result.correct) formInfo = WordInfo if mastery.word_id is not None else SymbolInfo learnedCache = LearnedCache(user, formInfo) user.tryToLearn(mastery.form, formInfo, learnedCache) return {'results': toJson(result), 'rating': mastery.rating}
def performWithJSON(self, languageId, json=None, user=None): """ Convert the quiz to JSON """ languageContext = BuildLanguageContext(languageId, user) quiz, masteryCache = RandomQuizFactory.buildQuiz( self.formInfo, user, languageContext) learnedCache = LearnedCache(user, self.formInfo) return { "quiz": toJson(quiz, user=user, learnedCache=learnedCache, masteryCache=masteryCache) }
def performWithJSON(self, languageId, json=None, user=None): """ Convert the quiz to JSON """ languageContext = BuildLanguageContext(languageId, user) uniqueForms = self.getUniqueConcepts(json['text'], languageContext) matchingHelper = PrequeriedFormsHelper(uniqueForms, WordInfo, languageContext) pairs = matchingHelper.getConceptPairs() masteryCache = BuildMasteryCache.ViaPairs(pairs, WordInfo, user) learnedCache = LearnedCache(user, WordInfo) return { "results": toJson(pairs, user=user, learnedCache=learnedCache, masteryCache=masteryCache) }
def performWithJSON(self, languageId, json=None, user=None): """ Convert the quiz to JSON """ languageContext = BuildLanguageContext(languageId, user) learnedForms = user.getLearnedFor(self.formInfo, languageContext.foreign) learnedFormsHelper = PrequeriedFormsHelper(learnedForms, self.formInfo, languageContext) pairs = learnedFormsHelper.getConceptPairs() masteryCache = BuildMasteryCache.ViaPairs(pairs, self.formInfo, user) learnedCache = LearnedCache(user, self.formInfo) return { "concepts": toJson(pairs, user=user, learnedCache=learnedCache, masteryCache=masteryCache), "isWords": self.formInfo.formModel is Word }
def performWithJSON(self, languageId, json=None, user=None): """ Convert the existing Concept Lists to JSON """ languageContext = BuildLanguageContext(languageId, user) conceptListHelper = ConceptListQueryHelper( self.formInfo, user, self.formInfo.listModel.query, languageContext) masteryCache = BuildMasteryCache.ViaForms( conceptListHelper.foreignForms, self.formInfo, user) boundLists = conceptListHelper.bound_lists learnedCache = LearnedCache(user, self.formInfo) return { "lists": toJson([ boundList for boundList in boundLists if len(boundList.concepts) > 0 ], user=user, learnedCache=learnedCache, masteryCache=masteryCache) }
def performWithJSON(self, languageId, listId, json=None, user=None): """ Convert the quiz to JSON """ languageContext = BuildLanguageContext(languageId, user) conceptListHelper = ConceptListQueryHelper( self.formInfo, user, self.formInfo.listModel.query.filter_by(id=listId), languageContext) boundList = conceptListHelper.bound_lists[0] masteryCache = BuildMasteryCache.ViaPairs(boundList.concepts, self.formInfo, user) learnedCache = LearnedCache(user, self.formInfo) quiz = Quiz(boundList.name, boundList.concepts, masteryCache) return { "quiz": toJson(quiz, user=user, learnedCache=learnedCache, masteryCache=masteryCache) }
def performWithJSON(self, wordId, json=None, user=None): """ Mark a word as learned by the current user """ word = Word.query.filter_by(id=wordId).first() learnedCache = LearnedCache(user, WordInfo) user.tryToLearn(word, WordInfo, learnedCache) return {"word": toJson(word, user=user, learnedCache=learnedCache)}