From 0356e584160d88470570e0e7bb655b65749e9a9c Mon Sep 17 00:00:00 2001 From: Chris Midkiff Date: Fri, 15 May 2020 14:19:14 -0400 Subject: [PATCH] updated utils and added README --- utils/README.txt | 14 ++++++++++++++ utils/server.py | 21 ++++++++++++--------- utils/{sampleGen.py => trialGen.py} | 0 3 files changed, 26 insertions(+), 9 deletions(-) create mode 100644 utils/README.txt rename utils/{sampleGen.py => trialGen.py} (100%) diff --git a/utils/README.txt b/utils/README.txt new file mode 100644 index 0000000..4841b34 --- /dev/null +++ b/utils/README.txt @@ -0,0 +1,14 @@ +This a collection of utilites to make running the Fitts Law Experiment software easier. These all require a python3 install. + +trialGen.py +This generates trials based on a given number of trials and a number of dots per trial. You can edit your directions and distances in this file as well as what devices you are testing. +Please note that your number of trials times your number of dots per trial must be evenly divisble by the product of your distances and directions. The script will refuse to generate otherwise. + +console.py +This communicates with the server and updates the participant ID for a given input device. I recommend running an instance of this for each input device during data collection. + +server.py +This requires the python package flask (pip3 install flask). +This serves up the trial files generated by trialGen.py and is used by console.py to update the participant ID. +Simply run with python3 and it will begin running a server on port 5000 +Note: The devices running both the software and the console.py script need to have a network connection to wherever this server is running. \ No newline at end of file diff --git a/utils/server.py b/utils/server.py index 8ad7a40..ad13c2d 100644 --- a/utils/server.py +++ b/utils/server.py @@ -1,45 +1,48 @@ from flask import Flask, jsonify, request import json +import os app = Flask(__name__) +base = os.getcwd() + @app.route('/cardboard') def card(): - data = json.load(open('/home/chris/dev/thesis/cardTrials.json')) + data = json.load(open(base + '/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 = json.load(open(base + '/cardTrials.json')) data['participantId'] = id - json.dump(data,open('/home/chris/dev/thesis/cardTrials.json','w')) + json.dump(data,open(base + '/cardTrials.json','w')) return 'ok ' + str(id) @app.route('/oculus') def oculus(): - data = json.load(open('/home/chris/dev/thesis/oculusTrials.json')) + data = json.load(open(base + '/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 = json.load(open(base + '/oculusTrials.json')) data['participantId'] = id - json.dump(data,open('/home/chris/dev/thesis/oculusTrials.json','w')) + json.dump(data,open(base + '/oculusTrials.json','w')) return 'ok ' + str(id) @app.route('/mouse') def mouse(): - data = json.load(open('/home/chris/dev/thesis/mouseTrials.json')) + data = json.load(open(base + '/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 = json.load(open(base + '/mouseTrials.json')) data['participantId'] = id - json.dump(data,open('/home/chris/dev/thesis/mouseTrials.json','w')) + json.dump(data,open(base + '/mouseTrials.json','w')) return 'ok ' + str(id) if __name__ == '__main__': diff --git a/utils/sampleGen.py b/utils/trialGen.py similarity index 100% rename from utils/sampleGen.py rename to utils/trialGen.py