def process_kitchen(self): # TODO: add sensor type as a column activity = self.datasets['activity'] activity = localize_time(activity, ['start_date']) doors = self.datasets['doors'] appliances = map_devices(self.datasets['appliances'], self.datasets['device_types']) doors = doors[(doors.location_name == 'fridge door') & (doors.transition == 'opened>closed')] activity = activity[activity.location_name.isin(['kitchen', 'dining room'])] activity.insert(0, 'device_type', 'pir') doors.insert(0, 'device_type', 'door') appliances.value = appliances.value.astype(str)\ .replace({'microwave-use': 'oven-use', 'toaster-use': 'oven-use', 'iron-use': np.nan, 'multi-use socket-use': np.nan}) doors = doors[['patient_id', 'start_date', 'device_type','location_name']]\ .rename({'location_name': 'activity'}, axis=1) activity = activity[['patient_id', 'start_date', 'device_type', 'location_name']]\ .rename({'location_name': 'activity'}, axis=1) appliances = appliances[['patient_id', 'start_date', 'device_type', 'value']]\ .rename({'value': 'activity'}, axis=1) kitchen = pd.concat([doors, activity, appliances.dropna()]) kitchen = kitchen[kitchen.patient_id != ''].sort_values( ['patient_id', 'start_date']) kitchen = process_transition(kitchen, ['patient_id'], 'start_date', 'activity', ['device_type']) return kitchen.reset_index(drop=True)
def process_doors(self): groupby = ['patient_id', 'location_name'] datetime = 'start_date' value = 'value' covariates = ['location_name'] df = self.datasets['door'] df = localize_time(df, ['start_date']) doors = process_transition(df, groupby, datetime, value, covariates) return doors.drop('location_name', axis=1).reset_index()
def process_doors(self): df = self.datasets['observation'] columns = ['subject', 'location', 'datetimeObserved', 'valueState', 'type'] df = (df[columns].query('type == "224751004"').dropna( subset=['location']).drop(columns='type')) df.columns = ['patient_id', 'location_name', 'start_date', 'value'] df.value = df.value.replace({'Close': 'closed', 'Open': 'opened'}) groupby = ['patient_id', 'location_name'] datetime = 'start_date' value = 'value' covariates = None df = localize_time(df, ['start_date']) doors = process_transition(df, groupby, datetime, value, covariates) doors = doors.reset_index() doors.location_name = doors.location_name.str.lower() return doors
def process_transitions(self): motion = self.datasets['motion'] motion = process_transition(motion, ['patient_id'], 'start_date', 'location_name') return motion.reset_index()