elephant_vending_machine.views module¶
Define all routes for the behavioral experiment server.
Here, all API routes for the experiment server are defined. Consider splitting into its own package if end up being a lot of routes.
-
elephant_vending_machine.views.add_remote_group(group_name)[source]¶ Adds a group to the remote hosts defined in flask config.
- Parameters
group_name (str) – The filename of the local group to be copied
- Raises
CalledProcessError – If scp or ssh calls fail for one of the hosts
-
elephant_vending_machine.views.add_remote_image(local_image_path, group, filename)[source]¶ Adds an image to the remote hosts defined in flask config.
- Parameters
local_image_path (str) – The local path of the image to be copied
filename (str) – The filename of the local file to be copied
- Raises
CalledProcessError – If scp or ssh calls fail for one of the hosts
-
elephant_vending_machine.views.allowed_experiment(name)[source]¶ Determines whether a group exists in the directory already
-
elephant_vending_machine.views.allowed_file(filename, allowed_extensions)[source]¶ Determines whether an uploaded image file has an allowed extension.
- Parameters
filename (str) – The filename which is to be checked
allowed_extensions (array of str) – The allowed file extensions
- Returns
True if filename includes extension and extension is an allowed extension False otherwise
-
elephant_vending_machine.views.allowed_group(name)[source]¶ Determines whether a group exists in the directory already
-
elephant_vending_machine.views.copy_image(group, image)[source]¶ Returns a message indicating whether copying of the specified file was successful
Example request:
POST /test1/blank.jpg/copy HTTP/1.1 Host: 127.0.0.1 Content-Type: multipart/form-data; boundary=--------------------------827430006917349763475527 Accept-Encoding: gzip, deflate, br Content-Length: 737067 Connection: keep-alive ----------------------------827430006917349763475527 Content-Disposition: form-data; name="test2" {name: "test2"} ----------------------------827430006917349763475527--
Example response:
HTTP/1.0 200 OK Content-Type: application/json Content-Length: 59 Access-Control-Allow-Origin: * Server: Werkzeug/0.16.1 Python/3.8.2 Date: Fri, 27 Mar 2020 16:13:42 GMT { "message": "File blank.jpg was successfully copied to group 'test2'." }
- Status 200
image file successfully copied
- Status 400
group with specified name could not be found
-
elephant_vending_machine.views.create_experiment_from_form()[source]¶ Return JSON body with message indicating result of group creation request
-
elephant_vending_machine.views.create_group()[source]¶ Return JSON body with message indicating result of group creation request
-
elephant_vending_machine.views.delete_experiment(filename)[source]¶ Returns a message indicating whether deletion of the specified file was successful
Example request:
DELETE /experiment/empty.py HTTP/1.1 Host: 127.0.0.1 Accept-Encoding: gzip, deflate, br Connection: keep-alive
Example response:
HTTP/1.0 200 OK Content-Type: application/json Content-Length: 59 Access-Control-Allow-Origin: * Server: Werkzeug/0.16.1 Python/3.8.2 Date: Fri, 27 Mar 2020 16:13:42 GMT { "message": "File empty.py was successfully deleted." }
- Status 200
experiment file successfully deleted
- Status 400
file with specified name could not be found
-
elephant_vending_machine.views.delete_group(name)[source]¶ Return JSON body with message indicating result of group deletion request
-
elephant_vending_machine.views.delete_image(group, filename)[source]¶ Returns a message indicating whether deletion of the specified file was successful
Example request:
DELETE /image/group-name/blank.jpg HTTP/1.1 Host: 127.0.0.1 Accept-Encoding: gzip, deflate, br Connection: keep-alive
Example response:
HTTP/1.0 200 OK Content-Type: application/json Content-Length: 59 Access-Control-Allow-Origin: * Server: Werkzeug/0.16.1 Python/3.8.2 Date: Fri, 27 Mar 2020 16:13:42 GMT { "message": "File blank.jpg was successfully deleted." }
- Status 200
image file successfully deleted
- Status 400
file with specified name could not be found
-
elephant_vending_machine.views.delete_log(filename)[source]¶ Returns a message indicating whether deletion of the specified file was successful
Example request:
DELETE /log/somelog.csv HTTP/1.1 Host: 127.0.0.1 Accept-Encoding: gzip, deflate, br Connection: keep-alive
Example response:
HTTP/1.0 200 OK Content-Type: application/json Content-Length: 59 Access-Control-Allow-Origin: * Server: Werkzeug/0.16.1 Python/3.8.2 Date: Fri, 27 Mar 2020 16:13:42 GMT { "message": "File somelog.csv was successfully deleted." }
- Status 200
log file successfully deleted
- Status 400
file with specified name could not be found
-
elephant_vending_machine.views.delete_remote_group(group_name)[source]¶ Deletes a group from the remote hosts defined in flask config.
- Parameters
group_name (str) – The name of the remote group to be deleted
- Raises
CalledProcessError – If scp or ssh calls fail for one of the hosts
-
elephant_vending_machine.views.delete_remote_image(group, filename)[source]¶ Deletes an image from the remote hosts defined in flask config.
- Parameters
filename (str) – The filename of the remote file to be deleted
- Raises
CalledProcessError – If scp or ssh calls fail for one of the hosts
-
elephant_vending_machine.views.download_example_path(filename='form_template.py')[source]¶ Return file to be downloaded
-
elephant_vending_machine.views.get_signal()[source]¶ Receives a signal from monitor pi, and sets the vending machine’s signal_sender variable
-
elephant_vending_machine.views.list_experiments()[source]¶ Returns a list of experiments from the experiment directory
Example request:
GET /experiment HTTP/1.1 Host: 127.0.0.1 Accept-Encoding: gzip, deflate, br Connection: keep-alive
Example response:
HTTP/1.0 200 OK Content-Type: application/json; charset=utf-8 Content-Length: 212 Server: Werkzeug/0.16.1 Python/3.8.1 Date: Thu, 13 Feb 2020 15:35:32 GMT { "files": [ "http://localhost/static/experiment/exampleExperiment.py", "http://localhost/static/experiment/testColorPerception.py" ] }
- Status 200
experiment file list successfully returned
-
elephant_vending_machine.views.list_groups()[source]¶ Return JSON body with message of all folders in the static/img directory
-
elephant_vending_machine.views.list_images(group)[source]¶ Returns a list of images from the images directory
Example request:
GET /image HTTP/1.1 Host: 127.0.0.1 Accept-Encoding: gzip, deflate, br Connection: keep-alive
Example response:
HTTP/1.0 200 OK Content-Type: application/json; charset=utf-8 Content-Length: 212 Server: Werkzeug/0.16.1 Python/3.8.1 Date: Thu, 13 Feb 2020 15:35:32 GMT { "files": [ "http://localhost/static/img/allBlack.png", "http://localhost/static/img/whiteStimuli.png" ] }
- Status 200
image file list successfully returned
-
elephant_vending_machine.views.list_logs()[source]¶ Returns a list of log resources from the log directory.
Example request:
GET /log HTTP/1.1 Host: 127.0.0.1 Accept-Encoding: gzip, deflate, br Connection: keep-alive
Example response:
HTTP/1.0 200 OK Content-Type: application/json; charset=utf-8 Content-Length: 212 Server: Werkzeug/0.16.1 Python/3.8.1 Date: Thu, 13 Feb 2020 15:35:32 GMT { "files": [ "http://localhost:5000/static/log/2020-03-17 04:26:02.085651 exampleExperiment.csv", "http://localhost:5000/static/log/2020-03-17 04:27:04.019992 exampleExperiment.csv" ] }
- Status 200
log file list successfully returned
-
elephant_vending_machine.views.run_experiment(filename)[source]¶ Start execution of experiment python file specified by user
Example request:
POST /run-experiment?name=example_experiment HTTP/1.1 Host: localhost:5000 Accept-Encoding: gzip, deflate, br Content-Length: Connection: keep-alive
Example response:
HTTP/1.0 200 OK Content-Type: application/json; charset=utf-8 Content-Length: 88 Server: Werkzeug/0.16.1 Python/3.8.1 Date: Thu, 13 Feb 2020 15:35:32 GMT { "log_file": "2020-03-17 05:15:06.558356 example_experiment.csv", "message": "Running example_experiment" }
All requests sent to this route should have an experiment file included as a query parameter, otherwise a 400 error will be returned
- Status 200
experiment started
- Status 400
malformed request
-
elephant_vending_machine.views.upload_experiment()[source]¶ Return JSON body with message indicating result of experiment upload request
Example request:
POST /experiment HTTP/1.1 Host: 127.0.0.1:5000 Content-Type: multipart/form-data; boundary=--------------------------827430006917349763475527 Accept-Encoding: gzip, deflate, br Content-Length: 737067 Connection: keep-alive ----------------------------827430006917349763475527 Content-Disposition: form-data; name="file"; filename="elephant.py" <elephant.py> ----------------------------827430006917349763475527--
Example response:
HTTP/1.0 200 OK Content-Type: text/html; charset=utf-8 Content-Length: 21 Server: Werkzeug/0.16.1 Python/3.8.1 Date: Thu, 13 Feb 2020 15:35:32 GMT { "message":"Success: Experiment saved." }
All requests sent to this route should have a python script file included in the body of the request, otherwise a 400 error will be returned
- Status 201
file saved
- Status 400
malformed request
-
elephant_vending_machine.views.upload_image(group)[source]¶ Return string indicating result of image upload request
Example request:
POST /image HTTP/1.1 Host: 127.0.0.1:5000 Content-Type: multipart/form-data; boundary=--------------------------827430006917349763475527 Accept-Encoding: gzip, deflate, br Content-Length: 737067 Connection: keep-alive ----------------------------827430006917349763475527 Content-Disposition: form-data; name="file"; filename="elephant.jpeg" <elephant.jpeg> ----------------------------827430006917349763475527--
Example response:
HTTP/1.0 200 OK Content-Type: text/html; charset=utf-8 Content-Length: 21 Server: Werkzeug/0.16.1 Python/3.8.1 Date: Thu, 13 Feb 2020 15:35:32 GMT { "message":"Success: Image saved." }
All requests sent to this route should have an image file included in the body of the request, otherwise a 400 error will be returned
- Status 201
file saved
- Status 400
malformed request