def processUserInput(): print("Cheeck user Input api called") uMeaning = request.args.get('userMeaning') uPrc = request.args.get('userPrc') id = request.args.get('id') #get the db word. db = get_db() dbWord = db.execute( 'SELECT * FROM studiedVocab' ' LEFT JOIN coreJpDict ON studiedVocab.dict_id = coreJpDict.id' ' WHERE coreJpDict.id = ?', (id, )).fetchone() print('-----fetching from db...') xd = db.execute( 'SELECT * FROM studiedVocab' ' LEFT JOIN coreJpDict ON studiedVocab.dict_id = coreJpDict.id') for word in xd: print(word.keys()) print(word['id'], word['jpWord'], word['dict_id'], word['meaning']) print("From user printed at backend server--") print(uMeaning) print(uPrc) correct = checkInput(uMeaning, uPrc, dbWord) updateRevisionDB(dbWord, correct) return jsonify({"validInput": correct})
def updateRevisionDB(word, correct): db = get_db() learntDate = word['dateRevised'] currDate = datetime.now() daysElapsed = (currDate - learntDate).days + 1 print("Correct: " + str(correct)) if correct: #*2 our stability. currS = word['stability'] newS = currS * 2 else: #if its wrong, we need to drop the stability so that it pops up slightly more frequently. #we assume that our memory retainment of this word is now 0.05, we get our S accordingly. newS = getS(0.05, daysElapsed) #check whether its revisable. memoryRet = getR(newS, daysElapsed) print("Memory ret: " + str(memoryRet) + " word is: "+ word['jpWord']) if isRevisable(memoryRet): revisable = 1 else: revisable = 0 db.execute( 'UPDATE jpVocab SET stability = ?, revisable = ?' ' WHERE id = ?', (newS, revisable, word['id']) ) db.commit() print("updated db from revision")
def addWord(): if request.method == 'POST': jpWord = request.form['jpWord'] pronunciation = request.form['pronunciation'] meaning = request.form['meaning'] error = None if not jpWord: error = "Please enter a japanese word." if not pronunciation: error = "Please enter the pronunciation" if not meaning: error = "Please enter the meaning" if error is not None: flash(error) else: db = get_db() db.execute( 'INSERT INTO jpVocab (jpWord, pronunciation, meaning)' ' VALUES (?,?,?)', (jpWord, pronunciation, meaning) ) db.commit() return redirect(url_for('main.wordList')) return render_template("main/addWord.html")
def studyTableRecords(): db = get_db() words = db.execute( 'SELECT * FROM studiedVocab' ' LEFT JOIN coreJpDict ON studiedVocab.dict_id = coreJpDict.id' ).fetchall() return render_template('study/studyRecords.html', records=words)
def wordList(): db = get_db() jpWords = db.execute( 'SELECT id, jpWord, pronunciation, meaning, dateRevised FROM jpVocab' ).fetchall() print("JP WORDS LIST: ") for item in jpWords: for x in item: print(x) flash("hi") return render_template('main/wordList.html', jpWords=jpWords)
def getDBWordsForStudy(level): db = get_db() #Select records from coreJpDict that dont exist in studyVocab words = db.execute( 'SELECT * FROM coreJpDict' ' LEFT JOIN studiedVocab ON studiedVocab.dict_id = coreJpDict.id' ' WHERE studiedVocab.dict_id IS NULL').fetchall() if len(words) == 0: return None return words
def getDBWordsForTest(): db = get_db() #get test words. testVocab = db.execute( 'SELECT * FROM jpVocab' ' WHERE revisable = 1' ' ORDER BY stability ASC' ).fetchall() if len(testVocab) == 0: return None return testVocab
def getDBWordsForRevise(level): db = get_db() #get test words. testVocab = db.execute( 'SELECT * FROM studiedVocab' ' LEFT JOIN coreJpDict ON studiedVocab.dict_id = coreJpDict.id' ' WHERE revisable = 1 AND coreJpDict.wordLevel = ?' ' ORDER BY stability ASC', (level, ) ).fetchall() if len(testVocab) == 0: return None return testVocab
def getJpWordInfo(): jpWord = request.args.get('jpWord') db = get_db() dbWord = db.execute( 'SELECT * FROM jpVocab' ' WHERE jpWord = ?', (jpWord, ) ).fetchone() meaning = dbWord['meaning'] prc = dbWord['pronunciation'] print("prc : " +prc) print("meaning: " + meaning) json = jsonify({"meaning":meaning, "prc":prc}) print(json) return json
def clearAllRecords(): db = get_db() db.execute('DELETE FROM jpVocab') db.commit() return redirect(url_for("main.wordList"))
def addStudiedWordToDB(id): db = get_db() db.execute('INSERT INTO studiedVocab (dict_id)' ' VALUES (?)', (id)) db.commit()
def dbRecords(): db = get_db() records = db.execute('SELECT * FROM jpVocab').fetchall() return render_template('main/dbRecords.html', records = records)