Skip to content

Commit

Permalink
list_models can include active property
Browse files Browse the repository at this point in the history
  • Loading branch information
niklastheman committed Dec 6, 2023
1 parent 4d46ac7 commit 7166d3b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
28 changes: 24 additions & 4 deletions fedn/fedn/network/api/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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"]}

Expand Down
3 changes: 2 additions & 1 deletion fedn/fedn/network/api/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"])
Expand Down

0 comments on commit 7166d3b

Please sign in to comment.