2022-05-02 14:20:39 +02:00
|
|
|
from random import randint
|
|
|
|
from numpy.random import choice
|
2022-04-28 18:37:36 +02:00
|
|
|
|
2022-05-02 00:17:32 +02:00
|
|
|
# card = id, title, due, interval, owned_by, shared
|
2022-04-29 16:57:24 +02:00
|
|
|
def generate_card (clltn=[], user="bob", shared=False):
|
|
|
|
id = len(clltn) + 1
|
2022-04-28 18:37:36 +02:00
|
|
|
title = "".join([chr(randint(ord('a'), ord('z'))) for i in range(5)])
|
|
|
|
due = -1 #means new
|
|
|
|
interval = 0
|
2022-05-02 14:20:39 +02:00
|
|
|
|
|
|
|
card = dict()
|
|
|
|
card["id"]= id
|
|
|
|
card["title"] = title
|
|
|
|
card["due"] = due
|
|
|
|
card["interval"] = interval
|
|
|
|
card["owned_by"] = user
|
|
|
|
card["shared"] = shared
|
2022-04-28 18:37:36 +02:00
|
|
|
return card
|
|
|
|
|
2022-05-02 14:20:39 +02:00
|
|
|
def generate_clltn(n_of_cards):
|
2022-05-02 00:17:32 +02:00
|
|
|
clltn = [] #mogoče bi blo dobro met dictionary, sam že štejemo len zgoraj...
|
2022-04-28 18:37:36 +02:00
|
|
|
for n in range(n_of_cards):
|
2022-04-29 16:57:24 +02:00
|
|
|
clltn.append(generate_card(clltn=clltn))
|
2022-04-28 18:37:36 +02:00
|
|
|
return clltn
|
|
|
|
|
2022-04-29 16:57:24 +02:00
|
|
|
##1 SR - super-memo style
|
|
|
|
|
2022-04-28 18:37:36 +02:00
|
|
|
def get_new(user_clltn, n_of_cards):
|
|
|
|
for card in user_clltn:
|
|
|
|
pass
|
|
|
|
|
2022-04-29 16:57:24 +02:00
|
|
|
|
2022-04-28 18:37:36 +02:00
|
|
|
def get_due(user_clltn, n_of_cards):
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
2022-04-29 18:09:54 +02:00
|
|
|
def generate_deck_sr(user_clltn, max_new, max_deck_size):
|
2022-04-28 18:37:36 +02:00
|
|
|
pass
|
|
|
|
|
2022-04-29 16:57:24 +02:00
|
|
|
|
|
|
|
def run_sr():
|
|
|
|
pass
|
2022-04-28 18:37:36 +02:00
|
|
|
|
|
|
|
#2 Probabilistic
|
2022-04-29 18:09:54 +02:00
|
|
|
## problem je, da pri probabilističnem težko nardiš, da pač en dan ni nič v decku, ker pač vedno izbere glede določeno število pač glede na uteži
|
|
|
|
|
2022-04-29 18:55:36 +02:00
|
|
|
def generate_weights(user_clltn):
|
2022-04-29 18:09:54 +02:00
|
|
|
"""generiramo uteži za due in new cards posebej; vrne tuple dveh listov za weightse..."""
|
|
|
|
|
|
|
|
weights_due = []
|
|
|
|
weights_new = []
|
2022-04-29 18:55:36 +02:00
|
|
|
for card in user_clltn:
|
2022-05-02 14:20:39 +02:00
|
|
|
due = card["due"]
|
2022-04-29 18:09:54 +02:00
|
|
|
|
|
|
|
if due > 0:
|
|
|
|
weights_due.append(due)
|
|
|
|
weights_new.append(0)
|
|
|
|
else:
|
|
|
|
weights_due.append(0)
|
|
|
|
weights_new.append(1)
|
|
|
|
|
|
|
|
return weights_new, weights_due
|
2022-04-28 18:37:36 +02:00
|
|
|
|
2022-04-29 18:55:36 +02:00
|
|
|
def generate_deck_prob(user_clltn, max_new, max_due):
|
2022-05-01 18:00:26 +02:00
|
|
|
deck, dck_due, dck_new, due_cards = [], [], [], 0
|
2022-04-29 18:55:36 +02:00
|
|
|
w_new, w_due = generate_weights(user_clltn)
|
|
|
|
|
2022-05-01 18:00:26 +02:00
|
|
|
#treba je sestet non zero weights
|
2022-04-29 18:55:36 +02:00
|
|
|
new_cards = sum(w_new)
|
2022-05-01 18:00:26 +02:00
|
|
|
for w in w_due:
|
|
|
|
if w > 0:
|
|
|
|
due_cards += 1
|
2022-04-29 18:55:36 +02:00
|
|
|
|
|
|
|
#preverimo, če imamo dovolj kartic
|
|
|
|
if new_cards<max_new:
|
|
|
|
max_new = new_cards
|
|
|
|
if due_cards<max_due:
|
|
|
|
max_due = due_cards
|
2022-05-01 16:56:28 +02:00
|
|
|
|
2022-05-02 14:20:39 +02:00
|
|
|
sum_w_new = sum(w_new)
|
|
|
|
sum_w_due = sum(w_due)
|
2022-05-01 16:56:28 +02:00
|
|
|
|
2022-04-29 18:55:36 +02:00
|
|
|
if due_cards:
|
2022-05-02 14:20:39 +02:00
|
|
|
dck_due = list(choice(user_clltn, size=max_due, replace=False, p=list(map(lambda x: x/sum_w_due, w_due)))) #garancija, da ni ponovitev
|
2022-04-29 18:55:36 +02:00
|
|
|
if new_cards:
|
2022-05-02 14:20:39 +02:00
|
|
|
dck_new = list(choice(user_clltn, size=max_new, replace=False, p=list(map(lambda x: x/sum_w_new, w_new))))
|
2022-04-29 18:55:36 +02:00
|
|
|
|
|
|
|
deck = dck_due + dck_new
|
2022-04-29 18:09:54 +02:00
|
|
|
|
2022-04-29 16:57:24 +02:00
|
|
|
return deck
|
2022-04-28 18:37:36 +02:00
|
|
|
|
2022-05-01 16:56:28 +02:00
|
|
|
def prob_eval_card(card):
|
2022-05-02 14:20:39 +02:00
|
|
|
|
|
|
|
print("intrest rate je: ", card["due"])
|
|
|
|
gumb = input("A te " + str(card["id"]) + " zanima?") # predpostalvjmao y = yes, m = maybe, n = no
|
|
|
|
due = card["due"]
|
2022-04-28 18:37:36 +02:00
|
|
|
|
2022-04-29 02:24:31 +02:00
|
|
|
if gumb == "y":
|
2022-05-01 18:00:26 +02:00
|
|
|
due = 1
|
2022-04-29 02:24:31 +02:00
|
|
|
elif gumb == "m":
|
2022-04-29 16:57:24 +02:00
|
|
|
due = abs(due / 1.3)
|
|
|
|
#abs je zato, ker "new" kodirano ko -1
|
|
|
|
# /1.3 in /2 sta na pamet izbrani funkciji
|
|
|
|
elif gumb=="n":
|
2022-04-29 02:24:31 +02:00
|
|
|
due = abs(due / 2)
|
|
|
|
|
2022-05-02 14:20:39 +02:00
|
|
|
card["due"] = due
|
2022-04-28 18:37:36 +02:00
|
|
|
|
2022-05-01 16:56:28 +02:00
|
|
|
def prob_eval_deck(deck, user_clltn):
|
2022-04-29 16:57:24 +02:00
|
|
|
for c in deck:
|
2022-05-02 14:20:39 +02:00
|
|
|
id = c["id"]
|
2022-05-01 16:56:28 +02:00
|
|
|
# tu dobimo karico, kjer se je nekaj spremenilo
|
2022-05-02 14:20:39 +02:00
|
|
|
prob_eval_card(c)
|
2022-05-01 18:00:26 +02:00
|
|
|
|
2022-04-29 02:24:31 +02:00
|
|
|
# engine
|
2022-05-01 16:56:28 +02:00
|
|
|
def run(user_clltn, n_of_days, max_new, max_due):
|
|
|
|
for day in range(n_of_days):
|
|
|
|
deck = generate_deck_prob(user_clltn, max_new, max_due) #to more bit global, da se ne generira skoz nov
|
2022-05-02 14:20:39 +02:00
|
|
|
prob_eval_deck(deck, user_clltn)
|
|
|
|
for card in user_clltn:
|
|
|
|
print("id: ", card["id"], "stopnja zanimanja: ", card["due"])
|
2022-05-01 16:56:28 +02:00
|
|
|
|
|
|
|
|
|
|
|
# config
|
|
|
|
n_of_days = 10
|
|
|
|
max_due = 15
|
|
|
|
max_new = 5
|
|
|
|
max_deck_size = max_new + max_due
|
2022-04-29 16:57:24 +02:00
|
|
|
|
2022-05-01 16:56:28 +02:00
|
|
|
user_clltn = generate_clltn(20)
|
2022-04-29 16:57:24 +02:00
|
|
|
|
2022-05-01 18:00:26 +02:00
|
|
|
run(user_clltn, n_of_days, max_new, max_due)
|