Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
153 additions
and
211 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# Expfactory Server (SQL) | ||
|
||
This will provide a static (SQL) server setup, that can either be run on a server natively (locally), or with a MySQL Dockerized database. Instructions for composer are included below: | ||
|
||
- Integration with [Concerto](https://github.com/campsych/concerto-platform/wiki): | ||
|
||
The basic instructions are also included here. | ||
|
||
|
||
## Customizing your SQL Server | ||
This is primarily intended for development, and if you would like a complete Dockerized application we recommend either using expfactory-docker or submitting a PR to this repo. The following command, run from this directory, will set up a mysql database available on port 3306 called `expfactory-mysql` | ||
|
||
docker run \ | ||
--detach \ | ||
--name=expfactory-mysql \ | ||
--env="MYSQL_ROOT_PASSWORD=composer" \ | ||
--env="MYSQL_USER=composer" \ | ||
--env="MYSQL_PASSWORD=composer" \ | ||
--publish 6603:3306 \ | ||
--volume=conf.d:/etc/mysql/conf.d \ | ||
--volume=data:/var/lib/mysql \ | ||
mysql | ||
|
||
After doing the above, you will want to copy the sql file into the container, and run it to configure the database: | ||
|
||
|
||
docker cp create_expfactory_table.sql expfactory-mysql:/create_expfactory_table.sql | ||
docker exec -it expfactory-mysql mysql -u=composer -password=composer > create_expfactory_table.sql | ||
|
||
You of course (are recommended) to set up a proper database. If you use the setup provided above, continue. Otherwise, be sure to change the host/etc credentials in `create_expfactory_table.php` and `database_conncect.php`. | ||
|
||
|
||
## Generating the battery | ||
If you have a server that can serve static files and want to deploy experiments using a MySQL database, this is the solution you should try. The batteries themselves are stored as static html files with a uid parameter in the query string to pass the subject id: e.g. `https://mywebserver/itest/digit_span-en/?uid=123456789` | ||
|
||
PHP scripts, also hosted by the web server, are called on experiment completion to save the results (in JSON format) to your MySQL database. | ||
|
||
This folder contains the required server resources to deploy. | ||
Ensure to define your database connection parameters in `database_connect.php.` | ||
In this folder, you will also find a [create_expfactory_table.sql](create_expfactory_table.sql) and a [concerto.conf](concerto.conf) file as an example of how to make [Concerto](https://github.com/campsych/concerto-platform/wiki). | ||
|
||
### 1. Edit your post url | ||
Edit the `post_url` variable in [webserver-battery-template.html](templates/webserver-battery-template.html) to change the default URL to the PHP script (`/itest/save_data.php`) if needed. If not a local URL, cross-origin resource sharing should be enabled : refer to [http://enable-cors.org/server_apache.html](http://enable-cors.org/server_apache.html) | ||
|
||
### 2. Generate your static files | ||
Then run [setup_battery_for_webserver.py](setup_battery_for_webserver.py) to generate the battery in a specified output folder (likely a web directory) | ||
|
||
|
||
python setup_battery_for_webserver.py --output /var/www/vhosts/expfactory-server/digit_span-en --experiments digit_span | ||
|
||
|
||
### 3. Testing | ||
Though the [run_battery.py](run_battery.py) script has no use in production, you may test your batteries easily with: | ||
|
||
|
||
python run_battery.py --port 8080 /var/www/vhosts/expfactory-server/digit_span-en |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
mysql: [Warning] Using a password on the command line interface can be insecure. | ||
ERROR 1045 (28000): Access denied for user '=composer'@'localhost' (using password: YES) | ||
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
from expfactory.battery import * | ||
from expfactory.utils import copy_directory | ||
from expfactory.vm import download_repo | ||
import argparse | ||
from glob import glob | ||
import os | ||
import sys | ||
import shutil | ||
import tempfile | ||
|
||
|
||
# Get CLI parameters | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument('--output', dest="output", help='Battery output directory',default=None) | ||
parser.add_argument('--experiments', dest="experiments", help='Experiment(s) to use in the battery, separated by commas.') | ||
|
||
try: | ||
args = parser.parse_args() | ||
except: | ||
parser.print_help() | ||
sys.exit(0) | ||
|
||
if args.output != None: | ||
if os.path.exists(args.output): | ||
print("Output directory should not exist, remove and run again.") | ||
sys.exit(0) | ||
|
||
|
||
# We will set up the repo downloads, etc, in a temporary place | ||
working_dir = tempfile.mkdtemp() | ||
experiments = ",".split(args.experiments) | ||
|
||
# Download the missing repos | ||
battery_repo='battery' | ||
experiment_repo='experiments' | ||
survey_repo='surveys' | ||
game_repo='games' | ||
|
||
# Download repos to working directory | ||
print('Downloading expfactory repos...') | ||
for repo in (battery_repo, experiment_repo, survey_repo, game_repo): | ||
folder = "%s/%s" %(working_dir,repo) | ||
if not (os.path.isdir(folder)): | ||
download_repo(repo_type=repo, | ||
destination=folder) | ||
|
||
battery_dest = "%s/%s" %(working_dir,battery_repo) | ||
|
||
# Generate battery with the experiment(s) | ||
print('Generating base...') | ||
base = generate_base(battery_dest=battery_dest, | ||
tasks=experiments, | ||
experiment_repo="%s/%s" %(working_dir,experiment_repo), | ||
survey_repo="%s/%s" %(working_dir,survey_repo), | ||
game_repo="%s/%s" %(working_dir,game_repo), | ||
add_experiments=True, | ||
add_surveys=False, | ||
add_games=False, | ||
battery_repo=battery_dest) | ||
|
||
# Customize the battery | ||
custom_variables = dict() | ||
custom_variables["load"] = [("[SUB_TOTALTIME_SUB]", 30)] | ||
|
||
template_exp = "templates/webserver-battery-template.html" | ||
template_exp_output = "%s/index.html" %(base["battery_repo"]) | ||
|
||
print('Generating experiment and battery templates...') | ||
template_experiments(battery_dest=base["battery_repo"], | ||
battery_repo=base["battery_repo"], | ||
valid_experiments=base["experiments"], | ||
custom_variables=custom_variables, | ||
template_exp=template_exp, | ||
template_exp_output=template_exp_output) | ||
|
||
# Copy needed php files there | ||
add_files = glob("%s/*.php" %os.getcwd()) | ||
for add_file in add_files: | ||
shutil.copyfile(add_file,"%s/%s" %(base['battery_repo'], | ||
os.path.basename(add_file))) | ||
|
||
# Remove git data from the battery | ||
if args.output != None: | ||
copy_directory(base["battery_repo"],args.output) | ||
battery_dest = args.output | ||
|
||
print('Battery generated in %s' %(battery_dest)) | ||
shutil.rmtree(working_dir) |
File renamed without changes.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.