another attempt at fixing the scheduling bug

master
janko 2022-10-31 17:40:25 +01:00
parent 39e9afda79
commit d53a3dfda0
2 changed files with 40 additions and 34 deletions

19
menu.py
View File

@ -1,8 +1,8 @@
from flask import (
Blueprint, flash, redirect, render_template, request, session, url_for
Blueprint, redirect, render_template, request, session, url_for
)
from create_db import Card, get_session
from sr_session import remaining_by_status, schedule_status
from sr_session import schedule_status, remaining_items, list_of_due_cards_by_ids, list_of_new_cards_by_ids, rated_today_by_staus
from settings import get_settings
from auth import login
@ -19,8 +19,17 @@ def index():
username = session['username']
print(username)
status = schedule_status(user_id)
remaining_new = remaining_by_status(user_id, "new")
remaining_due = remaining_by_status(user_id, "due")-remaining_new
user_settings = get_settings(user_id)
max_new = int(user_settings["max_new"])
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
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)
remaining_due_today = remaining_items(max_due, total_due, rated_today_due)
if request.method == "POST":
action = request.form.get("menu", False) #internetna rešitev, nevem kako, ampak dela, tj. dobi info iz meni buttonov
@ -44,4 +53,4 @@ def index():
elif action == "instructions":
return render_template("instructions.html", username=username, user_id=user_id)
return render_template("menu.html", username=username, deck_status=status, remaining_due=remaining_due, remaining_new=remaining_new)
return render_template("menu.html", username=username, deck_status=status, remaining_due=remaining_due_today, remaining_new=remaining_new_today)

View File

@ -139,6 +139,13 @@ def get_a_card_by_status(user_id, card_status):
"""
Export functions
"""
def remaining_items(max_items, total_queue, rated_today):
"""
gives number of remaining items. Either upto max or if total runs out earlier.
"""
n_of_remaining = min((max_items-rated_today), total_queue)
return n_of_remaining
def schedule_status(user_id):
"""
Returns information needed for start/continue/done menu ui
@ -150,30 +157,19 @@ def schedule_status(user_id):
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...
total_new = len(list_of_new_cards_by_ids(user_id))
total_due = len(list_of_due_cards_by_ids(user_id)) - total_new
remaining_new_today = remaining_items(max_new, total_new, rated_new)
remaining_due_today = remaining_items(max_due, total_due, rated_due)
remaining_total_today = remaining_due_today + remaining_new_today
max_today_new = min(max_new, scheduled_new+rated_new)
max_today_due = min(max_due, scheduled_due+rated_due)
"""print("SCHEDULE STATUS:\n ############################")
print("rated_due", rated_due)
print("rated_new", rated_new)
print("scheduled_due: ", scheduled_due)
print("scheduled_new: ", scheduled_new)
print("max_new_today", max_today_new)
print("max_due_today", max_today_due)"""
if max_today_due+max_today_new == rated_due+rated_new:
if remaining_total_today == 0:
return "done"
elif rated_due+rated_new == 0:
return "start"
elif max_today_due+max_today_new > rated_due+rated_new:
return "continue"
else:
raise Exception("Arithmetic problem with collection // rated too much?")
return "continue"
def remaining_by_status(user_id, status):
if status == "new":
@ -225,22 +221,23 @@ def sr_session():
max_new = int(user_settings["max_new"])
max_due = int(user_settings["max_due"])
all_new = len(list_of_new_cards_by_ids(user_id))
all_due = len(list_of_due_cards_by_ids(user_id)) - all_new
total_new = len(list_of_new_cards_by_ids(user_id))
total_due = len(list_of_due_cards_by_ids(user_id)) - total_new
rated_today_new = rated_today_by_staus("new", user_id)
rated_today_due = rated_today_by_staus("due", user_id)
"""
print("max_due: ", max_due, " all_due", all_due)
print("max_new: ", max_new, " all_new", all_new)
print("rated_today_new: ", rated_today_new)
"""
remaining_new_today = remaining_items(max_new, total_new, rated_today_new)
remaining_due_today = remaining_items(max_due, total_due, rated_today_due)
print("remaining_new_today: ", remaining_new_today)
print("remaining_due_today: ", remaining_due_today)
#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.
if min(max_new-rated_today_new, all_new) > 0:
#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.
if remaining_new_today > 0:
new_card_id=get_a_card_by_status(user_id, "new")
elif min(max_due-rated_today_due, all_due) > 0:
elif remaining_due_today > 0:
new_card_id=get_a_card_by_status(user_id, "due")
else:
dbsession.close()