Расширена общая статистика по дням: Отзывы, Календари, Жалобы, Тикеты, Подписки #22

This commit is contained in:
2026-05-27 22:40:03 +03:00
parent 4444461ee3
commit 2dac5e5102
9 changed files with 250 additions and 39 deletions
+30 -1
View File
@@ -5,7 +5,7 @@
-export([email_exists/1]).
-export([list_users/0]).
-export([block/2, unblock/2]).
-export([count_users/0, count_users_by_date/2, list_all/0]).
-export([count_users/0, count_users_by_date/2, count_pending_users/0, count_pending_users_by_date/2, list_all/0]).
-export([create_bot/2, delete_bot/1]).
%% ─────────────────────────────────────────────────────────────────
@@ -277,6 +277,35 @@ count_users_by_date(From, To) ->
end, [], Filtered),
lists:sort(Counts).
%%%-------------------------------------------------------------------
%%% @doc Количество неподтверждённых пользователей (status = pending).
%%% @end
%%%-------------------------------------------------------------------
-spec count_pending_users() -> non_neg_integer().
count_pending_users() ->
Match = #user{status = pending, _ = '_'},
length(mnesia:dirty_match_object(Match)).
%%%-------------------------------------------------------------------
%%% @doc Подсчёт неподтверждённых пользователей (status=pending) по дням.
%%% @end
%%%-------------------------------------------------------------------
-spec count_pending_users_by_date(From :: calendar:datetime(), To :: calendar:datetime()) ->
[{{pos_integer(), pos_integer(), pos_integer()}, non_neg_integer()}].
count_pending_users_by_date(From, To) ->
All = mnesia:dirty_match_object(#user{_ = '_'}),
Pending = lists:filter(fun(U) -> U#user.status =:= pending end, All),
Filtered = lists:filter(fun(U) -> U#user.created_at >= From andalso
U#user.created_at =< To end, Pending),
Counts = lists:foldl(fun(U, Acc) ->
Day = date_part(U#user.created_at),
case lists:keyfind(Day, 1, Acc) of
false -> [{Day, 1} | Acc];
{Day, C} -> lists:keyreplace(Day, 1, Acc, {Day, C+1})
end
end, [], Filtered),
lists:sort(Counts).
%%%-------------------------------------------------------------------
%%% @doc Выделить из datetime только дату `{Y,M,D}`.
%%% @end