<jupyter_start><jupyter_text>Compute daily outliers based on KDE density<jupyter_code>from iotfunctions.base import BaseSimpleAggregator
from iotfunctions.aggregate import (Aggregation, AggregateWithCalculation, add_simple_aggregator_execute)

# Run Monitoring's anomaly detector functions
EngineLogging.configure_console_logging(logging.DEBUG)

func = AggregateKDEDensity1d

# prepare parameter list
params_dict = {}
params_dict['source'] = 'power'
params_dict['name'] = 'power_out'
params_dict['alpha'] = 0.995

# replace aggregate call with 'execute_AggregateWithExpression'
func_name = 'execute_AggregateTimeInState'
add_simple_aggregator_execute(func, func_name)

func_clos = getattr(func(**params_dict), func_name)


# set up an Aggregation thingy with the entity index, timestamp index, 
# desired granularity and a (short) chain of aggregators
# granularity = frequency, dimension(s), include entity, entity id
aggii = Aggregation(None, ids=['deviceid'], timestamp='evt_timestamp', granularity=('D', None, True, 0), 
                    simple_aggregators=[(['power'], func_clos, 0.995)])
print(aggii)

jobsettings = { 'db': db, 
               '_db_schema': 'public', 'save_trace_to_file' : True}
et = aggii._build_entity_type(columns = [Column('changed',Float())], **jobsettings)

t = aggii.execute(df=df_i)

t[0.995]
t[[0.995]].groupby(['deviceid']).apply(lambda group:
    group.reset_index(level=0).resample('H').mean().ffill().plot(title=group.index[0][0]))<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12991339107261826, 'fraction_numerical': 0.013990672884743505, 'mean_word_length': 6.782383419689119, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '209041', 'license': 'MIT', 'n_tokens_mistral': 507, 'n_tokens_neox': 478, 'n_words': 101, 'path': 'ArmstarkPowerTrend.ipynb', 'repo_name': 'ankit-jha/mmfunctions', 'size': '1501'}