<commit_before>%% Copyright (c) 2013 <NAME>
%% See MIT-LICENSE for licensing information.

%%% -------------------------------------------------------------------
%%% Author  : <NAME> <EMAIL>
%%% Description :
%%%
%%% Created :  
-module(dht22_display_driver).

%% --------------------------------------------------------------------
%% Include files
%% --------------------------------------------------------------------
-define(MAX_QUEUE_LENGTH, 19).
%% --------------------------------------------------------------------
%% External exports
%% --------------------------------------------------------------------
-export([handle_msg/3]).

handle_msg([Node ,Sensor, Id, Time, Body], Config, Module_config) ->
	Data = proplists:get_value(data, Module_config, []),
	Module_config_1 = lists:keyreplace(data, 1 , Module_config, {data, add(Data, {Time, Body})}),
	lists:keyreplace(driver, 1, Config, {driver, {?MODULE, handle_msg}, Module_config_1}).
%% --------------------------------------------------------------------
%%% Internal functions
%% --------------------------------------------------------------------
add([], Value) ->
    [Value];
add(List, Value) ->
    case length(List) =< ?MAX_QUEUE_LENGTH of
        true -> [Value|List];
        false -> [Value|lists:sublist(List, ?MAX_QUEUE_LENGTH)]
    end.    
%% --------------------------------------------------------------------
%%% Test functions
%% --------------------------------------------------------------------
-include_lib("eunit/include/eunit.hrl").
-ifdef(TEST).
handle_msg_test() ->
	Config = [{driver, {dht22_display_driver, handle_msg}, [{data, []}]}],
	Config_1 = [{driver, {dht22_display_driver, handle_msg}, [{data, [{"1", "2"}]}]}],
	?assertEqual(Config_1, handle_msg(["Node", "Sensor", "Id", "1", "2"], Config, [{data, []}])).
-endif.<commit_msg>implemented handling of 0.0 values<commit_after>%% Copyright (c) 2013 <NAME>
%% See MIT-LICENSE for licensing information.

%%% -------------------------------------------------------------------
%%% Author  : <NAME> <EMAIL>
%%% Description :
%%%
%%% Created :  
-module(dht22_display_driver).

%% --------------------------------------------------------------------
%% Include files
%% --------------------------------------------------------------------
-define(MAX_QUEUE_LENGTH, 19).
%% --------------------------------------------------------------------
%% External exports
%% --------------------------------------------------------------------
-export([handle_msg/3]).

handle_msg([Node ,Sensor, Id, Time, [{temp, "0.0"},{hum, "0.0"}]], Config, Module_config) ->
	lager:warning("dht22_display_driver got a message with incorrect values: ~p", [[Node ,Sensor, Id, Time, [{temp, "0.0"},{hum, "0.0"}]]]),
	Config;

handle_msg([Node ,Sensor, Id, Time, [{temp, Temp},{hum, Hum}]], Config, Module_config) ->
	Data = proplists:get_value(data, Module_config, []),
	Module_config_1 = lists:keyreplace(data, 1 , Module_config, {data, add(Data, {Time, [{temp, Temp},{hum, Hum}]})}),
	lists:keyreplace(driver, 1, Config, {driver, {?MODULE, handle_msg}, Module_config_1});

handle_msg([Node ,Sensor, Id, Time, Body], Config, Module_config) ->
	lager:warning("dht22_display_driver got the wrong message : ~p", [[Node ,Sensor, Id, Time, Body]]),
	Config.
%% --------------------------------------------------------------------
%%% Internal functions
%% --------------------------------------------------------------------
add([], Value) ->
    [Value];
add(List, Value) ->
    case length(List) =< ?MAX_QUEUE_LENGTH of
        true -> [Value|List];
        false -> [Value|lists:sublist(List, ?MAX_QUEUE_LENGTH)]
    end.    

%% --------------------------------------------------------------------
%%% Test functions
%% --------------------------------------------------------------------
-include_lib("eunit/include/eunit.hrl").
-ifdef(TEST).
handle_msg_test() ->
	Config = [{driver, {dht22_display_driver, handle_msg}, [{data, []}]}],
	Config_1 = [{driver, {dht22_display_driver, handle_msg}, [{data, [{"1", "2"}]}]}],
	?assertEqual(Config_1, handle_msg(["Node", "Sensor", "Id", "1", "2"], Config, [{data, []}])).
-endif.
{'fraction_non_alphanumeric': 0.44704463208685163, 'fraction_numerical': 0.014475271411338963, 'mean_word_length': 1.4330985915492958, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 23, '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}}
{'dir': 'git-commits-cleaned', 'id': '397151', 'n_tokens_mistral': 1112, 'n_tokens_neox': 1091, 'n_words': 233}