<commit_before>%%% @doc The entity channel - forwards messages from a client to its inhabited entity
%%% -------------------------------------------------------------------------------------------------------------------

-module(pre_channel_entity).

-include("log.hrl").
-include("pre_entity.hrl").

% API
-export([register_hooks/0, build_state_event/3, generate_timestamp/0, generate_timestamp/1]).

% Hooks
-export([client_logged_in_hook/2, client_disconnected_hook/3]).

% pre_client_channels
-export([client_request/4, client_response/4, client_event/3]).


%% --------------------------------------------------------------------------------------------------------------------
%% API
%% --------------------------------------------------------------------------------------------------------------------

register_hooks() ->
	?debug("Registering client hooks."),
    pre_hooks:add_hook(client_logged_in, ?MODULE, client_logged_in_hook, undefined, [node()]),
    pre_hooks:add_hook(client_disconnected, ?MODULE, client_disconnected_hook, undefined, [node()]).

%% --------------------------------------------------------------------------------------------------------------------

-spec build_state_event(EventType, StateUpdate, EntityID) -> json() when
	EventType :: binary(),
	StateUpdate :: json(),
	EntityID :: binary().

build_state_event(undefined, StateUpdate, EntityID) ->

	{StateItems, OtherItems} = lists:foldl(
		fun({_Key, [{_K, _V} | _] = Value}, {StateItemsAcc1, OtherItemsAcc1}) ->
				{Value ++ StateItemsAcc1, OtherItemsAcc1};
			({_Key, _Value} = Item, {StateItemsAcc2, OtherItemsAcc2}) ->
				{StateItemsAcc2, [Item | OtherItemsAcc2]}
		end,
		{[], []},
		StateUpdate<commit_msg>Minor correction to spec.<commit_after>%%% @doc The entity channel - forwards messages from a client to its inhabited entity
%%% -------------------------------------------------------------------------------------------------------------------

-module(pre_channel_entity).

-include("log.hrl").
-include("pre_entity.hrl").

% API
-export([register_hooks/0, build_state_event/3, generate_timestamp/0, generate_timestamp/1]).

% Hooks
-export([client_logged_in_hook/2, client_disconnected_hook/3]).

% pre_client_channels
-export([client_request/4, client_response/4, client_event/3]).


%% --------------------------------------------------------------------------------------------------------------------
%% API
%% --------------------------------------------------------------------------------------------------------------------

register_hooks() ->
	?debug("Registering client hooks."),
    pre_hooks:add_hook(client_logged_in, ?MODULE, client_logged_in_hook, undefined, [node()]),
    pre_hooks:add_hook(client_disconnected, ?MODULE, client_disconnected_hook, undefined, [node()]).

%% --------------------------------------------------------------------------------------------------------------------

-spec build_state_event(EventType, StateUpdate, EntityID) -> json() when
	EventType :: binary() | 'undefined',
	StateUpdate :: json(),
	EntityID :: binary().

build_state_event(undefined, StateUpdate, EntityID) ->

	{StateItems, OtherItems} = lists:foldl(
		fun({_Key, [{_K, _V} | _] = Value}, {StateItemsAcc1, OtherItemsAcc1}) ->
				{Value ++ StateItemsAcc1, OtherItemsAcc1};
			({_Key, _Value} = Item, {StateItemsAcc2, OtherItemsAcc2}) ->
				{StateItemsAcc2, [Item | OtherItemsAcc2]}
		end,
		{[], []},
		StateUpdate
{'fraction_non_alphanumeric': 0.38510762070971494, 'fraction_numerical': 0.009889470622454915, 'mean_word_length': 1.6312165263963274, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, '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': '487603', 'n_tokens_mistral': 899, 'n_tokens_neox': 874, 'n_words': 165}