popravljeni vsi zaznani bugi, card spremenil iz tuple v dict, standard lib choices zamenjal z numpy choice

master
Jan Kostanjevec 2022-05-02 14:20:39 +02:00
parent 278ed0f3e9
commit c1931cfed8
1 changed files with 26 additions and 28 deletions

52
test.py
View File

@ -1,7 +1,5 @@
from random import randint, choices from random import randint
# item from numpy.random import choice
#collection
clltn = []
# card = id, title, due, interval, owned_by, shared # card = id, title, due, interval, owned_by, shared
def generate_card (clltn=[], user="bob", shared=False): def generate_card (clltn=[], user="bob", shared=False):
@ -9,8 +7,14 @@ def generate_card (clltn=[], user="bob", shared=False):
title = "".join([chr(randint(ord('a'), ord('z'))) for i in range(5)]) title = "".join([chr(randint(ord('a'), ord('z'))) for i in range(5)])
due = -1 #means new due = -1 #means new
interval = 0 interval = 0
owned_by = user
card = id, title, due, interval, owned_by, shared card = dict()
card["id"]= id
card["title"] = title
card["due"] = due
card["interval"] = interval
card["owned_by"] = user
card["shared"] = shared
return card return card
def generate_clltn(n_of_cards): def generate_clltn(n_of_cards):
@ -46,7 +50,7 @@ def generate_weights(user_clltn):
weights_due = [] weights_due = []
weights_new = [] weights_new = []
for card in user_clltn: for card in user_clltn:
_, _, due, _, _, _ = card due = card["due"]
if due > 0: if due > 0:
weights_due.append(due) weights_due.append(due)
@ -73,22 +77,24 @@ def generate_deck_prob(user_clltn, max_new, max_due):
if due_cards<max_due: if due_cards<max_due:
max_due = due_cards max_due = due_cards
print("weigts new: ", w_new, "due: ", w_due) sum_w_new = sum(w_new)
sum_w_due = sum(w_due)
if due_cards: if due_cards:
dck_due = choices(user_clltn, weights=w_due, k=max_due) #ni garancije, da ni ponovitev 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: if new_cards:
dck_new = choices(user_clltn, weights=w_new, k=max_new) 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 deck = dck_due + dck_new
return deck return deck
def prob_eval_card(card): def prob_eval_card(card):
id, title, due, interval, owned_by, shared = card #due je tukaj interest rate
print("intrest rate je: ", due) print("intrest rate je: ", card["due"])
gumb = input("A te " + title + " zanima?") # predpostalvjmao y = yes, m = maybe, n = no gumb = input("A te " + str(card["id"]) + " zanima?") # predpostalvjmao y = yes, m = maybe, n = no
due = card["due"]
if gumb == "y": if gumb == "y":
due = 1 due = 1
elif gumb == "m": elif gumb == "m":
@ -98,29 +104,21 @@ def prob_eval_card(card):
elif gumb=="n": elif gumb=="n":
due = abs(due / 2) due = abs(due / 2)
card_mod = id, title, due, interval, owned_by, shared card["due"] = due
return card_mod
def prob_eval_deck(deck, user_clltn): def prob_eval_deck(deck, user_clltn):
for c in deck: for c in deck:
print("deck: ", deck) id = c["id"]
id, _, _, _, _, _ = c
# tu dobimo karico, kjer se je nekaj spremenilo # tu dobimo karico, kjer se je nekaj spremenilo
card_mod = prob_eval_card(c) prob_eval_card(c)
# tu jo poiščemo v clltn in updejatmo
for index, card in enumerate(user_clltn):
if card[0] == id:
user_clltn[index] = card_mod
break
return user_clltn #TODO ta collection ima samo eno karto updejtano, ne pa celega decka
# engine # engine
def run(user_clltn, n_of_days, max_new, max_due): def run(user_clltn, n_of_days, max_new, max_due):
for day in range(n_of_days): 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 deck = generate_deck_prob(user_clltn, max_new, max_due) #to more bit global, da se ne generira skoz nov
user_clltn = prob_eval_deck(deck, user_clltn) prob_eval_deck(deck, user_clltn)
print("konec dneva: ", user_clltn) for card in user_clltn:
print("id: ", card["id"], "stopnja zanimanja: ", card["due"])
# config # config