WorldViz User Forum

WorldViz User Forum (https://forum.worldviz.com/index.php)
-   Vizard (https://forum.worldviz.com/forumdisplay.php?f=17)
-   -   Visual Analog Scale (https://forum.worldviz.com/showthread.php?t=6297)

Roy 12-12-2019 11:39 PM

Visual Analog Scale
 
Hi,

Is there any example program for VAS (visual analog scale) to get participants' data?
Or, any functions for it?

Thanks

Jeff 12-13-2019 05:57 AM

There is no built-in VAS GUI object but it's possible to create one. Here is an example that adds a VAS slider to the ortho layer. The user can select a value between 0-10:

Code:

import viz
import viztask

VAS_MOVE_EVENT = viz.getEventID('VAS_MOVE_EVENT')
VAS_CONFIRM_EVENT = viz.getEventID('VAS_CONFIRM_EVENT')

class SliderVAS:
        """Add a VAS slider to the ortho layer"""
       
        def __init__(self, text, scale=2, left=viz.KEY_LEFT, right=viz.KEY_RIGHT, confirm=viz.KEY_RETURN):
                # parent the slider, slider numbers, and text to a group object
                self._group = viz.addGroup(parent=viz.ORTHO)
                viz.link(viz.CenterCenter,self._group)

                self.slider = viz.addSlider()
                self.slider.setParent(self._group)
                self.slider.setScale([scale,1,1])
                self.slider.setTickSize(.2,1)
                sliderWidth = self.slider.getBoundingBox()[0]
                stepWidth = sliderWidth/11

                self._text = viz.addText(text,parent=self._group)
                self._text.alignment( viz.ALIGN_CENTER_BOTTOM )
                self._text.setPosition(-0,-100)
                self._text.fontSize(45)

                for i in range(0,11):
                        slidernum = viz.addText(str(i),parent=self._group)
                        slidernum.alignment(viz.TEXT_CENTER_BOTTOM)
                        slidernum.setPosition(-sliderWidth/2*0.89 +(i*stepWidth*0.98),75,0)
                        slidernum.fontSize(40)
                       
                self._waitLeft = viztask.waitKeyDown(left)
                self._waitRight = viztask.waitKeyDown(right)
                self._waitConfirm = viztask.waitKeyDown(confirm)
                self._sliderStep = 0.1
                self._sliderschedule = viztask.schedule( self._moveSlider() )

        # get the slider value as a number between 0 and 10
        def getValue(self):
                value = int(round((self.slider.get() * 10.0)))
                return value

        def _moveSlider(self):
                while True:
                        d = yield viztask.waitAny([self._waitLeft,self._waitRight,self._waitConfirm])
                        if d.condition is self._waitLeft:
                                self.slider.set(self.slider.get()+ self._sliderStep * -1)
                                viz.sendEvent(VAS_MOVE_EVENT)
                        elif d.condition is self._waitRight:
                                self.slider.set(self.slider.get()+ self._sliderStep)
                                viz.sendEvent(VAS_MOVE_EVENT)
                        else:
                                viz.sendEvent(VAS_CONFIRM_EVENT)
                                break
                self._group.visible(viz.OFF)


if __name__ == '__main__':
        import vizinfo       
       
        viz.go()
        viz.window.setSize(1280,720)
        viz.clearcolor(viz.SLATE)
        vizinfo.InfoPanel('Use left and right arrow keys to move the slider\ntick and the Enter key to select a value')
       
        questions = ['How much do you like pizza?',
                                'How much do you like chocolate?']
        def surveyTask():               
                for question in questions:
                        vas = SliderVAS(question)
                        yield viztask.waitEvent(VAS_CONFIRM_EVENT)
                        print 'Value:',vas.getValue()
                print 'Survey complete'
               
        viztask.schedule( surveyTask() )



All times are GMT -7. The time now is 10:58 AM.

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