niimpy.preprocessing.battery module

niimpy.preprocessing.battery.battery_charge_discharge(df, config)[source]

Returns a DataFrame showing the mean difference in battery values and mean battery charge/discharge rate within specified time windows. If there is no specified timeframe, the function sets a 30 min default time window. Parameters ———- df: dataframe with date index

niimpy.preprocessing.battery.battery_discharge(df, config)[source]

This function returns the mean discharge rate of the battery within a specified time window. If there is no specified timeframe, the function sets a 30 min default time window. The function aggregates this number by user, by timewindow. Parameters ———- df: pandas.DataFrame

Dataframe with the battery information

config: dict, optional

Dictionary keys containing optional arguments for the computation of scrren information. Keys can be column names, other dictionaries, etc.

Returns

result: dataframe

niimpy.preprocessing.battery.battery_gaps(df, config)[source]

Returns a DataFrame with the mean time difference between consecutive battery timestamps. The mean is calculated within intervals specified in config. The minimum size of the considered deltas can be decided with the min_duration_between parameter.

Parameters
df: pandas.DataFrame

Dataframe with the battery information

config: dict, optional

Dictionary keys containing optional arguments for the computation of batter information. Keys can be column names, other dictionaries, etc.

Optional arguments in config:

min_duration_between: Timedelta, for example, pd.Timedelta(minutes=5)

niimpy.preprocessing.battery.battery_mean_level(df, config)[source]

This function returns the mean battery level within the specified timeframe. If there is no specified timeframe, the function sets a 30 min default time window. The function aggregates this number by user, by timewindow. Parameters ———- df: pandas.DataFrame

Dataframe with the battery information

config: dict, optional

Dictionary keys containing optional arguments for the computation of scrren information. Keys can be column names, other dictionaries, etc.

Returns

result: dataframe

niimpy.preprocessing.battery.battery_median_level(df, config)[source]

This function returns the median battery level within the specified timeframe. If there is no specified timeframe, the function sets a 30 min default time window. The function aggregates this number by user, by timewindow. Parameters ———- df: pandas.DataFrame

Dataframe with the battery information

config: dict, optional

Dictionary keys containing optional arguments for the computation of scrren information. Keys can be column names, other dictionaries, etc.

Returns

result: dataframe

niimpy.preprocessing.battery.battery_occurrences(df, config)[source]

Returns a dataframe showing the amount of battery data points found within a specified time window. If there is no specified timeframe, the function sets a 30 min default time window. Parameters ———- df: pandas.DataFrame

Dataframe with the battery information

config: dict, optional

Dictionary keys containing optional arguments for the computation of batter information. Keys can be column names, other dictionaries, etc.

niimpy.preprocessing.battery.battery_shutdown_time(df, config)[source]

This function returns the total time the phone has been turned off within a specified time window. If there is no specified timeframe, the function sets a 30 min default time window. The function aggregates this number by user, by timewindow. Parameters ———- df: pandas.DataFrame

Dataframe with the battery information

config: dict, optional

Dictionary keys containing optional arguments for the computation of scrren information. Keys can be column names, other dictionaries, etc.

Returns

result: dataframe

niimpy.preprocessing.battery.battery_std_level(df, config)[source]

This function returns the standard deviation battery level within the specified timeframe. If there is no specified timeframe, the function sets a 30 min default time window. The function aggregates this number by user, by timewindow. Parameters ———- df: pandas.DataFrame

Dataframe with the battery information

config: dict, optional

Dictionary keys containing optional arguments for the computation of scrren information. Keys can be column names, other dictionaries, etc.

Returns

result: dataframe

niimpy.preprocessing.battery.extract_features_battery(df, features=None)[source]

Calculates battery features

Parameters
dfpd.DataFrame

dataframe of battery data. It must contain these columns: battery_level and battery_status.

featuresmap (dictionary) of functions that compute features.

it is a map of map, where the keys to the first map is the name of functions that compute features and the nested map contains the keyword arguments to that function. If there is no arguments use an empty map. Default is None. If None, all the available functions are used. Those functions are in the dict battery.ALL_FEATURES. You can implement your own function and use it instead or add it to the mentioned map.

Returns
featurespd.DataFrame

Dataframe of computed features where the index is users and columns are the the features.

niimpy.preprocessing.battery.find_battery_gaps(battery_df, other_df, config)[source]

Returns a dataframe showing the gaps found only in the battery data. The default interval is 6 hours. Parameters ———- battery_df: Dataframe other_df: Dataframe

The data you want to compare with

niimpy.preprocessing.battery.find_non_battery_gaps(battery_df, other_df, config)[source]

Returns a dataframe showing the gaps found only in the other data. The default interval is 6 hours. Parameters ———- battery_df: Dataframe other_df: Dataframe

The data you want to compare with

niimpy.preprocessing.battery.find_real_gaps(battery_df, other_df, config)[source]

Returns a dataframe showing the gaps found both in the battery data and the other data. The default interval is 6 hours. Parameters ———- battery_df: Dataframe other_df: Dataframe

The data you want to compare with

niimpy.preprocessing.battery.format_battery_data(df, config)[source]

Returns a DataFrame with battery data for a user. Parameters ———- battery: DataFrame with battery data

niimpy.preprocessing.battery.group_data(df)[source]

Group the dataframe by a standard set of columns listed in group_by_columns.

niimpy.preprocessing.battery.reset_groups(df)[source]

Group the dataframe by a standard set of columns listed in group_by_columns.

niimpy.preprocessing.battery.shutdown_info(df, config)[source]

Returns a pandas DataFrame with battery information for the timestamps when the phone has shutdown. This includes both events, when the phone has shut down and when the phone has been rebooted. NOTE: This is a helper function created originally to preprocess the application info data Parameters ———- bat: pandas.DataFrame

Dataframe with the battery information

config: dict, optional

Dictionary keys containing optional arguments for the computation of scrren information. Keys can be column names, other dictionaries, etc.

Returns

shutdown: pandas series