from otree.api import * import numpy as np import math from itertools import combinations import pandas as pd doc = """ Your app description """ class C(BaseConstants): NAME_IN_URL = 'popularity' PLAYERS_PER_GROUP = None NUM_ROUNDS = 20 NUM_PRODUCTS = 20 class Subsession(BaseSubsession): pass class Product(ExtraModel): name = models.StringField() choice_type = models.StringField() fame = models.StringField() popularity = models.StringField() def creating_session(subsession: Subsession): round = subsession.round_number if round == 1: # rows = read_csv("binarychoice/yougovdata.csv", Product) # rows = pd.read_csv("binarychoice/yougovdata.csv") for p in subsession.get_players(): p.participant.popProducts = [] p.participant.popChoiceTypes = [] choice_types = p.participant.choiceTypes chosen_products = p.participant.chosenProducts for choice_type in choice_types: for product in chosen_products[choice_type]: p.participant.popProducts.append(product) p.participant.popChoiceTypes.append(choice_type) for p in subsession.get_players(): p.choice_type = p.participant.popChoiceTypes[round-1] p.product = p.participant.popProducts[round-1] p.productImg = subsession.session.productImgs[p.choice_type][p.product] class Group(BaseGroup): pass class Player(BasePlayer): choice_type = models.StringField() product = models.StringField() familiarity = models.IntegerField() like = models.IntegerField() productImg = models.StringField() ## Skala för recognizability 'How familiar are you with this confectionery?" "Never heard of", "have heard of but never tasted", "Have tasted once or a few times", "Eats several times" ## Skala för tycke: se dokument pass # PAGES class Popularity(Page): form_model = 'player' form_fields = ["familiarity", "like"] @staticmethod def vars_for_template(player: Player): return dict(product=player.product, choice_type=player.choice_type, productImg=player.productImg) page_sequence = [Popularity]