From ae3d6913d5e88cff8bf29cbe292a6ba832390bfc Mon Sep 17 00:00:00 2001 From: Niklas Date: Mon, 23 Oct 2023 15:55:20 +0200 Subject: [PATCH] get plot data --- fedn/fedn/network/api/interface.py | 26 ++++++++++++++++++++++++++ fedn/fedn/network/api/server.py | 14 ++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/fedn/fedn/network/api/interface.py b/fedn/fedn/network/api/interface.py index e45d15919..effcaa05d 100644 --- a/fedn/fedn/network/api/interface.py +++ b/fedn/fedn/network/api/interface.py @@ -7,6 +7,7 @@ from flask import jsonify, send_from_directory from werkzeug.utils import secure_filename +from fedn.network.dashboard.plots import Plot from fedn.common.config import get_controller_config, get_network_config from fedn.network.combiner.interfaces import ( @@ -733,6 +734,31 @@ def get_client_config(self, checksum=True): payload["checksum"] = checksum_str return jsonify(payload) + def get_plot_data(self, feature=None): + """Get plot data. + + :return: The plot data as json response. + :rtype: :py:class:`flask.Response` + """ + + plot = Plot(self.control.statestore) + + try: + valid_metrics = plot.fetch_valid_metrics() + feature = feature or valid_metrics[0] + box_plot = plot.create_box_plot(feature) + except Exception as e: + valid_metrics = None + box_plot = None + print(e, flush=True) + + result = { + "valid_metrics": valid_metrics, + "box_plot": box_plot, + } + + return jsonify(result) + def start_session( self, session_id, diff --git a/fedn/fedn/network/api/server.py b/fedn/fedn/network/api/server.py index 43cf34024..25826bbdd 100644 --- a/fedn/fedn/network/api/server.py +++ b/fedn/fedn/network/api/server.py @@ -343,6 +343,20 @@ def add_client(): return response +@app.route("/get_plot_data", methods=["GET"]) +def get_plot_data(): + """Get plot data from the statestore. + rtype: json + """ + + try: + feature = request.args.get("feature", None) + response = api.get_plot_data(feature=feature) + except TypeError as e: + return jsonify({"success": False, "message": str(e)}), 400 + return response + + if __name__ == "__main__": config = get_controller_config() port = config["port"]