Skip to content

Commit

Permalink
combiner (grouped clients) pagination
Browse files Browse the repository at this point in the history
  • Loading branch information
niklastheman committed Oct 30, 2023
1 parent 384a4fd commit 371bbfb
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 17 deletions.
5 changes: 2 additions & 3 deletions fedn/fedn/common/tracer/mongotracer.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,11 @@ def set_round_data(self, round_data):
self.rounds.update_one({'round_id': str(round_data['round_id'])}, {
'$push': {'reducer': round_data}}, True)


def update_client_status(self, client_name, status):
datetime_now = datetime.now()
filter_query = {"name": client_name} # Replace with the desired name

# Define the update operation
update_query = {"$set": {"last_seen": datetime_now, "status": status}} # Replace with the property and value to update

self.clients.update_one(filter_query, update_query)
self.clients.update_one(filter_query, update_query)
13 changes: 5 additions & 8 deletions fedn/fedn/network/api/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ def get_clients(self, limit=None, skip=None, status=False):
"""
# Will return list of ObjectId
response = self.statestore.list_clients(limit, skip, status)

arr = []

for element in response["result"]:
obj = {
"id": element["name"],
Expand All @@ -87,7 +87,7 @@ def get_clients(self, limit=None, skip=None, status=False):
arr.append(obj)

result = {"result": arr, "count": response["count"]}

return jsonify(result)

def get_active_clients(self, combiner_id):
Expand Down Expand Up @@ -759,7 +759,7 @@ def get_plot_data(self, feature=None):
}

return jsonify(result)

def list_combiners_data(self, limit=None, skip=None):
"""Get combiners data.
"""
Expand All @@ -768,8 +768,7 @@ def list_combiners_data(self, limit=None, skip=None):

arr = []

## order list by combiner name

# order list by combiner name
for element in response["result"]:

obj = {
Expand All @@ -779,8 +778,6 @@ def list_combiners_data(self, limit=None, skip=None):

arr.append(obj)

arr.sort(key=lambda x: x["count"], reverse=True)

result = {"result": arr, "count": response["count"]}

return jsonify(result)
Expand Down
14 changes: 8 additions & 6 deletions fedn/fedn/network/statestore/mongostatestore.py
Original file line number Diff line number Diff line change
Expand Up @@ -607,15 +607,15 @@ def list_clients(self, limit=None, skip=None, status=False, sort_key="last_seen"
result = self.clients.find(find, projection).limit(limit).skip(skip).sort(sort_key, sort_order)
else:
result = self.clients.find(find, projection).sort(sort_key, sort_order)

count = self.clients.count_documents(find)

return {
"result": result,
"count": count,
}

def list_combiners_data(self, limit=None, skip=None):
def list_combiners_data(self, limit=None, skip=None, sort_key="count", sort_order=pymongo.DESCENDING):
"""List all combiner data.
:return: list of combiner data.
Expand All @@ -624,19 +624,21 @@ def list_combiners_data(self, limit=None, skip=None):

result = None
count = None

pipeline = [
{"$group": {"_id": "$combiner", "count": {"$sum": 1}}}
{"$group": {"_id": "$combiner", "count": {"$sum": 1}}},
{"$sort": {sort_key: sort_order, "_id": pymongo.ASCENDING}}
]

if limit is not None and skip is not None:
limit = int(limit)
skip = int(skip)
pipeline.append({"$limit": limit})

pipeline.append({"$skip": skip})
pipeline.append({"$limit": limit})

result = self.clients.aggregate(pipeline)

pipeline_count = [
{"$group": {"_id": "$combiner"}},
{"$group": {"_id": None, "count": {"$sum": 1}}}
Expand Down

0 comments on commit 371bbfb

Please sign in to comment.