Skip to content

Commit

Permalink
create mode and get mode done
Browse files Browse the repository at this point in the history
  • Loading branch information
jiji14 committed Dec 7, 2023
1 parent 4fa7a8d commit 3074f4e
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
22 changes: 22 additions & 0 deletions emission/core/wrapper/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,3 +228,25 @@ def unregister(userEmail):
get_uuid_db().delete_one({'user_email': userEmail})
get_profile_db().delete_one({'user_id': uuid})
return uuid

def getModes(self):
user = get_profile_db().find_one({'user_id': self.uuid})
modes = user['modes']
filteredModes = {key: value for key, value in modes.items() if value.get('isActive', False)}
sortedModes = dict(sorted(filteredModes.items(), key=lambda x: (x[1]["frequency"]), reverse=True))
return sortedModes

def insertMode(self, mode):
from datetime import datetime
modes = self.getModes()
if mode in modes:
modes[mode]['frequency'] = modes[mode]['frequency'] + 1
else:
modes[mode] = {
'createdAt': datetime.now(),
'frequency': 1,
'isActive': True,
}
get_profile_db().update_one({'user_id': self.uuid}, {'$set': {'modes': modes}})
return modes

17 changes: 17 additions & 0 deletions emission/net/api/cfc_webapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,23 @@ def getUserProfile():
user = User.fromUUID(user_uuid)
return user.getProfile()

@post('/mode/get')
def getUserModes():
logging.debug("Called getUserModes")
user_uuid = getUUID(request)
user = User.fromUUID(user_uuid)
return user.getModes()

@post('/mode/create')
def createUserMode():
logging.debug("Called createUserMode")
new_mode = request.json['mode']
user_uuid = getUUID(request)
user = User.fromUUID(user_uuid)
to_return = user.insertMode(new_mode)
logging.debug("Successfully created mode for user %s" % user_uuid)
return {"modes": to_return}

@post('/result/metrics/<time_type>')
def summarize_metrics(time_type):
_fill_aggregate_backward_compat(request)
Expand Down

0 comments on commit 3074f4e

Please sign in to comment.