Расширена статистика для разделов #22

This commit is contained in:
2026-05-28 13:49:08 +03:00
parent 2dac5e5102
commit 1986fd4694
20 changed files with 1189 additions and 71 deletions
+33
View File
@@ -6,6 +6,7 @@
-export([list_users/0]).
-export([block/2, unblock/2]).
-export([count_users/0, count_users_by_date/2, count_pending_users/0, count_pending_users_by_date/2, list_all/0]).
-export([count_users_by_role/0, count_users_by_status/0]).
-export([create_bot/2, delete_bot/1]).
%% ─────────────────────────────────────────────────────────────────
@@ -306,6 +307,38 @@ count_pending_users_by_date(From, To) ->
end, [], Filtered),
lists:sort(Counts).
%%%-------------------------------------------------------------------
%%% @doc Подсчёт пользователей по ролям.
%%% Возвращает список [{Role :: atom(), Count :: non_neg_integer()}].
%%% @end
%%%-------------------------------------------------------------------
-spec count_users_by_role() -> [{atom(), non_neg_integer()}].
count_users_by_role() ->
Users = mnesia:dirty_match_object(#user{_ = '_'}),
Dict = lists:foldl(fun(#user{role = Role}, Acc) ->
case lists:keyfind(Role, 1, Acc) of
false -> [{Role, 1} | Acc];
{Role, C} -> lists:keyreplace(Role, 1, Acc, {Role, C+1})
end
end, [], Users),
Dict.
%%%-------------------------------------------------------------------
%%% @doc Подсчёт пользователей по статусам.
%%% Возвращает список [{Status :: atom(), Count :: non_neg_integer()}].
%%% @end
%%%-------------------------------------------------------------------
-spec count_users_by_status() -> [{atom(), non_neg_integer()}].
count_users_by_status() ->
Users = mnesia:dirty_match_object(#user{_ = '_'}),
Dict = lists:foldl(fun(#user{status = Status}, Acc) ->
case lists:keyfind(Status, 1, Acc) of
false -> [{Status, 1} | Acc];
{Status, C} -> lists:keyreplace(Status, 1, Acc, {Status, C+1})
end
end, [], Users),
Dict.
%%%-------------------------------------------------------------------
%%% @doc Выделить из datetime только дату `{Y,M,D}`.
%%% @end