contentmatcher/test.py

133 lines
3.5 KiB
Python

from random import randint
from numpy.random import choice
# card = id, title, due, interval, owned_by, shared
def generate_card (clltn=[], user="bob", shared=False):
id = len(clltn) + 1
title = "".join([chr(randint(ord('a'), ord('z'))) for i in range(5)])
due = -1 #means new
interval = 0
card = dict()
card["id"]= id
card["title"] = title
card["due"] = due
card["interval"] = interval
card["owned_by"] = user
card["shared"] = shared
return card
def generate_clltn(n_of_cards):
clltn = [] #mogoče bi blo dobro met dictionary, sam že štejemo len zgoraj...
for n in range(n_of_cards):
clltn.append(generate_card(clltn=clltn))
return clltn
##1 SR - super-memo style
def get_new(user_clltn, n_of_cards):
for card in user_clltn:
pass
def get_due(user_clltn, n_of_cards):
pass
def generate_deck_sr(user_clltn, max_new, max_deck_size):
pass
def run_sr():
pass
#2 Probabilistic
## 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
def generate_weights(user_clltn):
"""generiramo uteži za due in new cards posebej; vrne tuple dveh listov za weightse..."""
weights_due = []
weights_new = []
for card in user_clltn:
due = card["due"]
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
def generate_deck_prob(user_clltn, max_new, max_due):
deck, dck_due, dck_new, due_cards = [], [], [], 0
w_new, w_due = generate_weights(user_clltn)
#treba je sestet non zero weights
new_cards = sum(w_new)
for w in w_due:
if w > 0:
due_cards += 1
#preverimo, če imamo dovolj kartic
if new_cards<max_new:
max_new = new_cards
if due_cards<max_due:
max_due = due_cards
sum_w_new = sum(w_new)
sum_w_due = sum(w_due)
if due_cards:
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
if new_cards:
dck_new = list(choice(user_clltn, size=max_new, replace=False, p=list(map(lambda x: x/sum_w_new, w_new))))
deck = dck_due + dck_new
return deck
def prob_eval_card(card):
print("intrest rate je: ", card["due"])
gumb = input("A te " + str(card["id"]) + " zanima?") # predpostalvjmao y = yes, m = maybe, n = no
due = card["due"]
if gumb == "y":
due = 1
elif gumb == "m":
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":
due = abs(due / 2)
card["due"] = due
def prob_eval_deck(deck, user_clltn):
for c in deck:
id = c["id"]
# tu dobimo karico, kjer se je nekaj spremenilo
prob_eval_card(c)
# engine
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
prob_eval_deck(deck, user_clltn)
for card in user_clltn:
print("id: ", card["id"], "stopnja zanimanja: ", card["due"])
# config
n_of_days = 10
max_due = 15
max_new = 5
max_deck_size = max_new + max_due
user_clltn = generate_clltn(20)
run(user_clltn, n_of_days, max_new, max_due)