def vars_for_template(self): #Array for single set of points pointA = [] pointB = [] #Array to hold 2 sets of points pointsA = [] pointsB = [] qd = self.player.current_question() #Adding points for set A pointA.append(float(qd['A_p1'])) pointA.append(float(qd['A_p3'])) #Adding points for set B pointB.append(float(qd['B_p1'])) pointB.append(float(qd['B_p3'])) #Adding A and B to points pointsA.append(pointA) pointsB.append(pointB) #This line is needed for the data to be passed to highcharts #Without it the data is in the wrong form and will crash program pointsA = safe_json(pointsA) pointsB = safe_json(pointsB) #payofflab1 = str("\'"+"$"+str(qd['payoff1'])+"\'") #payofflab3 = str("\'"+"$"+str(qd['payoff3'])+"\'") #Returns [[a1,a2],[b1,b2]] as a series return{ 'seriesA' : pointsA, 'seriesB' : pointsB, #'poffA' : payofflab1, #'poffC' : payofflab3, }
def vars_for_template(self): if (self.session.config['margin'] == 'low'): demand = self.session.vars['demand'][self.round_number - 1] demandindex = (demand - 500) / 50 else: demand = self.session.vars['demand'][self.round_number - 1] demandindex = (demand - 300) / 100 if (demandindex < self.player.orderquantity): demandtext = "Because demand was lower than your inventory level, you have excess units in your inventory that you could not sell to the customers." elif (demandindex > self.player.orderquantity): demandtext = "Because demand was higher than your inventory level, you could not satisfy all the customer demand." else: demandtext = "Your order quantity exactly matched demand." return { 'round': self.player.round_number, 'margin': safe_json(self.session.config['margin']), 'orderqindex': safe_json(self.player.orderquantity), 'demand': demand, 'demandindex': safe_json(demandindex), 'player_in_all_rounds': self.player.in_all_rounds(), 'demandtext': demandtext }
def vars_for_template(self): if (self.session.config['margin'] == 'low'): demand = self.session.vars['demand'][self.round_number - 1] demandindex = (demand - 500) / 50 else: demand = self.session.vars['demand'][self.round_number - 1] demandindex = (demand - 300) / 100 if (demandindex < self.player.orderquantity): demandtext = "excess items" elif (demandindex > self.player.orderquantity): demandtext = "unsatisfied demand" else: demandtext = "inventory matched demand" profitt = profit(demand, self.player.orderquantity, self.session.config['margin']) return { 'round': self.player.round_number, 'margin': safe_json(self.session.config['margin']), 'orderquantity': safe_json(self.player.trueorderquantity), 'orderqindex': safe_json(self.player.orderquantity), 'demand': demand, 'demandindex': safe_json(demandindex), 'player_in_all_rounds': self.player.in_all_rounds(), 'demandtext': demandtext, 'profit': int(profitt) }
def vars_for_admin_report(self): group = self.get_groups()[0] series = [] transaction_prices = [g.sale_price for g in group.in_all_rounds()] series.append({ 'name': 'Transaction Price', 'data': transaction_prices }) for player in group.get_players(): payoffs = [p.payoff for p in player.in_all_rounds()] series.append({ 'name': 'Earnings for %s' % player.role().capitalize(), 'data': payoffs }) highcharts_series = safe_json(series) round_numbers = safe_json(list(range(1, Constants.num_rounds + 1))) return { 'highcharts_series': highcharts_series, 'round_numbers': round_numbers }
def vars_for_template(self): "This method defines the variables which are handed over to the html file." sum_costs_ob = get_sum_costs(self) return { 'current_day': safe_json(self.player.period.start - 1), 'end_day': safe_json(self.player.period.end - 1), }
def vars_for_template(self): if (self.session.config['margin'] == 'low'): marginlow = True baselinereward = '0.12' else: marginlow = False baselinereward = '0.20' return { 'baselinereward': baselinereward, 'marginlow': marginlow, 'margin': safe_json(self.session.config['margin']), 'label1l': 'If your order quantity is 600 and the demand realization is 700, what is your profit?', 'label2l': 'If your order quantity is 600, what is the probability that your profit will be 936?', 'label3l': 'If your order quantity is 750, what is the probability that your profit will be 806?', 'label4': 'What happens if the demand is higher than your order quantity?', 'label5': 'If your average profit over all the rounds is 1130, what is your monetary reward from Part 2 (without the baseline reward)?', 'label1h': 'If your order quantity is 400 and the demand realization is 500, what is your profit?', 'label2h': 'If your order quantity is 500, what is the probability that your profit will be 700?', 'label3h': 'If your order quantity is 800, what is the probability that your profit will be 942?', }
def vars_for_template(self): if (Constants.margin == 'low'): marginlow = True baselinereward = '0.12' else: marginlow = False baselinereward = '0.20' return { 'baselinereward': baselinereward, 'marginlow': marginlow, 'margin': safe_json(Constants.margin), 'label1': 'If your decision is C and the state of the world realization is S5, what is your profit?', 'label2': 'If your decision is C, what is the probability that your profit will be 936?', 'label3': 'If your decision is F, what is the probability that your profit will be 806?', 'label4': 'If the state of the world is S5 in one round, what is the probability that state of world is S3 in the next round?', 'label5': 'If your average profit over all the rounds is 1130, what is your monetary reward from Part 2 (without the baseline reward)?', }
def vars_for_template(self): return { 'round': self.player.round_number, 'margin': safe_json(Constants.margin), 'player_in_all_rounds': self.player.in_all_rounds(), }
def vars_for_template(self): return { 'endingPxWidth': Constants.c_endingPxWidth[self.session.config['treatment']], 'timer_left_in_ms': safe_json((self.subsession.timer_time_left() + 1) * 1000), }
def clicktrack(context, *args, **kwargs): if 'participant' not in context: context['vars_for_clicktracking'] = {} return context #print("Who made context happen? {}".format(context)) participant = context['participant'] channel = 'clicktracking-{}'.format(participant.code) # channel name should not contain illegal chars, # so that it can be used in JS and URLs if not re.match(r'^[a-zA-Z0-9_-]+$', channel): raise ValueError( "'channel' can only contain ASCII letters, numbers, underscores, and hyphens. " "Value given was: {}".format(context['channel'])) context['channel'] = channel vars_for_js = { 'channel': context['channel'], 'participant_code': participant.code, } context['vars_for_clicktracking'] = safe_json(vars_for_js) return context
def vars_for_template(self): return { 'lottery11_condition': Constants.lotteries[0]['condition'], 'lottery11_return': Constants.lotteries[0]['return per point invested'], 'lottery11_description': Constants.lotteries[0]['description'], 'lottery12_condition': Constants.lotteries[1]['condition'], 'lottery12_return': Constants.lotteries[1]['return per point invested'], 'lottery12_description': Constants.lotteries[1]['description'], 'lottery21_condition': Constants.lotteries[2]['condition'], 'lottery21_return': Constants.lotteries[2]['return per point invested'], 'lottery21_description': Constants.lotteries[2]['description'], 'lottery22_condition': Constants.lotteries[3]['condition'], 'lottery22_return': Constants.lotteries[3]['return per point invested'], 'lottery22_description': Constants.lotteries[3]['description'], 'lottery23_condition': Constants.lotteries[4]['condition'], 'lottery23_return': Constants.lotteries[4]['return per point invested'], 'lottery23_description': Constants.lotteries[4]['description'], 'lottery31_condition': Constants.lotteries[5]['condition'], 'lottery31_return': Constants.lotteries[5]['return per point invested'], 'lottery31_description': Constants.lotteries[5]['description'], 'lottery32_condition': Constants.lotteries[6]['condition'], 'lottery32_return': Constants.lotteries[6]['return per point invested'], 'lottery32_description': Constants.lotteries[6]['description'], 'lottery41_condition': Constants.lotteries[7]['condition'], 'lottery41_return': Constants.lotteries[7]['return per point invested'], 'lottery41_description': Constants.lotteries[7]['description'], 'lottery42_condition': Constants.lotteries[8]['condition'], 'lottery42_return': Constants.lotteries[8]['return per point invested'], 'lottery42_description': Constants.lotteries[8]['description'], 'lottery43_condition': Constants.lotteries[9]['condition'], 'lottery43_return': Constants.lotteries[9]['return per point invested'], 'lottery43_description': Constants.lotteries[9]['description'], "player_scores": safe_json(self.session.vars['player_scores']), "player_rank": safe_json(self.player.rank) }
def vars_for_template(self): return { 'image_path': 'real_effort/paragraphs/{}.png'.format( self.round_number), 'reference_text': safe_json(Constants.reference_texts[self.round_number - 1]), 'debug': settings.DEBUG, 'required_accuracy': 100 * (1 - Constants.allowed_error_rates[self.round_number - 1]) }
def vars_for_template(self): if (self.session.config['margin'] == 'low'): demand = self.session.vars['demand'][self.round_number - 1] demandindex = (demand - 500) / 50 else: demand = self.session.vars['demand'][self.round_number - 1] demandindex = (demand - 300) / 100 if self.player.id_in_group % 2 == 1: blockseq = 'blocks1' else: blockseq = 'blocks2' if blockseq == 'blocks1': blocktitlee = blocktitle(self.round_number, self.session.config['blocks1']) else: blocktitlee = blocktitle(self.round_number, self.session.config['blocks2']) return { 'blockk': blocktitlee, 'round': self.player.round_number, 'orderqindex': safe_json(self.player.orderquantity), 'demand': demand, 'demandindex': safe_json(demandindex), 'player_in_all_rounds': self.player.in_rounds(1, self.player.round_number - 5), 'player_in_previous_5rounds': self.player.in_rounds(self.player.round_number - 4, self.player.round_number) }
def vars_for_template(self): if (self.session.config['margin'] == 'low'): marginlow = True else: marginlow = False return { 'marginlow': marginlow, 'margin': safe_json(self.session.config['margin']), }
def vars_for_template(self): return { 'image_path': 'real_effort/paragraphs/{}.png'.format(self.round_number), 'reference_text': safe_json(Constants.reference_texts[self.round_number - 1]), 'debug': settings.DEBUG, 'required_accuracy': 100 * (1 - Constants.allowed_error_rates[self.round_number - 1]) }
def hash_and_save_json(participants, session_code, url=""): """ participants is the participants list session_code is the current session code see above """ codes = [participant.code for participant in participants] # Choose Hashing or Encrypting here hashed = hash_participant_codes(codes) try: if not os.path.exists(folder): os.makedirs(folder) with open(folder + date + "_" + session_code + ".json", 'x') as out: print(out.name, 'does not yet exist') json.dump(hashed, out, indent=4) safe_json(hashed) except: print(folder + date + "_" + session_code + ".json", 'does already exist') return hashed
def vars_for_admin_report(self): group = self.get_groups()[0] series = [] transaction_prices = [g.sale_price for g in group.in_all_rounds()] series.append({ 'name': 'Transaction Price', 'data': transaction_prices}) for player in group.get_players(): payoffs = [p.payoff for p in player.in_all_rounds()] series.append( {'name': 'Earnings for %s' % player.role().capitalize(), 'data': payoffs}) highcharts_series = safe_json(series) round_numbers = safe_json(list(range(1, Constants.num_rounds + 1))) return { 'highcharts_series': highcharts_series, 'round_numbers': round_numbers }
def vars_for_template(self): return { 'with_prime': { 'NoPrime': 'NoPrime', 'WithPrime': 'WithPrime', 'NoPrime_NoEcoGeste': 'NoPrime' }[self.player.role()], 'with_ecogeste': { 'NoPrime': 'WithEcoGeste', 'WithPrime': 'WithEcoGeste', 'NoPrime_NoEcoGeste': 'NoEcoGeste' }[self.player.role()], 'timer_left_in_ms': safe_json((self.subsession.timer_time_left() + 1) * 1000), }
def vars_for_template(self): if self.round_number == 1: header_text = 'You will be shown 5 pages of transcription, one on each screen. When you click next, your transcription of the first page will be submitted and you will be presented with a fresh link to a second page of transcription and a blank text box, and so on until the fifth page. After you submit the fifth page we ask a few basic demographic questions and give you a code to submit your HIT.' else: header_text = '' return { # 'image_path': 'https://dl.dropboxusercontent.com/u/1688949/trx/{}_{}.png'.format(self.player.id_in_group-1, # self.round_number), 'image_path': 'transcription/1_{}.png'.format(self.round_number), # 'reference_text': safe_json(Constants.reference_texts[self.player.id_in_group-2,self.round_number - 1]), 'reference_text': safe_json(Constants.reference_texts[0,self.round_number - 1]), 'header_text': header_text, 'debug': settings.DEBUG, 'required_accuracy': 100 * (1 - Constants.allowed_error_rates[self.round_number - 1]), 'agreed': self.player.in_round(1).emp_price }
def chat_template_tag(context, *args, **kwargs): player = context['player'] group = context['group'] Constants = context['Constants'] participant = context['participant'] kwargs.setdefault('channel', group.id) kwargs.setdefault('nickname', 'Player {}'.format(player.id_in_group)) nickname = str(kwargs['nickname']) unprefixed_channel = str(kwargs['channel']) # channel name should not contain illegal chars, # so that it can be used in JS and URLs if not re.match(r'^[a-zA-Z0-9_-]+$', unprefixed_channel): raise ChatTagError( "'channel' can only contain ASCII letters, numbers, underscores, and hyphens. " "Value given was: {}".format(unprefixed_channel)) # prefix the channel name with session code and app name channel = '{}-{}-{}-{}'.format( context['session'].id, # name_in_url could be very long, so take the first chars # and combine with a hash to ensure uniqueness Constants.name_in_url[:50], hash(Constants.name_in_url), kwargs['channel']) context['channel'] = channel nickname_signed = Signer().sign(nickname) socket_path = channel_utils.chat_path(channel, participant.id) vars_for_js = { 'socket_path': socket_path, 'channel': channel, 'participant_id': participant.id, 'nickname_signed': nickname_signed, } context['vars_for_js'] = safe_json(vars_for_js) return context
def chat(context, *args, **kwargs): player = context['player'] group = context['group'] Constants = context['Constants'] participant = context['participant'] kwargs.setdefault('channel', group.id) kwargs.setdefault('nickname', 'Player {}'.format(player.id_in_group)) # prefix the channel name with session code and app name channel = '{}-{}-{}'.format( context['session'].id, Constants.name_in_url, kwargs['channel'] ) nickname = kwargs['nickname'] # channel name should not contain illegal chars, # so that it can be used in JS and URLs if not re.match(r'^[a-zA-Z0-9_-]+$', channel): raise ValueError( "'channel' can only contain ASCII letters, numbers, underscores, and hyphens. " "Value given was: {}".format(context['channel'])) NicknameRegistration.objects.update_or_create( participant=participant, channel=channel, defaults={'nickname': nickname} ) context['channel'] = channel vars_for_js = { 'channel': context['channel'], 'participant_code': participant.code, 'participant_id': participant.id } context['vars_for_js'] = safe_json(vars_for_js) return context
def json(val): return safe_json(val)
def vars_for_admin_report(self): if('codes' not in self.session.vars): self.session.vars['codes'] = hash_and_save_json(self.session.participant_set.all(), self.session.code, "") return {'AccessExit': safe_json(self.session.vars['codes'])}
def vars_for_template(self): return { 'round': self.player.round_number, 'margin': safe_json(Constants.margin) }
def vars_for_template(self): return { 'timer_left_in_ms': safe_json((self.subsession.timer_time_left() + 1) * 1000), }
def vars_for_template(self): return { "player_scores": safe_json(self.session.vars['player_scores']), "player_rank": safe_json(self.player.rank) }
def vars_for_template(self): return { 'round': self.player.round_number, 'margin': safe_json(self.session.config['margin']) }
def json(val): return safe_json(val)
def vars_for_template(self): return {'private_value': safe_json(self.player.private_value)}
def vars_for_template(self): return {'private_value': safe_json(self.player.private_value)}