yet another attempt to fix the scheduling bug

master
janko 2022-10-31 18:24:47 +01:00
parent 8b115c98ad
commit 774d269d91
2 changed files with 17 additions and 8 deletions

View File

@ -17,7 +17,6 @@ def index():
if 'user_id' in session: if 'user_id' in session:
user_id = session['user_id'] user_id = session['user_id']
username = session['username'] username = session['username']
print(username)
status = schedule_status(user_id) status = schedule_status(user_id)
user_settings = get_settings(user_id) user_settings = get_settings(user_id)
@ -25,7 +24,7 @@ def index():
max_due = int(user_settings["max_due"]) max_due = int(user_settings["max_due"])
total_new = len(list_of_new_cards_by_ids(user_id)) total_new = len(list_of_new_cards_by_ids(user_id))
total_due = len(list_of_due_cards_by_ids(user_id)) - total_new total_due = len(list_of_due_cards_by_ids(user_id))
rated_today_new = rated_today_by_staus("new", user_id) rated_today_new = rated_today_by_staus("new", user_id)
rated_today_due = rated_today_by_staus("due", user_id) rated_today_due = rated_today_by_staus("due", user_id)
remaining_new_today = remaining_items(max_new, total_new, rated_today_new) remaining_new_today = remaining_items(max_new, total_new, rated_today_new)
@ -33,13 +32,10 @@ def index():
if request.method == "POST": if request.method == "POST":
action = request.form.get("menu", False) #internetna rešitev, nevem kako, ampak dela, tj. dobi info iz meni buttonov action = request.form.get("menu", False) #internetna rešitev, nevem kako, ampak dela, tj. dobi info iz meni buttonov
print(action)
if action == "new_session": if action == "new_session":
#preverimo če so sploh karte v collectionu #preverimo če so sploh karte v collectionu
print("userID", user_id)
c = dbsession.query(Card).filter(Card.owner_id == user_id).all() c = dbsession.query(Card).filter(Card.owner_id == user_id).all()
if c == []: if c == []:
print("ne najdem collectiona")
return render_template("error/no_cards_in_collection.html", username=username) return render_template("error/no_cards_in_collection.html", username=username)
return redirect(url_for("deck")) return redirect(url_for("deck"))

View File

@ -70,13 +70,26 @@ def is_due(card_id):
dbsession.close() dbsession.close()
return date.today() >= due_date return date.today() >= due_date
def is_new(card_id):
dbsession = get_session()
rating = dbsession.query(Rating).filter(Rating.card_id == card_id).first()
dbsession.close()
if rating == None:
return True
else:
return False
def list_of_due_cards_by_ids(user_id): def list_of_due_cards_by_ids(user_id):
"this should not include new cards"
dbsession = get_session() dbsession = get_session()
cards = dbsession.query(Card).filter(Card.owner_id == user_id).all() cards = dbsession.query(Card).filter(Card.owner_id == user_id).all()
l = [] l = []
for card in cards: for card in cards:
if is_due(card.id): if is_new(card.id):
pass
elif is_due(card.id):
l.append(card.id) l.append(card.id)
dbsession.close() dbsession.close()
return l return l
@ -158,7 +171,7 @@ def schedule_status(user_id):
rated_due = rated_today_by_staus("due", user_id) rated_due = rated_today_by_staus("due", user_id)
total_new = len(list_of_new_cards_by_ids(user_id)) total_new = len(list_of_new_cards_by_ids(user_id))
total_due = len(list_of_due_cards_by_ids(user_id)) - total_new total_due = len(list_of_due_cards_by_ids(user_id))
remaining_new_today = remaining_items(max_new, total_new, rated_new) remaining_new_today = remaining_items(max_new, total_new, rated_new)
remaining_due_today = remaining_items(max_due, total_due, rated_due) remaining_due_today = remaining_items(max_due, total_due, rated_due)
@ -222,7 +235,7 @@ def sr_session():
max_due = int(user_settings["max_due"]) max_due = int(user_settings["max_due"])
total_new = len(list_of_new_cards_by_ids(user_id)) total_new = len(list_of_new_cards_by_ids(user_id))
total_due = len(list_of_due_cards_by_ids(user_id)) - total_new total_due = len(list_of_due_cards_by_ids(user_id))
rated_today_new = rated_today_by_staus("new", user_id) rated_today_new = rated_today_by_staus("new", user_id)
rated_today_due = rated_today_by_staus("due", user_id) rated_today_due = rated_today_by_staus("due", user_id)