WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 08-03-2020, 12:56 PM
F_Rocabado F_Rocabado is offline
Member
 
Join Date: Jul 2020
Posts: 2
Unhappy 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() )
Reply With Quote
  #2  
Old 08-25-2021, 10:45 AM
mspusch mspusch is offline
WorldViz Team Member
 
Join Date: Feb 2003
Posts: 223
Hi Rocabado,

Hope all is well. We are just working thru a clean-up here with our support systems and from what we can tell, your support ended up happening in the WorldViz closed support ticket system for our customers with Support contracts (under support@worldviz.com), and hopefully your questions have all been addressed?

Sorry for not answering earlier here, and thanks for being a Worldviz customer.

All best,

Matthias
Reply With Quote
Reply

Tags
data, experiment, task


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Vizard and Matlab sagar29 Vizard 7 12-25-2017 11:36 PM
Sending data from MATLAB(Simulink) to Vizard sagar29 Vizard 0 01-05-2017 04:31 PM
Any experience with Polaris Spectra? VRPN is providing bad data! performlabrit Vizard 0 06-29-2016 03:19 PM
Use saved text file data as replay sources problem mizutani_jun Vizard 4 10-14-2010 05:49 PM
tracking using quaternarion data jfreeman Vizard 2 06-01-2005 09:48 AM


All times are GMT -7. The time now is 02:23 AM.


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