from otree.api import * doc = """ Your app description """ class Constants(BaseConstants): name_in_url = 'treatment' players_per_group = None num_rounds = 1 class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): pass def creating_session(subsession): # %% Prelim import pandas as pd import random for player in subsession.get_players(): # Set participant treatment status participant = player.participant participant.treatment = random.choice([1, 2]) print('set treatment to', participant.treatment) # Randomize choice sets for participant df_clean = pd.read_excel('./wines_corrected_DEMO.xlsx') wine_profiles = df_clean[['name_id', 'name_correct', 'wine_type', 'varietal', 'country', 'year', 'price']] # Generate a table wines that participant will see in markets mkts = 1 # number choice sets J = 5 # number of wines in given choice set # Assign non-duplicated name, year, varietal pairs to each market wine_ids = list(set(wine_profiles['name_id'])) markets = [] for i in range((int(mkts))): row = random.sample(wine_ids, J) markets.append(row) wines_list = [wine for market in markets for wine in market] wines_df = pd.DataFrame(wines_list, columns=['name_id']) wines_df = wines_df.merge(wine_profiles, how='left', on='name_id', validate='m:1') wines_df['wine_id'] = wines_df.index wines_df.set_index('wine_id').reset_index() wines_df.to_csv(f'./wines_participants/wines_participant_{participant.code}.csv', index=False) # PAGES class treatmentInfo(Page): pass page_sequence = [ treatmentInfo ]