From 774d269d9168d78dd2fb45e04f1ba6dfdda9a444 Mon Sep 17 00:00:00 2001 From: janko Date: Mon, 31 Oct 2022 18:24:47 +0100 Subject: [PATCH] yet another attempt to fix the scheduling bug --- menu.py | 6 +----- sr_session.py | 19 ++++++++++++++++--- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/menu.py b/menu.py index b29ca02..3a6dc77 100644 --- a/menu.py +++ b/menu.py @@ -17,7 +17,6 @@ def index(): if 'user_id' in session: user_id = session['user_id'] username = session['username'] - print(username) status = schedule_status(user_id) user_settings = get_settings(user_id) @@ -25,7 +24,7 @@ def index(): max_due = int(user_settings["max_due"]) 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_due = rated_today_by_staus("due", user_id) remaining_new_today = remaining_items(max_new, total_new, rated_today_new) @@ -33,13 +32,10 @@ def index(): if request.method == "POST": 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": #preverimo če so sploh karte v collectionu - print("userID", user_id) c = dbsession.query(Card).filter(Card.owner_id == user_id).all() if c == []: - print("ne najdem collectiona") return render_template("error/no_cards_in_collection.html", username=username) return redirect(url_for("deck")) diff --git a/sr_session.py b/sr_session.py index e31e892..aa426e1 100644 --- a/sr_session.py +++ b/sr_session.py @@ -70,13 +70,26 @@ def is_due(card_id): dbsession.close() 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): + "this should not include new cards" dbsession = get_session() cards = dbsession.query(Card).filter(Card.owner_id == user_id).all() l = [] for card in cards: - if is_due(card.id): + if is_new(card.id): + pass + elif is_due(card.id): l.append(card.id) dbsession.close() return l @@ -158,7 +171,7 @@ def schedule_status(user_id): rated_due = rated_today_by_staus("due", 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_due_today = remaining_items(max_due, total_due, rated_due) @@ -222,7 +235,7 @@ def sr_session(): max_due = int(user_settings["max_due"]) 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_due = rated_today_by_staus("due", user_id)