WorldViz User Forum

WorldViz User Forum (https://forum.worldviz.com/index.php)
-   Vizard (https://forum.worldviz.com/forumdisplay.php?f=17)
-   -   Problems saving my data (https://forum.worldviz.com/showthread.php?t=6320)

F_Rocabado 08-03-2020 12:56 PM

Problems saving my data
 
Hello everyone,
I've been working for a while now on the script I'm going to share down below. I have struggled a making my data iterable type so I could save it but now I don't know why it only saves the last trial data. All my experience with python comes by working on this script... any help will be very much appreciated it since I've been all day trying to figure out why this is happening with no luck :(

Code:

import viz
import viztask
import vizact
import vizinfo
import vizshape
import vizfx
import vizcam

import random

viz.setMultiSample(4)
viz.fov(60)
viz.go()

viz.MainView.move([-9,40,60])

#luz
viz.MainView.getHeadLight().disable()
light = viz.addLight(euler=(90, 89, 90))
light.position(1,1,1,0)
light.color(viz.WHITE)
light.ambient([1,1,1])
light.intensity(1)
light.spread(180)
viz.setOption('viz.lightModel.ambient',[0]*3)

#Clase
viz.clearcolor( viz.SLATE )
classroom = viz.add('classroom.osgb')

# cielo
classroom.getChild('pz_skydome').remove()
day = viz.add('sky_day.osgb')
day.renderToBackground()

# e_neutro
neutro = vizshape.addSphere(radius=5)
neutro.color(viz.WHITE)
neutro.setPosition([-4,60,150])
neutro.visible(False)

# Añadimos los objetos de la tarea
duck_der = viz.addChild('duck.wrl', parent = classroom)
duck_der.setPosition(13,55,150)
duck_der.setScale([15,15,15])
duck_der.visible(viz.OFF)

duck_izq = viz.addChild('duck.wrl', parent = classroom)
duck_izq.setPosition(-21,55,150)
duck_izq.setScale([15,15,15])
duck_izq.visible(viz.OFF)

wheelbarrow_der = viz.addChild('wheelbarrow.ive', parent = classroom)
wheelbarrow_der.setPosition(13,55,150)
wheelbarrow_der.setScale([15,15,15])
wheelbarrow_der.visible(viz.OFF)

wheelbarrow_izq = viz.addChild('wheelbarrow.ive', parent = classroom)
wheelbarrow_izq.setPosition(-21,55,150)
wheelbarrow_izq.setScale([15,15,15])
wheelbarrow_izq.visible(viz.OFF)

               
def despedida():
        fin = vizinfo.InfoPanel('Has terminado con el experimento')
        fin.visible(viz.ON)
        yield viztask.waitTime(3)
        fin.visible(viz.OFF)
       
results = []
obj = [duck_der, duck_izq, wheelbarrow_der, wheelbarrow_izq]
               
def Trial():
               
        neutro.visible(viz.ON)
        yield viztask.waitTime(0.65)
        neutro.visible(viz.OFF)
        for i in obj:
                print(1)
       
                object_d = random.choice(obj)
                object_d.visible(viz.ON)
               
               
                d = yield viztask.waitDraw()
               
                #prueba de que va bien
                print 'obj name:', object_d
                       
                #Tiempo desde que aparece el objeto en la pantalla
                displayTime = d.time

                #Teclas de ineterés
                d = yield viztask.waitKeyDown(('f', 'j'))

                #Calculamos el tiempo de reacción
                reactionTime = d.time - displayTime
                p_key = d.key

                #Prueba de que el tiempo de reaccion es correcto
                print 'Reaction time:',reactionTime
                print 'key:',p_key                       
                       
                #Apagamso los objetos
                wheelbarrow_der.visible(viz.OFF)
                duck_der.visible(viz.OFF)
                wheelbarrow_izq.visible(viz.OFF)
                duck_izq.visible(viz.OFF)
                       
                results.append((object_d, p_key,reactionTime))
                       
                #Tiempo de espera entre ensayos
                yield viztask.waitTime(1)       
                       
                #resultados
        viztask.returnValue(results)
               
       
def Experiment():
       
        yield Trial()
        yield despedida()
       
        #Log trials to file
        try:
                with open('Data.txt','w') as f:
                        for object_d, p_key,reactionTime in results:
                                data = (str(object_d)+'\t'+ str (p_key)+'\t'+ str(reactionTime)+'\n')
                                f.write(data)
                                print out
        except IOError:
                viz.logWarn('Could not log results to file. Make sure you have permission to write to folder')
                       
viztask.schedule( Experiment() )



All times are GMT -7. The time now is 05:54 PM.

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