WorldViz User Forum

WorldViz User Forum (https://forum.worldviz.com/index.php)
-   Vizard (https://forum.worldviz.com/forumdisplay.php?f=17)
-   -   check user input using vizinfo panel (https://forum.worldviz.com/showthread.php?t=5266)

armo 01-22-2015 02:05 AM

check user input using vizinfo panel
 
Dear all

I am running an experiment with a 3x2 design, so that I have two variables, one with three levels and the other one with two.
Before the experiment starts, the experimenter has to choose what sequence of two levels, each from one of the two variables, have to be presented, but I would like to create a mechanism that controls if the input sequence has already been chosen. Specifically, I posed these conditions:

- if the sequence of variables has not already been chosen, the execution flow keeps going on
- if the sequence of variables has already been chosen but the experiment wants to go on anyway, the output data are renamed to prevent overwriting.
- if the sequence of variables has already been chosen and the experimenter wants to choose another sequence, turns back to the vizinfo panel.

The first two conditions work, but the third doesn't. Specifically, the user can choose another sequence but when he hits again the run button nothing happens and so the experiment doesn't go on. Could anyone tell me where I did wrong in my code?


best regards,
armo

Code:

import viz
import vizinfo

class Experiment:
        def __init__(self,title):
                self.title = title
       
# create a class object with the current experiment data
current_exp = Experiment('current experiment')


class ExperimentalSetting:
        def __init__(self, var1=None, var2=None):
                self.var1 = var1
                self.var2 = var2

class ExperimentalSession:
        def __init__(self, phase=None, number=None):
                self.phase = phase
                self.number = number
                self.settings = ExperimentalSetting()
                               
        def __repr__(self):
                return self.phase + ' ' + str(self.number)


# create a class object with the current session data
current_session = ExperimentalSession()       

viz.go()

def get_session_info():
        global phase
        global current_session
        global current_RT_file
        global current_ACC_file

        import os
        def check_existing_file(file_name, extension):
                '''checks if a file already exists'''
                if        os.path.exists( file_name + extension ):
                        print 'file already exists...'       
                        return True
                else: return False
               
        def add_suffix(f):
                '''adds a suffix to a file.
                Used when a file already exists'''
                copy_suffix = 'Copy'
                f = f + ' - ' +  copy_suffix
                return f       
       
        def rename_existing_file(file_name, extension):
                '''if a file already exists, rename it with a suffix extension'''
                if        check_existing_file(file_name, extension):
                        checked_fileName = add_suffix(file_name) + extension
                else: checked_fileName = file_name + extension
                return checked_fileName       
       
        current_RT_file        = None
        current_ACC_file = None
       
        isEqual = False
        while not isEqual:
                print 'displaying vizinfo box'
                #Add the vizinfo box
                infoBox = vizinfo.add('')
                infoBox.scale(1.5,1.5)
                infoBox.translate( 0.85, 0.95 )
                infoBox.title('Experiment Info: ' + current_exp.title)
               
                #Add the GUI elements to the box
                phaseTrainingBox = infoBox.add(viz.RADIO,1,'Training')
                phaseExperimentBox = infoBox.add(viz.RADIO,1,'Experiment')
                variable1_A_Box = infoBox.add(viz.RADIO,2,'A')
                variable1_B_Box = infoBox.add(viz.RADIO,2,'B')
                variable1_C_Box = infoBox.add(viz.RADIO,2,'C')
                variable2_1_Box = infoBox.add(viz.RADIO,3,'1')
                variable2_2_Box = infoBox.add(viz.RADIO,3,'2')

                runButton = infoBox.add(viz.BUTTON,'Run')

                # waits for pressing the runbutton to go forward
                yield viztask.waitButtonUp(runButton)

                # get the current session settings
                if phaseTrainingBox.get() == viz.DOWN:
                        current_session.phase = 'Training'
                elif phaseExperimentBox.get() == viz.DOWN:
                        current_session.phase = 'Experiment'
                       
                if variable1_A_Box.get() == viz.DOWN:
                        current_session.settings.var1 = 'A'
                elif variable1_B_Box.get() == viz.DOWN:
                        current_session.settings.var1 = 'B'
                elif variable1_C_Box.get() == viz.DOWN:
                        current_session.settings.var1 = 'B'
                       
                if variable2_1_Box.get() == viz.DOWN:
                        current_session.settings.var2 = '1'
                elif variable2_2_Box.get() == viz.DOWN:
                        current_session.settings.var2 = '2'

                current_file_labels = [
                current_session.phase,
                current_session.settings.var1,
                current_session.settings.var2,
                ]

                # create two files object with the experiment RT and ACC data
                RT_folder = 'data/RT/'
                ACC_folder = 'data/ACC/'

                current_RT_file_name = RT_folder + '_'.join(current_file_labels) + '_RT'       
                current_ACC_file_name = ACC_folder +  '_'.join(current_file_labels) + '_ACC'
               
                print current_RT_file_name
               
                if check_existing_file(current_RT_file_name, '.txt') and check_existing_file(current_ACC_file_name, '.txt'):
                        answer = viz.ask('this sequence has already been chosen. Continue?')
                        if answer:               
                                print 'chose to continue and rename file'
                                current_RT_file = open( rename_existing_file(current_RT_file_name, '.txt'),'w')
                                current_ACC_file = open( rename_existing_file(current_ACC_file_name, '.txt'),'w')
                                isEqual = True
                        else:
                                print 'chose not to continue'
                                return
                else:
                        print 'the file names don\'t already exist'
                        current_RT_file = open( current_RT_file_name + '.txt','w')
                        current_ACC_file = open( current_ACC_file_name + '.txt','w')
                        break
       
        infoBox.remove()
               
        print 'current settings:', [x for x in current_file_labels]

def experimental_flow():
        yield get_session_info()
       
import viztask
viztask.schedule(experimental_flow)



All times are GMT -7. The time now is 01:48 AM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Copyright 2002-2023 WorldViz LLC