fix: format code

This commit is contained in:
DDDHuang 2022-04-16 11:41:41 +08:00
parent c777759707
commit ea6b3c7b51
3 changed files with 21 additions and 19 deletions

View File

@ -307,17 +307,19 @@ calculate_rate(CurrVal, #rate{max = MaxRate0, last_v = LastVal,
%% calculate the max rate since the emqx startup
MaxRate =
if MaxRate0 >= CurrRate -> MaxRate0;
true -> CurrRate
case MaxRate0 >= CurrRate of
true -> MaxRate0;
false -> CurrRate
end,
%% calculate the average rate in last 5 mins
{Last5MinSamples, Acc5Min, Last5Min} =
if Tick =< ?SAMPCOUNT_5M ->
case Tick =< ?SAMPCOUNT_5M of
true ->
Acc = AccRate5Min0 + CurrRate,
{lists:reverse([CurrRate | lists:reverse(Last5MinSamples0)]),
Acc, Acc / Tick};
true ->
false ->
[FirstRate | Rates] = Last5MinSamples0,
Acc = AccRate5Min0 + CurrRate - FirstRate,
{lists:reverse([CurrRate | lists:reverse(Rates)]),

View File

@ -99,7 +99,7 @@ rule_info_schema() ->
schema("/rules") ->
#{
operationId => '/rules',
'operationId' => '/rules',
get => #{
tags => [<<"rules">>],
description => <<"List all rules">>,
@ -111,7 +111,7 @@ schema("/rules") ->
tags => [<<"rules">>],
description => <<"Create a new rule using given Id">>,
summary => <<"Create a Rule">>,
requestBody => rule_creation_schema(),
'requestBody' => rule_creation_schema(),
responses => #{
400 => error_schema('BAD_REQUEST', "Invalid Parameters"),
201 => rule_info_schema()
@ -120,7 +120,7 @@ schema("/rules") ->
schema("/rule_events") ->
#{
operationId => '/rule_events',
'operationId' => '/rule_events',
get => #{
tags => [<<"rules">>],
description => <<"List all events can be used in rules">>,
@ -133,7 +133,7 @@ schema("/rule_events") ->
schema("/rules/:id") ->
#{
operationId => '/rules/:id',
'operationId' => '/rules/:id',
get => #{
tags => [<<"rules">>],
description => <<"Get a rule by given Id">>,
@ -149,7 +149,7 @@ schema("/rules/:id") ->
description => <<"Update a rule by given Id to all nodes in the cluster">>,
summary => <<"Update a Rule">>,
parameters => param_path_id(),
requestBody => rule_creation_schema(),
'requestBody' => rule_creation_schema(),
responses => #{
400 => error_schema('BAD_REQUEST', "Invalid Parameters"),
200 => rule_info_schema()
@ -168,7 +168,7 @@ schema("/rules/:id") ->
schema("/rules/:id/reset_metrics") ->
#{
operationId => '/rules/:id/reset_metrics',
'operationId' => '/rules/:id/reset_metrics',
put => #{
tags => [<<"rules">>],
description => <<"Reset a rule metrics">>,
@ -183,12 +183,12 @@ schema("/rules/:id/reset_metrics") ->
schema("/rule_test") ->
#{
operationId => '/rule_test',
'operationId' => '/rule_test',
post => #{
tags => [<<"rules">>],
description => <<"Test a rule">>,
summary => <<"Test a Rule">>,
requestBody => rule_test_schema(),
'requestBody' => rule_test_schema(),
responses => #{
400 => error_schema('BAD_REQUEST', "Invalid Parameters"),
412 => error_schema('NOT_MATCH', "SQL Not Match"),

View File

@ -48,9 +48,9 @@
-spec(apply_rules(list(rule()), input()) -> ok).
apply_rules([], _Input) ->
ok;
apply_rules([#{enable := false}|More], Input) ->
apply_rules([#{enable := false} | More], Input) ->
apply_rules(More, Input);
apply_rules([Rule|More], Input) ->
apply_rules([Rule | More], Input) ->
apply_rule_discard_result(Rule, Input),
apply_rules(More, Input).
@ -150,14 +150,14 @@ select_and_transform(Fields, Input) ->
select_and_transform([], _Input, Output) ->
Output;
select_and_transform(['*'|More], Input, Output) ->
select_and_transform(['*' | More], Input, Output) ->
select_and_transform(More, Input, maps:merge(Output, Input));
select_and_transform([{as, Field, Alias}|More], Input, Output) ->
select_and_transform([{as, Field, Alias} | More], Input, Output) ->
Val = eval(Field, Input),
select_and_transform(More,
nested_put(Alias, Val, Input),
nested_put(Alias, Val, Output));
select_and_transform([Field|More], Input, Output) ->
select_and_transform([Field | More], Input, Output) ->
Val = eval(Field, Input),
Key = alias(Field),
select_and_transform(More,
@ -172,7 +172,7 @@ select_and_collect(Fields, Input) ->
select_and_collect([{as, Field, {_, A} = Alias}], Input, {Output, _}) ->
Val = eval(Field, Input),
{nested_put(Alias, Val, Output), {A, ensure_list(Val)}};
select_and_collect([{as, Field, Alias}|More], Input, {Output, LastKV}) ->
select_and_collect([{as, Field, Alias} | More], Input, {Output, LastKV}) ->
Val = eval(Field, Input),
select_and_collect(More,
nested_put(Alias, Val, Input),
@ -181,7 +181,7 @@ select_and_collect([Field], Input, {Output, _}) ->
Val = eval(Field, Input),
Key = alias(Field),
{nested_put(Key, Val, Output), {'item', ensure_list(Val)}};
select_and_collect([Field|More], Input, {Output, LastKV}) ->
select_and_collect([Field | More], Input, {Output, LastKV}) ->
Val = eval(Field, Input),
Key = alias(Field),
select_and_collect(More,