dodal funkcijo za generiranje prob decka

master
Kostanjevec 2022-04-29 18:55:36 +02:00
parent 94f0fd7f41
commit 0159f5b184
1 changed files with 37 additions and 28 deletions

63
test.py
View File

@ -21,8 +21,8 @@ def generate_clltn (n_of_cards):
# USER
## config
max_due = 2
max_new = 1
max_due = 15
max_new = 5
max_deck_size = max_new + max_due
# setup
user_clltn = generate_clltn(100)
@ -49,16 +49,12 @@ def run_sr():
#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, max_deck_size):
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:
#problem je edgecase, ko ni populacije kar propade...
if len(user_clltn)<max_deck_size:
max_deck_size = len(user_clltn) # lame fast hack...
_, _, due, _, _, _ = card
if due > 0:
@ -70,25 +66,30 @@ def generate_weights(user_clltn, max_deck_size):
return weights_new, weights_due
#TODO
def generate_deck_prob(user_clltn, max_deck_size, max_new):
deck = []
for c in range(max_deck_size):
deck.append(user_clltn[c]) # tu vzame prvic ampak moralo bi random c brez ponavljanja obteženih z "due". rabimo tudi naključnih/najnovejših? max_new novih cardov.
def generate_deck_prob(user_clltn, max_new, max_due):
deck, dck_due, dck_new = [], [], []
w_new, w_due = generate_weights(user_clltn)
new_cards = sum(w_new)
due_cards = sum(w_due)
#preverimo, če imamo dovolj kartic
if new_cards<max_new:
max_new = new_cards
if due_cards<max_due:
max_due = due_cards
if due_cards:
dck_due = choices(user_clltn, cum_weights=w_due, k=max_due)
if new_cards:
dck_new = choices(user_clltn, cum_weights=w_new, k=max_new)
deck = dck_due + dck_new
"""
if sum(weights_due)>0:
#due
dck = choices(user_clltn, cum_weights=weights_new, k=max_due)
dck_new = choices(user_clltn, k=max)
#new
#??
else:
dck = choices(user_clltn, k=max_new)
"""
return deck
print(generate_deck_prob(user_clltn, max_new, max_due))
#TODO?
def prob_eval(card):
id, title, due, interval, owned_by, shared = card #due je tukaj interest rate
@ -119,9 +120,17 @@ def run_prob(deck, user_clltn):
# random python stuff
"""
Output = [item for item in Input
if item[0] == 3 or item[1] == 3]
## kako najt tuple v listu in ga spremeniti?
## kako vzet weight iz tuple in ga assignat pri izbiranju?
recordlist = [('sku1','item1','bro1'),('sku2','item2','bro2')]
for index, item in enumerate(recordlist):
itemlist = list(item)
if itemlist[0] == 'sku1':
itemlist[1] = itemlist[1]+','+'item'
item = tuple(itemlist)
print(generate_weights(user_clltn, max_deck_size))
recordlist[index] = item
print(recordlist)
"""