From 133da4c568658bba87835474e676760973c7aae5 Mon Sep 17 00:00:00 2001 From: janko Date: Sat, 29 Oct 2022 19:50:51 +0200 Subject: [PATCH] added user_id in rated_rated_today_by_status to try to fix a bug, also fixed no collection bug by changing the order of some if statements --- sr_session.py | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/sr_session.py b/sr_session.py index 506f272..65d3ddf 100644 --- a/sr_session.py +++ b/sr_session.py @@ -95,14 +95,17 @@ def list_of_new_cards_by_ids(user_id): #TODO sus ker ni user id? -def rated_today_by_staus (card_status): +def rated_today_by_staus (card_status, user_id): """ Returns number of cards rated today by user by status (new or due) """ dbsession = get_session() today = date.today() - ratings_today = dbsession.query(Rating).filter(Rating.rating_time == today) + ratings_today = dbsession.query(Rating).filter( + Rating.rating_time == today, + Rating.user_id == user_id + ) n = 0 d = 0 for rating in ratings_today: @@ -145,21 +148,25 @@ def schedule_status(user_id): max_new = int(user_settings["max_new"]) max_due = int(user_settings["max_due"]) - rated_new = rated_today_by_staus("new") - rated_due = rated_today_by_staus("due") + rated_new = rated_today_by_staus("new", user_id) + rated_due = rated_today_by_staus("due", user_id) scheduled_new = len(list_of_new_cards_by_ids(user_id)) scheduled_due = len(list_of_due_cards_by_ids(user_id))-scheduled_new #TODO ta problem je mogoče še kje... max_today_new = min(max_new, scheduled_new+rated_new) - max_today_due = min(max_due, scheduled_due+rated_due) + max_today_due = min(max_due, scheduled_due+rated_due) + print("max_new_today", max_today_new) + print("max_due_today", max_today_due) + print("rated_due", rated_due) + print("rated_new", rated_new) - if rated_due+rated_new == 0: + if max_today_due+max_today_new == rated_due+rated_new: + return "done" + elif rated_due+rated_new == 0: return "start" elif max_today_due+max_today_new > rated_due+rated_new: return "continue" - elif max_today_due+max_today_new == rated_due+rated_new: - return "done" else: raise Exception("Arithmetic problem with collection // rated too much?") @@ -215,8 +222,8 @@ def sr_session(): all_new = len(list_of_new_cards_by_ids(user_id)) all_due = len(list_of_due_cards_by_ids(user_id)) - rated_today_new = rated_today_by_staus("new") - rated_today_due = rated_today_by_staus("due") + rated_today_new = rated_today_by_staus("new", user_id) + rated_today_due = rated_today_by_staus("due", user_id) #checks if there are any new/due cards left for today and gets the next one. max can be more than all scheduled, min decides which is the limt.