2020-09-01 18:01:24 +02:00
|
|
|
import pandas as pd
|
|
|
|
import numpy as np
|
|
|
|
|
2020-12-03 00:41:03 +01:00
|
|
|
def rapids_features(sensor_data_files, time_segment, provider, filter_data_by_segment, *args, **kwargs):
|
2020-10-08 00:11:06 +02:00
|
|
|
|
|
|
|
light_data = pd.read_csv(sensor_data_files["sensor_data"])
|
2020-09-01 18:01:24 +02:00
|
|
|
requested_features = provider["FEATURES"]
|
|
|
|
# name of the features this function can compute
|
|
|
|
base_features_names = ["count", "maxlux", "minlux", "avglux", "medianlux", "stdlux"]
|
|
|
|
# the subset of requested features this function can compute
|
|
|
|
features_to_compute = list(set(requested_features) & set(base_features_names))
|
|
|
|
|
2020-11-30 20:42:19 +01:00
|
|
|
light_features = pd.DataFrame(columns=["local_segment"] + features_to_compute)
|
2020-09-01 18:01:24 +02:00
|
|
|
if not light_data.empty:
|
2020-12-03 00:41:03 +01:00
|
|
|
light_data = filter_data_by_segment(light_data, time_segment)
|
2020-09-01 18:01:24 +02:00
|
|
|
|
|
|
|
if not light_data.empty:
|
|
|
|
light_features = pd.DataFrame()
|
|
|
|
if "count" in features_to_compute:
|
2020-11-30 20:42:19 +01:00
|
|
|
light_features["count"] = light_data.groupby(["local_segment"]).count()["timestamp"]
|
2020-09-01 18:01:24 +02:00
|
|
|
|
|
|
|
# get light ambient luminance related features
|
|
|
|
if "maxlux" in features_to_compute:
|
2020-11-30 20:42:19 +01:00
|
|
|
light_features["maxlux"] = light_data.groupby(["local_segment"])["double_light_lux"].max()
|
2020-09-01 18:01:24 +02:00
|
|
|
if "minlux" in features_to_compute:
|
2020-11-30 20:42:19 +01:00
|
|
|
light_features["minlux"] = light_data.groupby(["local_segment"])["double_light_lux"].min()
|
2020-09-01 18:01:24 +02:00
|
|
|
if "avglux" in features_to_compute:
|
2020-11-30 20:42:19 +01:00
|
|
|
light_features["avglux"] = light_data.groupby(["local_segment"])["double_light_lux"].mean()
|
2020-09-01 18:01:24 +02:00
|
|
|
if "medianlux" in features_to_compute:
|
2020-11-30 20:42:19 +01:00
|
|
|
light_features["medianlux"] = light_data.groupby(["local_segment"])["double_light_lux"].median()
|
2020-09-01 18:01:24 +02:00
|
|
|
if "stdlux" in features_to_compute:
|
2022-09-16 12:58:57 +02:00
|
|
|
light_features["stdlux"] = light_data.groupby(["local_segment"])["double_light_lux"].std().fillna(0)
|
2020-09-01 18:01:24 +02:00
|
|
|
|
|
|
|
light_features = light_features.reset_index()
|
|
|
|
|
|
|
|
return light_features
|