fixing bugs...

master
Kostanjevec 2022-08-16 10:50:41 +02:00
parent a9f2a75442
commit ae4077db26
1 changed files with 57 additions and 27 deletions

View File

@ -11,29 +11,34 @@ testing
def autofill_ratings(): def autofill_ratings():
dbsession = get_session() dbsession = get_session()
for i in range(100): for i in range(100):
card = Rating(user_id="1", card_id="10", rating_value=choice(["Yes", "Maybe", "No"]), rating_time=date.today()-timedelta(choice([i for i in range(100)]))) card = Rating(user_id="1", card_id=choice([10, 13, 14, 75]), rating_value=choice(["Maybe", "No"]), rating_time=date.today()-timedelta(choice([i for i in range(100)])))
dbsession.add(card) dbsession.add(card)
dbsession.commit() dbsession.commit()
dbsession.close() dbsession.close()
return None return None
autofill_ratings()
"""
Config
"""
maybe_factor = 1.2
no_factor = 2.1
""" """
Main fuctions Main fuctions
""" """
def calculate_interval(sorted_rates): def calculate_interval(sorted_rates, maybe_factor, no_factor):
maybe_factor = 1.2
no_factor = 2.1
if sorted_rates == []: if sorted_rates == []:
return 1 return 1
elif sorted_rates[0].rating_value == "Yes": elif sorted_rates[0].rating_value == "Yes":
return 1 return 1
elif sorted_rates[0].rating_value == "Maybe": elif sorted_rates[0].rating_value == "Maybe":
sorted_rates.pop(0) sorted_rates.pop(0)
return calculate_interval(sorted_rates) * maybe_factor return calculate_interval(sorted_rates, maybe_factor, no_factor) * maybe_factor
elif sorted_rates[0].rating_value == "No": elif sorted_rates[0].rating_value == "No":
sorted_rates.pop(0) sorted_rates.pop(0)
return calculate_interval(sorted_rates) * no_factor return calculate_interval(sorted_rates, maybe_factor, no_factor) * no_factor
elif sorted_rates[0].rating_value == "Delete": elif sorted_rates[0].rating_value == "Delete":
return -1 #"Deleted" return -1 #"Deleted"
@ -49,10 +54,10 @@ def get_interval(card_id):
print("ni kart... kaj zdaj") #@TODO print("ni kart... kaj zdaj") #@TODO
return None return None
else: else:
interval = calculate_interval(sorted_rates_by_card) interval = calculate_interval(sorted_rates_by_card, maybe_factor, no_factor)
return round(interval) return round(interval)
#to vključuje tudi new...
def is_due(card_id): def is_due(card_id):
dbsession = get_session() dbsession = get_session()
interval = get_interval(card_id) interval = get_interval(card_id)
@ -67,7 +72,7 @@ def is_due(card_id):
return date.today() >= due_date return date.today() >= due_date
def list_of_due_card_by_ids(user_id): def list_of_due_cards_by_ids(user_id):
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 = []
@ -89,21 +94,8 @@ def list_of_new_cards_by_ids(user_id):
dbsession.close() dbsession.close()
return l return l
#obsolete
def make_deck(user_id, max_new, max_due):
due_cards = list_of_due_card_by_ids(user_id)
new_cards = list_of_new_cards_by_ids(user_id)
due_deck = []
due_deck.append(choices(due_cards, k=max_due))
new_deck = []
new_deck.append(choices(new_cards, k=max_new))
deck = new_deck + due_deck
return deck
#TODO sus ker ni user id?
def rated_today_by_staus (card_status): def rated_today_by_staus (card_status):
""" """
Returns number of cards rated today by user by status (new or due) Returns number of cards rated today by user by status (new or due)
@ -140,12 +132,48 @@ def get_a_card_by_status(user_id, card_status):
card_id = l[0] card_id = l[0]
print(l, "00000000" , card_id) print(l, "00000000" , card_id)
if card_status == "due": if card_status == "due":
l = list_of_due_card_by_ids(user_id) l = list_of_due_cards_by_ids(user_id)
card_id = l[0] card_id = l[0]
print(l, "00000000" , card_id) print(l, "00000000" , card_id)
return card_id return card_id
"""
Export functions
"""
def schedule_status(user_id):
"""
Returns information needed for start/continue/done menu ui
"""
user_settings = get_settings(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")
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)
if 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?")
def remaining_by_status(user_id, status):
if status == "new":
l = len(list_of_new_cards_by_ids(user_id))
elif status == "due":
l = len(list_of_due_cards_by_ids(user_id))
return l
""" """
Engine Engine
""" """
@ -190,7 +218,7 @@ def sr_session():
max_due = user_settings["max_due"] max_due = user_settings["max_due"]
all_new = len(list_of_new_cards_by_ids(user_id)) all_new = len(list_of_new_cards_by_ids(user_id))
all_due = len(list_of_due_card_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_new = rated_today_by_staus("new")
rated_today_due = rated_today_by_staus("due") rated_today_due = rated_today_by_staus("due")
@ -206,5 +234,7 @@ def sr_session():
return redirect("/menu") return redirect("/menu")
show_card = dbsession.query(Card).get(new_card_id) show_card = dbsession.query(Card).get(new_card_id)
interval = get_interval(new_card_id)
return render_template("deck.html", username=username, card=show_card) #these factors should be better packaged
return render_template("deck.html", username=username, card=show_card, maybe_in=round(interval*maybe_factor), no_in=round(no_factor*interval))