added code
This commit is contained in:
@@ -3,7 +3,7 @@ from typing import Callable
|
||||
|
||||
import numpy as np
|
||||
from vsm_datascience_common import constants
|
||||
from vsm_datascience_common.cycle_database_connection.db_utils import get_cycles_collection
|
||||
from vsm_datascience_common.cycle_database_connection.db_utils import get_cycles_collection, get_collection
|
||||
from vsm_datascience_common.cycles.sequences import get_timestamps, get_values
|
||||
|
||||
from utils.smoothing import get_curve_composition
|
||||
@@ -243,6 +243,67 @@ def get_window_fn(cycle: dict,
|
||||
return fn(windows)
|
||||
|
||||
|
||||
def get_user_age(cycle: dict) -> int:
|
||||
"""
|
||||
Returns the age of the user in years the cycle belongs to as array. Returns average age, if user has no age specified
|
||||
Args:
|
||||
cycle: cycle belonging to the user
|
||||
|
||||
Returns:
|
||||
age_array: array with the age of th user, same length as cycle
|
||||
|
||||
"""
|
||||
|
||||
user_id = cycle["user_id"]
|
||||
cycle_length = len(get_values(cycle))
|
||||
pii = get_collection("personal_informations", constants.METADATA_DB_NAME).find_one({"user_id": user_id})
|
||||
if pii is None:
|
||||
return np.full((cycle_length,), 37) # 37 is mean of all users
|
||||
else:
|
||||
return np.full((cycle_length,), pii["age"])
|
||||
|
||||
|
||||
def get_user_weight(cycle: dict) -> np.array:
|
||||
"""
|
||||
Returns the weight of the user in KG the cycle belongs to as array. Returns average weight of user if user has no weight specified
|
||||
Args:
|
||||
cycle: cycle belonging to the user
|
||||
|
||||
Returns:
|
||||
weight_array: weight of the user for each datapoint in the cycle
|
||||
|
||||
"""
|
||||
|
||||
user_id = cycle["user_id"]
|
||||
cycle_length = len(get_values(cycle))
|
||||
pii = get_collection("personal_informations", constants.METADATA_DB_NAME).find_one({"user_id": user_id})
|
||||
if pii is None:
|
||||
return np.full((cycle_length,), 70) # 70 is mean for all users
|
||||
else:
|
||||
return np.full((cycle_length,), pii["weight"])
|
||||
|
||||
|
||||
def get_user_height(cycle: dict) -> np.array:
|
||||
"""
|
||||
Returns the height of the user in cm the cycle belongs to. Returns average height of user if user has no height specified
|
||||
Args:
|
||||
cycle: cycle belonging to the user
|
||||
|
||||
Returns:
|
||||
height_array: height of the user for each datapoint in the cycle
|
||||
|
||||
"""
|
||||
|
||||
user_id = cycle["user_id"]
|
||||
cycle_length = len(get_values(cycle))
|
||||
pii = get_collection("personal_informations", constants.METADATA_DB_NAME).find_one({"user_id": user_id})
|
||||
|
||||
if pii is None:
|
||||
return np.full((cycle_length,), 167) # 167 is mean for all users
|
||||
else:
|
||||
return np.full((cycle_length,), pii["height"])
|
||||
|
||||
|
||||
def get_cycle_length_stats(cycle: dict) -> dict:
|
||||
user_id = cycle["user_id"]
|
||||
cycle_length = len(get_values(cycle))
|
||||
|
||||
Reference in New Issue
Block a user