From 7166d3bbe4fa6e938270965c758d1fc2343237e0 Mon Sep 17 00:00:00 2001 From: Niklas Date: Wed, 6 Dec 2023 16:01:22 +0100 Subject: [PATCH] list_models can include active property --- fedn/fedn/network/api/interface.py | 28 ++++++++++++++++++++++++---- fedn/fedn/network/api/server.py | 3 ++- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/fedn/fedn/network/api/interface.py b/fedn/fedn/network/api/interface.py index 32a9c00ea..b9461b2c1 100644 --- a/fedn/fedn/network/api/interface.py +++ b/fedn/fedn/network/api/interface.py @@ -740,7 +740,7 @@ def get_latest_model(self): {"success": False, "message": "No initial model set."} ) - def get_models(self, session_id=None, limit=None, skip=None): + def get_models(self, session_id: str = None, limit: str = None, skip: str = None, include_active: str = None): result = self.statestore.list_models(session_id, limit, skip) if result is None: @@ -749,10 +749,30 @@ def get_models(self, session_id=None, limit=None, skip=None): 404, ) - arr = [] + include_active: bool = include_active == "true" + + if include_active: + + latest_model = self.statestore.get_latest_model() - for model in result["result"]: - arr.append(model) + arr = [ + { + "committed_at": element["committed_at"], + "model": element["model"], + "session_id": element["session_id"], + "active": element["model"] == latest_model, + } + for element in result["result"] + ] + else: + arr = [ + { + "committed_at": element["committed_at"], + "model": element["model"], + "session_id": element["session_id"], + } + for element in result["result"] + ] result = {"result": arr, "count": result["count"]} diff --git a/fedn/fedn/network/api/server.py b/fedn/fedn/network/api/server.py index cc8d1b4a9..4dc22bc84 100644 --- a/fedn/fedn/network/api/server.py +++ b/fedn/fedn/network/api/server.py @@ -44,8 +44,9 @@ def list_models(): session_id = request.args.get("session_id", None) limit = request.args.get("limit", None) skip = request.args.get("skip", None) + include_active = request.args.get("include_active", None) - return api.get_models(session_id, limit, skip) + return api.get_models(session_id, limit, skip, include_active) @app.route("/delete_model_trail", methods=["GET", "POST"])