NTX-McGill / NeuroTechX-McGill-2021

Other
16 stars 5 forks source link

added routes for backend to start,stop, begin and end collecting #91

Closed wykzhang closed 2 years ago

wykzhang commented 2 years ago

Issues linked: closes #86, closes #87, closes #88, closes #89 Workflow:

  1. Client will perform GET FLASKAPP/api/openbci/start to start the bci stream process, and the response will only come once the stream process is connected to the bci machine. The response will contain the process_id
  2. Once the client is ready to begin collecting data for a character, it will send a request at POST FLASKAPP/api/openbci/:process_id/collect/start with a request form containing the following information:
    • character
    • phase
    • frequency
  3. Once the client wants to stop recording the information, it will send a request to POST FLASKAPP/api/openbci/:process_id/collect/stop, and the backend will upload the information to the db for the character that just stopped recording. The response will only return once the backend has finished uploading the data to the db
  4. The client can now repeat steps 2 and 3 for all the required characters.
  5. Once the client has finished obtaining results for all characters, it may call the endpoint POST FLASKAPP/api/openbci/:process_id/stop to close the subprocess. If the process is still recording information or if it is still in the midst of uploading data, it should return the appropriate error in a message.

Testing: The above workflow has been tested on a local database running in docker, and all the endpoints were tested in a simple smoke test with dummy data from openBCI.

No substantial delay was noticed when uploading around 5 seconds of data, but additional testing may be required depending on the use case.

I suggest additional testing with production database, and with the actual equipment.

Shared dictionary: This is the template for the new shared dictionary between the flask app and subprocesses:

 bci_processes_states = {process_id: {
   character : str, 
   phase: float, 
   frequency: float, 
   q: Queue, 
   config_id: int,
   bci_config: str,
  state: str (Could be either start, ready, collect, stop)
   }
 }

The state allows the subprocess to act as a simple state machine, where its action performed will depend on the state given by the parent process

mlej8 commented 2 years ago

tagging @HassanKanj16 and @TheMatrixMaster to keep you up to date with backend progress.