diff --git a/analysis_server/app.py b/analysis_server/app.py index 3ddff9e5..59cbbf78 100644 --- a/analysis_server/app.py +++ b/analysis_server/app.py @@ -7,12 +7,19 @@ import time from PIL import Image from flask_cors import CORS +import base64 import eeg app = Flask(__name__) CORS(app, resources={r"/api/*": {"origins": "*"}}) + +def encode_image_to_base64(image_path): + with open(image_path, "rb") as image_file: + encoded_string = base64.b64encode(image_file.read()).decode('utf-8') + return encoded_string + # TODO: handle multiple files @app.route('/api/v1/process_eeg', methods=['POST']) def process(): @@ -66,14 +73,23 @@ def process(): powerComparisonImage = Image.fromarray(powerComparisonData) powerComparisonImage.save("powerComparisons.png") + powerDistributionBase64= encode_image_to_base64("powerDistributions.png") + powerComparisonBase64 = encode_image_to_base64("powerComparisons.png") - # remember to delete folder after processing - return jsonify({"files": os.listdir(temp_dir)}), 200 + # do foof analysis and display that + + # # remember to delete folder after processing + return jsonify({"images": { + "powerDistribution": powerDistributionBase64, + "powerComparison": powerComparisonBase64 + }, "summary": "Steady State Frequency Averages from Recordings"}), 200 except Exception as e: print("error", e) return jsonify({'error': str(e)}), 500 +# TODO: endpoint for ERP analysis + if __name__ == '__main__': app.run(debug=True, port=8000) diff --git a/analysis_server/eeg.py b/analysis_server/eeg.py index c24a796d..825462c2 100644 --- a/analysis_server/eeg.py +++ b/analysis_server/eeg.py @@ -299,7 +299,7 @@ def load_session_epochs(files: dict, _on: set, _channels: list = [],qualityCutof return on -def load_session_summery(files: dict, _channels: list = [], qualityCutoffFilter: int = 0, epochSize: int = -1, returnEpoched = False, debug=False) -> dict: +def load_session_summary(files: dict, _channels: list = [], qualityCutoffFilter: int = 0, epochSize: int = -1, returnEpoched = False, debug=False) -> dict: """ Takes a session of EEG data, computes some metrics, and returns them. @@ -457,10 +457,10 @@ def __init__(self,fileBundles: dict,epochSize=5, qualityCutoffFilter=0.95, debug if bundleType == "tags": # this means it's a dict of datasets based on tags # this means it's an array of datasets based on tags for y in self.fileBundles[x]: - self.fileBundleSummeries[x].append(load_session_summery(self.fileBundles[x][y],qualityCutoffFilter=qualityCutoffFilter,epochSize=epochSize,returnEpoched=True,debug=debug)) + self.fileBundleSummeries[x].append(load_session_summary(self.fileBundles[x][y],qualityCutoffFilter=qualityCutoffFilter,epochSize=epochSize,returnEpoched=True,debug=debug)) sum += len(self.fileBundleSummeries[x][-1]) elif bundleType == "ids": - self.fileBundleSummeries[x].append(load_session_summery(self.fileBundles[x],qualityCutoffFilter=qualityCutoffFilter,epochSize=epochSize,returnEpoched=True,debug=debug)) + self.fileBundleSummeries[x].append(load_session_summary(self.fileBundles[x],qualityCutoffFilter=qualityCutoffFilter,epochSize=epochSize,returnEpoched=True,debug=debug)) sum += len(self.fileBundleSummeries[x]) else: raise Exception("Invalid bundleType") @@ -736,10 +736,4 @@ def load_fileset( continue *type, session = f.stem.split("_") sessions[session]["_".join(type)] = str(f) - return sessions - - -if __name__ == "__main__": - df = load_data() - print(df) - print(df.describe()) \ No newline at end of file + return sessions \ No newline at end of file