from . import models, views from ._builtin import Page from .models import Constants import csv import boto3 import time import random import os import base64 class Ending(Page): def is_displayed(self): return self.round_number == 1 def before_next_page(self): resp1 = [self.player.participant.vars['run1_r1'], self.player.participant.vars['run1_r2'], self.player.participant.vars['run1_r3'], self.player.participant.vars['run1_r4']] resp2 = [self.player.participant.vars['run2_r1'], self.player.participant.vars['run2_r2'], self.player.participant.vars['run2_r3'], self.player.participant.vars['run2_r4']] nn = self.player.participant.vars['name'] file_name = nn + '_SSSTAccImplicit' + '.csv' f = open(file_name, "w") writer = csv.writer(f) writer.writerows([[self.participant.vars['tiempo']], [nn], [self.player.participant.vars['age']], [self.player.participant.vars['genero']], [self.player.participant.vars['zurdo']], [self.player.participant.vars['educacion']], [self.player.participant.vars['music']],[self.player.participant.vars['singing']], [self.player.participant.vars['dancing']],[self.player.participant.vars['sports']], [[self.player.participant.vars['L1']],[self.player.participant.vars['L1_aos']],[self.player.participant.vars['L1_sp']],[self.player.participant.vars['L1_com']],[self.player.participant.vars['L1_rd']],[self.player.participant.vars['L1_wr']]], [[self.player.participant.vars['L2']], [self.player.participant.vars['L2_aos']], [self.player.participant.vars['L2_sp']], [self.player.participant.vars['L2_com']], [self.player.participant.vars['L2_rd']], [self.player.participant.vars['L2_wr']]], [[self.player.participant.vars['L3']], [self.player.participant.vars['L3_aos']], [self.player.participant.vars['L3_sp']], [self.player.participant.vars['L3_com']], [self.player.participant.vars['L3_rd']], [self.player.participant.vars['L3_wr']]], [[self.player.participant.vars['L4']], [self.player.participant.vars['L4_aos']], [self.player.participant.vars['L4_sp']], [self.player.participant.vars['L4_com']], [self.player.participant.vars['L4_rd']], [self.player.participant.vars['L4_wr']]], [[self.player.participant.vars['L5']], [self.player.participant.vars['L5_aos']], [self.player.participant.vars['L5_sp']], [self.player.participant.vars['L5_com']], [self.player.participant.vars['L5_rd']], [self.player.participant.vars['L5_wr']]], [[self.player.participant.vars['L6']], [self.player.participant.vars['L6_aos']], [self.player.participant.vars['L6_sp']], [self.player.participant.vars['L6_com']], [self.player.participant.vars['L6_rd']], [self.player.participant.vars['L6_wr']]]]) writer.writerows([self.participant.vars['q1']]) writer.writerows([resp1]) writer.writerows([self.participant.vars['q2']]) writer.writerows([resp2]) writer.writerows([[time.asctime(time.gmtime())], ['end']]) f.close() # send it to the cloud s3 = boto3.resource('s3', region_name='eu-west-3', config=boto3.session.Config(signature_version='s3v4')) # Please change name here with the name of your S3 bucket s3.meta.client.upload_file(file_name, 'sss-task-results-bucket', file_name) class VolumeAdjustment(Page): def is_displayed(self): return self.round_number == 1 class Demographics(Page): def is_displayed(self): return self.round_number == 1 form_model = models.Player form_fields = ['age', 'genero', 'zurdo', 'educacion', 'music', 'singing','dancing','sports', 'L1', 'L1_aos', 'L1_sp', 'L1_com', 'L1_rd','L1_wr', 'L2', 'L2_aos', 'L2_sp', 'L2_com', 'L2_rd', 'L2_wr', 'L3', 'L3_aos', 'L3_sp', 'L3_com', 'L3_rd', 'L3_wr', 'L4', 'L4_aos', 'L4_sp', 'L4_com', 'L4_rd', 'L4_wr', 'L5', 'L5_aos', 'L5_sp', 'L5_com', 'L5_rd', 'L5_wr', 'L6', 'L6_aos', 'L6_sp', 'L6_com', 'L6_rd', 'L6_wr'] def before_next_page(self): if self.round_number == 1: self.player.participant.vars['age'] = self.player.age self.player.participant.vars['genero'] = self.player.genero self.player.participant.vars['educacion'] = self.player.educacion self.player.participant.vars['music'] = self.player.music self.player.participant.vars['singing'] = self.player.singing self.player.participant.vars['dancing'] = self.player.dancing self.player.participant.vars['sports'] = self.player.sports self.player.participant.vars['zurdo'] = self.player.zurdo self.player.participant.vars['L1'] = self.player.L1 self.player.participant.vars['L1_aos'] = self.player.L1_aos self.player.participant.vars['L1_sp'] = self.player.L1_sp self.player.participant.vars['L1_com'] = self.player.L1_com self.player.participant.vars['L1_rd'] = self.player.L1_rd self.player.participant.vars['L1_wr'] = self.player.L1_wr self.player.participant.vars['L2'] = self.player.L2 self.player.participant.vars['L2_aos'] = self.player.L2_aos self.player.participant.vars['L2_sp'] = self.player.L2_sp self.player.participant.vars['L2_com'] = self.player.L2_com self.player.participant.vars['L2_rd'] = self.player.L2_rd self.player.participant.vars['L2_wr'] = self.player.L2_wr self.player.participant.vars['L3'] = self.player.L3 self.player.participant.vars['L3_aos'] = self.player.L3_aos self.player.participant.vars['L3_sp'] = self.player.L3_sp self.player.participant.vars['L3_com'] = self.player.L3_com self.player.participant.vars['L3_rd'] = self.player.L3_rd self.player.participant.vars['L3_wr'] = self.player.L3_wr self.player.participant.vars['L4'] = self.player.L4 self.player.participant.vars['L4_aos'] = self.player.L4_aos self.player.participant.vars['L4_sp'] = self.player.L4_sp self.player.participant.vars['L4_com'] = self.player.L4_com self.player.participant.vars['L4_rd'] = self.player.L4_rd self.player.participant.vars['L4_wr'] = self.player.L4_wr self.player.participant.vars['L5'] = self.player.L5 self.player.participant.vars['L5_aos'] = self.player.L5_aos self.player.participant.vars['L5_sp'] = self.player.L5_sp self.player.participant.vars['L5_com'] = self.player.L5_com self.player.participant.vars['L5_rd'] = self.player.L5_rd self.player.participant.vars['L5_wr'] = self.player.L5_wr self.player.participant.vars['L6'] = self.player.L6 self.player.participant.vars['L6_aos'] = self.player.L6_aos self.player.participant.vars['L6_sp'] = self.player.L6_sp self.player.participant.vars['L6_com'] = self.player.L6_com self.player.participant.vars['L6_rd'] = self.player.L6_rd self.player.participant.vars['L6_wr'] = self.player.L6_wr class Step1(Page): def is_displayed(self): return self.round_number == 1 class Step2(Page): form_model = models.Player form_fields = ['audio_test2'] def before_next_page(self): texto = self.player.audio_test2 name = self.player.participant.vars['name'] + '_SSSTestImp_silence1.wav' aux = base64.b64decode(texto[texto.find(",") + 1:] + "===") wav_result = open(name, 'wb') wav_result.write(aux) s3 = boto3.resource('s3', region_name='eu-west-3', config=boto3.session.Config(signature_version='s3v4')) # Please change name here with the name of your S3 bucket s3.meta.client.upload_file(name, 'sss-task-results-bucket', name) os.remove(name) def is_displayed(self): return self.round_number == 1 class Step1R(Page): def is_displayed(self): return self.round_number == 1 class Step2R(Page): form_model = models.Player form_fields = ['audio_test2'] def before_next_page(self): texto = self.player.audio_test2 name = self.player.participant.vars['name'] + '_SSSTestImp_silence2.wav' aux = base64.b64decode(texto[texto.find(",") + 1:] + "===") wav_result = open(name, 'wb') wav_result.write(aux) s3 = boto3.resource('s3', region_name='eu-west-3', config=boto3.session.Config(signature_version='s3v4')) # Please change name here with the name of your S3 bucket s3.meta.client.upload_file(name, 'sss-task-results-bucket', name) os.remove(name) def is_displayed(self): return self.round_number == 1 class Instructions(Page): form_model = models.Player form_fields = ['name'] def name_error_message(self, value): n = value s3 = boto3.resource('s3', region_name='eu-west-3', config=boto3.session.Config(signature_version='s3v4')) lol = n + '_SSSTAccImplicit.csv' # Please change name here with the name of your S3 bucket my_bucket = s3.Bucket('sss-task-results-bucket') esta = 0 for file in my_bucket.objects.all(): if file.key == lol: esta = 1 if esta == 1: return 'ce nom dutilisateur est déja occupé. Veuillez insérer le code qui vous a été attribué dans Moodle dans le cadre du cours « Introduction à la Psychologie du Langage' def is_displayed(self): return self.round_number == 1 def before_next_page(self): if self.round_number == 1: self.player.inicializar() self.player.participant.vars['tiempo'] = time.asctime(time.gmtime()) self.player.participant.vars['name']=self.player.name class Run1(Page): form_model = models.Player form_fields = ['audio_test2'] def before_next_page(self): texto = self.player.audio_test2 name = self.player.participant.vars['name'] + '_SSSTestImp_run1.wav' aux = base64.b64decode(texto[texto.find(",") + 1:] + "===") wav_result = open(name, 'wb') wav_result.write(aux) s3 = boto3.resource('s3', region_name='eu-west-3', config=boto3.session.Config(signature_version='s3v4')) # Please change name here with the name of your S3 bucket s3.meta.client.upload_file(name, 'sss-task-results-bucket', name) os.remove(name) def is_displayed(self): return self.round_number == 1 class Test1Run1(Page): form_model = models.Player form_fields = ['selection'] def before_next_page(self): self.player.participant.vars['run1_r1'] = self.player.selection def selection_choices(self): foo = ['OUI', 'NON'] return random.sample(foo, 2) class Test2Run1(Page): form_model = models.Player form_fields = ['selection'] def before_next_page(self): self.player.participant.vars['run1_r2'] = self.player.selection def selection_choices(self): foo = ['OUI', 'NON'] return random.sample(foo, 2) class Test3Run1(Page): form_model = models.Player form_fields = ['selection'] def before_next_page(self): self.player.participant.vars['run1_r3'] = self.player.selection def selection_choices(self): foo = ['OUI', 'NON'] return random.sample(foo, 2) class Test4Run1(Page): form_model = models.Player form_fields = ['selection'] def before_next_page(self): self.player.participant.vars['run1_r4'] = self.player.selection def selection_choices(self): foo = ['OUI', 'NON'] return random.sample(foo, 2) class Run2(Page): form_model = models.Player form_fields = ['audio_test2'] def before_next_page(self): texto = self.player.audio_test2 name = self.player.participant.vars['name'] + '_SSSTestImp_run2.wav' aux = base64.b64decode(texto[texto.find(",") + 1:] + "===") wav_result = open(name, 'wb') wav_result.write(aux) s3 = boto3.resource('s3', region_name='eu-west-3',config=boto3.session.Config(signature_version='s3v4')) s3.meta.client.upload_file(name, 'sss-task-results-bucket', name) os.remove(name) def is_displayed(self): return self.round_number == 1 class Test1Run2(Page): form_model = models.Player form_fields = ['selection'] def before_next_page(self): self.player.participant.vars['run2_r1'] = self.player.selection def selection_choices(self): foo = ['OUI', 'NON'] return random.sample(foo, 2) class Test2Run2(Page): form_model = models.Player form_fields = ['selection'] def before_next_page(self): self.player.participant.vars['run2_r2'] = self.player.selection def selection_choices(self): foo = ['OUI', 'NON'] return random.sample(foo, 2) class Test3Run2(Page): form_model = models.Player form_fields = ['selection'] def before_next_page(self): self.player.participant.vars['run2_r3'] = self.player.selection def selection_choices(self): foo = ['OUI', 'NON'] return random.sample(foo, 2) class Test4Run2(Page): form_model = models.Player form_fields = ['selection'] def selection_choices(self): foo = ['OUI', 'NON'] return random.sample(foo, 2) def before_next_page(self): self.player.participant.vars['run2_r4'] = self.player.selection class MicTest(Page): form_model = models.Player form_fields = ['audio_test2'] def is_displayed(self): return self.round_number == 1 def before_next_page(self): texto=self.player.audio_test2 name = self.player.participant.vars['name'] + '_mictestRep.mp3' aux=base64.b64decode(texto[texto.find(",")+1:] + "===") wav_result = open(name, 'wb') wav_result.write(aux) s3 = boto3.resource('s3', region_name='eu-west-3',config=boto3.session.Config(signature_version='s3v4')) s3.meta.client.upload_file(name, 'sss-task-results-bucket', name ) os.remove(name) page_sequence = [ Instructions, MicTest, VolumeAdjustment, Step1, Step2, Run1, Test1Run1, Test2Run1, Test3Run1, Test4Run1, Step1R, Step2R, Run2, Test1Run2, Test2Run2, Test3Run2, Test4Run2, #Demographics, Ending ]