Skip to content

Commit

Permalink
fix get_combiners
Browse files Browse the repository at this point in the history
  • Loading branch information
Wrede committed Oct 30, 2023
1 parent 22b4308 commit 7b64d3e
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 8 deletions.
8 changes: 7 additions & 1 deletion fedn/fedn/network/api/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ def get_all_combiners(self, limit=None, skip=None):
:rtype: :class:`flask.Response`
"""
# Will return list of ObjectId
response = self.statestore.get_combiners(limit, skip)
projection = {"name": True, "updated_at": True}
response = self.statestore.get_combiners(limit, skip, projection=projection)
arr = []
for element in response["result"]:
obj = {
Expand Down Expand Up @@ -760,6 +761,11 @@ def get_plot_data(self, feature=None):

def list_combiners_data(self, combiners):
"""Get combiners data.
:param combiners: The combiners to get data for.
:type combiners: list
:return: The combiners data as json response.
:rtype: :py:class:`flask.Response`
"""

response = self.statestore.list_combiners_data(combiners)
Expand Down
2 changes: 1 addition & 1 deletion fedn/fedn/network/api/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def get_combiners(self):
"""
data = self.statestore.get_combiners()
combiners = []
for c in data:
for c in data["result"]:
if c['certificate']:
cert = base64.b64decode(c['certificate'])
key = base64.b64decode(c['key'])
Expand Down
2 changes: 1 addition & 1 deletion fedn/fedn/network/api/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ def add_client():

@app.route("/list_combiners_data", methods=["POST"])
def list_combiners_data():
"""Add a client to the network.
"""List data from combiners.
return: The response from control.
rtype: json
"""
Expand Down
26 changes: 21 additions & 5 deletions fedn/fedn/network/statestore/mongostatestore.py
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,8 @@ def get_reducer(self):
def get_combiner(self, name):
"""Get combiner by name.
:param name: name of combiner to get.
:type name: str
:return: The combiner.
:rtype: ObjectId
"""
Expand All @@ -519,18 +521,26 @@ def get_combiner(self, name):
except Exception:
return None

def get_combiners(self, limit=None, skip=None, sort_key="updated_at", sort_order=pymongo.DESCENDING):
def get_combiners(self, limit=None, skip=None, sort_key="updated_at", sort_order=pymongo.DESCENDING, projection={}):
"""Get all combiners.
:return: list of combiners.
:rtype: list
:param limit: The maximum number of combiners to return.
:type limit: int
:param skip: The number of combiners to skip.
:type skip: int
:param sort_key: The key to sort by.
:type sort_key: str
:param sort_order: The sort order.
:type sort_order: pymongo.ASCENDING or pymongo.DESCENDING
:param projection: The projection.
:type projection: dict
:return: Dictionary of combiners in result and count.
:rtype: dict
"""

result = None
count = None

projection = {"name": True, "updated_at": True}

try:
if limit is not None and skip is not None:
limit = int(limit)
Expand Down Expand Up @@ -640,6 +650,12 @@ def list_clients(self, limit=None, skip=None, status=False, sort_key="last_seen"
def list_combiners_data(self, combiners, sort_key="count", sort_order=pymongo.DESCENDING):
"""List all combiner data.
:param combiners: list of combiners to get data for.
:type combiners: list
:param sort_key: The key to sort by.
:type sort_key: str
:param sort_order: The sort order.
:type sort_order: pymongo.ASCENDING or pymongo.DESCENDING
:return: list of combiner data.
:rtype: list(ObjectId)
"""
Expand Down

0 comments on commit 7b64d3e

Please sign in to comment.