Skip to content

Commit

Permalink
get plot data
Browse files Browse the repository at this point in the history
  • Loading branch information
niklastheman committed Oct 23, 2023
1 parent b99e593 commit ae3d691
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
26 changes: 26 additions & 0 deletions fedn/fedn/network/api/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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,
Expand Down
14 changes: 14 additions & 0 deletions fedn/fedn/network/api/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down

0 comments on commit ae3d691

Please sign in to comment.