Added utils and updated unity version
This commit is contained in:
14
utils/console.py
Normal file
14
utils/console.py
Normal file
@@ -0,0 +1,14 @@
|
||||
import requests
|
||||
base = input('Enter URL of server instance (http://example.com): ')
|
||||
device = input('Which input method are we managing?: ')
|
||||
while True:
|
||||
choice = input('Enter Participant ID (or quit): ')
|
||||
if choice == 'quit':
|
||||
break
|
||||
r = requests.post(base + '/' + device + 'Post',data={'id':choice})
|
||||
if r.status_code is 200:
|
||||
print('Updated')
|
||||
else:
|
||||
print('Error occured')
|
||||
print(r.status_code)
|
||||
print(r.text)
|
||||
38
utils/sampleGen.py
Normal file
38
utils/sampleGen.py
Normal file
@@ -0,0 +1,38 @@
|
||||
import json
|
||||
from random import choice,shuffle
|
||||
direction = ["Up","Left","Right"]
|
||||
distance = ["Short","Medium","Long"]
|
||||
devices = ["cardboard","mouse","oculus"]
|
||||
options = []
|
||||
for x in direction:
|
||||
for y in distance:
|
||||
options.append(x+y)
|
||||
print(options)
|
||||
numDots = int(input("Number of Dots per Trial: "))
|
||||
numTrials = int(input("Number of Trials: "))
|
||||
totalNum = numDots * numTrials
|
||||
mod = totalNum % len(options)
|
||||
dots = []
|
||||
if mod is 0:
|
||||
c = totalNum//len(options)
|
||||
for option in options:
|
||||
dots = dots + ([option] * c)
|
||||
print(dots.count(option))
|
||||
shuffle(dots)
|
||||
print(dots)
|
||||
trials = []
|
||||
for x in range(numTrials):
|
||||
trial = []
|
||||
for y in range(numDots):
|
||||
trial.append(dots.pop())
|
||||
trials.append(trial)
|
||||
root = {}
|
||||
for d in devices:
|
||||
root['trials'] = trials
|
||||
root['inputMethod'] = d
|
||||
root['participantId'] = 0
|
||||
with open(d+'Trials.json','w') as f:
|
||||
json.dump(root,f,indent=4)
|
||||
|
||||
else:
|
||||
print("Please enter evenly divisible numbers")
|
||||
47
utils/server.py
Normal file
47
utils/server.py
Normal file
@@ -0,0 +1,47 @@
|
||||
from flask import Flask, jsonify, request
|
||||
import json
|
||||
app = Flask(__name__)
|
||||
|
||||
@app.route('/cardboard')
|
||||
def card():
|
||||
data = json.load(open('/home/chris/dev/thesis/cardTrials.json'))
|
||||
return jsonify(data)
|
||||
|
||||
@app.route('/cardboardPost', methods=['POST'])
|
||||
def cardPost():
|
||||
id = int(request.args.get('id', ''))
|
||||
data = json.load(open('/home/chris/dev/thesis/cardTrials.json'))
|
||||
data['participantId'] = id
|
||||
json.dump(data,open('/home/chris/dev/thesis/cardTrials.json','w'))
|
||||
return 'ok ' + str(id)
|
||||
|
||||
|
||||
@app.route('/oculus')
|
||||
def oculus():
|
||||
data = json.load(open('/home/chris/dev/thesis/oculusTrials.json'))
|
||||
return jsonify(data)
|
||||
|
||||
@app.route('/oculusPost',methods=['POST'])
|
||||
def oculusPost():
|
||||
id = int(request.args.get('id', ''))
|
||||
data = json.load(open('/home/chris/dev/thesis/oculusTrials.json'))
|
||||
data['participantId'] = id
|
||||
json.dump(data,open('/home/chris/dev/thesis/oculusTrials.json','w'))
|
||||
return 'ok ' + str(id)
|
||||
|
||||
@app.route('/mouse')
|
||||
def mouse():
|
||||
data = json.load(open('/home/chris/dev/thesis/mouseTrials.json'))
|
||||
return jsonify(data)
|
||||
|
||||
@app.route('/mousePost',methods=['POST'])
|
||||
def mousePost():
|
||||
id = int(request.args.get('id', ''))
|
||||
data = json.load(open('/home/chris/dev/thesis/mouseTrials.json'))
|
||||
data['participantId'] = id
|
||||
json.dump(data,open('/home/chris/dev/thesis/mouseTrials.json','w'))
|
||||
return 'ok ' + str(id)
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.debug = False
|
||||
app.run(host = '0.0.0.0',port=5000)
|
||||
Reference in New Issue
Block a user