from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range, ) from base64 import b64decode from GmailApi.GmailApi import SendEmail author = 'Your name here' doc = """ Your app description """ class Constants(BaseConstants): name_in_url = 'payment_control' players_per_group = None num_rounds = 1 expt_point = 0.2 class Subsession(BaseSubsession): pass class Group(BaseGroup): def ack_payment(self, id_in_group, payload): b64 = payload['base64pdf'] player = self.get_player_by_id(id_in_group) pdfPath = f'{self.session.code}_{player.participant.id_in_session}.pdf' bytes_decoded = b64decode(b64, validate=True) with open(pdfPath, 'wb') as file: file.write(bytes_decoded) file.close() send_email = SendEmail() send_email.send(pdfPath, f'{self.session.code} Participant: {player.participant.id_in_session}') # self.send_email_pdf_figs(pdfPath, f'{self.session.code} Participant: {player.participant.id_in_session}', 'testest', 'alvinx.tan@gmail.com') return { id_in_group: True } class Player(BasePlayer): mobile_number = models.StringField() name = models.StringField() payoff_from_round = models.IntegerField() lottery_earnings = models.IntegerField() show_up_fee = models.IntegerField() total_earnings = models.FloatField() payoff_from_game_number = models.IntegerField() stage3payoff = models.IntegerField() receipt_ack = models.BooleanField( widget=widgets.CheckboxInput, ) def start(self): self.stage3payoff = self.participant.vars['Stage3Earning']['Earning'] self.payoff_from_round = self.participant.vars['Stage3Earning']['Round'] self.payoff_from_game_number = self.participant.vars['Stage3Earning']['Game_number'] self.lottery_earnings = 6 if self.participant.vars['dice_number'] == 6 else 0 self.show_up_fee = int(self.session.config['participation_fee']) self.total_earnings = self.show_up_fee + float(Constants.expt_point * self.stage3payoff) + self.lottery_earnings self.payoff = self.stage3payoff + self.lottery_earnings / Constants.expt_point def custom_export(players): yield ['session', 'participant_code', 'participant_id', 'show up fee', 'lottery earnings', 'payoff from stage 3', 'payoff from round', 'payoff from game number', 'total earnings', 'full name', 'mobile number'] for p in players: yield [p.session.code, p.participant.code, p.participant.id_in_session, p.show_up_fee, p.lottery_earnings, p.stage3payoff, p.payoff_from_round, p.payoff_from_game_number, p.total_earnings, p.name, p.mobile_number]