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
# item
#collection
clltn = []
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):
@ -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)])
due = -1 #means new
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
def generate_clltn(n_of_cards):
@ -46,7 +50,7 @@ def generate_weights(user_clltn):
weights_due = []
weights_new = []
for card in user_clltn:
_, _, due, _, _, _ = card
due = card["due"]
if due > 0:
weights_due.append(due)
@ -73,22 +77,24 @@ def generate_deck_prob(user_clltn, max_new, max_due):
if due_cards<max_due:
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:
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:
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
return deck
def prob_eval_card(card):
id, title, due, interval, owned_by, shared = card #due je tukaj interest rate
print("intrest rate je: ", due)
gumb = input("A te " + title + " zanima?") # predpostalvjmao y = yes, m = maybe, n = no
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":
@ -98,29 +104,21 @@ def prob_eval_card(card):
elif gumb=="n":
due = abs(due / 2)
card_mod = id, title, due, interval, owned_by, shared
return card_mod
card["due"] = due
def prob_eval_deck(deck, user_clltn):
for c in deck:
print("deck: ", deck)
id, _, _, _, _, _ = c
id = c["id"]
# tu dobimo karico, kjer se je nekaj spremenilo
card_mod = 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
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
user_clltn = prob_eval_deck(deck, user_clltn)
print("konec dneva: ", user_clltn)
prob_eval_deck(deck, user_clltn)
for card in user_clltn:
print("id: ", card["id"], "stopnja zanimanja: ", card["due"])
# config