from random import random, randint, shuffle from otree import settings def one_to_one_matching_after_vote(subsession): for group in subsession.get_groups(): players = group.get_players() group_size = len(players) ## hier die seller und customer mal testen seller = players[group_size-3:] seller_ids = [group.seller_first, group.seller_second, group.seller_third] #seller_ids = [4,5,6] ## todo: wieder rausnehmen customers = players[:group_size-3] shuffle(customers) counts = dict(X=0, Y=0, Z=0) seller_list_letter = ['X', 'Y', 'Z'] for p in players: if p.id_in_group in seller_ids: continue ## überspringe seller choices = [p.market_interaction_choice_1, p.market_interaction_choice_2, p.market_interaction_choice_3] ## choices haben ID 1,2,3 für X,Y,Z print("spieler - choices", p.id_in_group, choices) for i, choice in enumerate(choices): counts[seller_list_letter[choice-1]]+= 7 / (2**i) # Set Match if not chosen yet ## TODO: Falls das im 24 nicht passt mit Matching hier nochmal die seller_ids benutzen und zurückrechnen selected_seller_id = seller_ids[choice - 1] selected_seller = group.get_player_by_id(selected_seller_id) #selected_seller = seller[choice-1]#seller[seller_ids[i]]#seller[i]##group.get_player_by_id(choice) if selected_seller.match == -1: selected_seller.match = p.id_in_group p.match = selected_seller.id_in_group#choice p.matched_pref = i+1 p.match_letter = seller_list_letter[choice - 1] p.matched_index = choice - 1 if settings.DEBUG: #print( f'match - {p.matched_index} - bekommen: {choice} - pref/loopcounter - {p.matched_pref} - Letter: {p.match_letter}') pass break most_chosen_letter = max(counts, key=counts.get) most_chosen_index = seller_list_letter.index(most_chosen_letter) ### Todo Pcds: Rückwärtsrechnen des Anbieters ###Todo 22.04.2024: auskommentiert damit Experiment nach Runde 5 weitergeht; Befehl unten muss noch gefixt werden seller[most_chosen_index+1].top = True #group.get_player_by_id(most_chosen_index+1).top = True ## set groups by hand? ## break print(group.get_players()) #return 0/0 def create_group_seller_order(group): ### Todo: für kleinere Gruppen evtl nicht gut seller = [] for p in group.get_players(): if not p.customer: seller.append(p) shuffle(seller) first, second, third = seller #### HIER NUR FÜR DEN TEST first.avg_rating = randint(1, 5) second.avg_rating = randint(1, 5) third.avg_rating = randint(1, 5) return first.id_in_group,second.id_in_group,third.id_in_group def get_market_interaction_data(group, round = 1): ### Todo: für kleinere Gruppen evtl nicht gut first, second, third = group.get_player_by_id(group.seller_first), group.get_player_by_id(group.seller_second), group.get_player_by_id(group.seller_third) #score_1 , score_2 , score_3 = first.rating_received, second.rating_received, third.rating_received ''' first.avg_rating = randint(1,5) second.avg_rating = randint(1,5) third.avg_rating = randint(1,5) ''' min_score = min(first.avg_rating,second.avg_rating,third.avg_rating) max_score = max(first.avg_rating,second.avg_rating,third.avg_rating) ## performance = Punkte aus den Vorrunden in den Tasks performance = randint(1,20)#(calc_points_total_till_round(first) + calc_points_total_till_round(second) + calc_points_total_till_round(third))/3 return (first,second,third), min_score, max_score, performance