<commit_before>%  @copyright 2010-2014 Zuse Institute Berlin

%   Licensed under the Apache License, Version 2.0 (the "License");
%   you may not use this file except in compliance with the License.
%   You may obtain a copy of the License at
%
%       http://www.apache.org/licenses/LICENSE-2.0
%
%   Unless required by applicable law or agreed to in writing, software
%   distributed under the License is distributed on an "AS IS" BASIS,
%   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
%   See the License for the specific language governing permissions and
%   limitations under the License.
%% @version $Id$
-module(gossip_load_default).
-vsn('$Id$').

-behavior(gossip_load_beh).

-export([get_load/1, init_histo/2]).

-spec get_load(node_details:node_details()) -> gossip_load_beh:load().
get_load(NodeDetails) ->
    node_details:get(NodeDetails, load).

-spec init_histo(node_details:node_details(), NumberOfBuckets::pos_integer())
                    -> gossip_load:histogram().
init_histo(NodeDetails, NumberOfBuckets) ->
    DB = node_details:get(NodeDetails, db),
    MyRange = node_details:get(NodeDetails, my_range),
    Buckets = intervals:split(intervals:all(), NumberOfBuckets),
    [ {BucketInterval, get_load_for_interval(BucketInterval, MyRange, DB)}
        || BucketInterval <- Buckets ].

-spec get_load_for_interval(BucketInterval::intervals:interval(),
    MyRange::intervals:interval(), DB::db_dht:db()) -> gossip_load:avg() | unknown.
get_load_for_interval(BucketInterval, MyRange, DB) ->
    Intersection = intervals:intersection(BucketInterval, MyRange),
    case intervals:is_empty(Intersection) of
        true -> unknown;
        false ->
            Load = db_dht:get_load(DB, BucketInterval),
            {float(Load), 1.0}
    end.<commit_msg>gossip: do not throw in gossip_load if the DB is not accessible anymore<commit_after>%  @copyright 2010-2014 Zuse Institute Berlin

%   Licensed under the Apache License, Version 2.0 (the "License");
%   you may not use this file except in compliance with the License.
%   You may obtain a copy of the License at
%
%       http://www.apache.org/licenses/LICENSE-2.0
%
%   Unless required by applicable law or agreed to in writing, software
%   distributed under the License is distributed on an "AS IS" BASIS,
%   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
%   See the License for the specific language governing permissions and
%   limitations under the License.
%% @version $Id$
-module(gossip_load_default).
-vsn('$Id$').

-behavior(gossip_load_beh).

-export([get_load/1, init_histo/2]).

-spec get_load(node_details:node_details()) -> gossip_load_beh:load().
get_load(NodeDetails) ->
    node_details:get(NodeDetails, load).

-spec init_histo(node_details:node_details(), NumberOfBuckets::pos_integer())
                    -> gossip_load:histogram().
init_histo(NodeDetails, NumberOfBuckets) ->
    DB = node_details:get(NodeDetails, db),
    MyRange = node_details:get(NodeDetails, my_range),
    Buckets = intervals:split(intervals:all(), NumberOfBuckets),
    [ {BucketInterval, get_load_for_interval(BucketInterval, MyRange, DB)}
        || BucketInterval <- Buckets ].

-spec get_load_for_interval(BucketInterval::intervals:interval(),
    MyRange::intervals:interval(), DB::db_dht:db()) -> gossip_load:avg() | unknown.
get_load_for_interval(BucketInterval, MyRange, DB) ->
    Intersection = intervals:intersection(BucketInterval, MyRange),
    case intervals:is_empty(Intersection) of
        true -> unknown;
        false ->
            try
                Load = db_dht:get_load(DB, BucketInterval),
                {float(Load), 1.0}
            catch
                Level:Reason ->
                    log:pal("[ gossip ~p ] error while accessing DB: thrown ~s, reason:~.2p",
                            [self(), Level, Reason]),
                    unknown
            end
    end.
{'fraction_non_alphanumeric': 0.1127475876079228, 'fraction_numerical': 0.008379888268156424, 'mean_word_length': 3.6070175438596492, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '6584131', 'n_tokens_mistral': 1193, 'n_tokens_neox': 1151, 'n_words': 313}