Расширена общая статистика по дням: Отзывы, Календари, Жалобы, Тикеты, Подписки #22
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
-export([update_status/2, check_expired/0]).
|
||||
-export([list_subscriptions/0, create_subscription/1, update_subscription/2, delete_subscription/1]).
|
||||
-export([count_subscription/0]).
|
||||
-export([count_subscriptions_by_date/2]).
|
||||
|
||||
-define(TRIAL_DAYS, 30).
|
||||
|
||||
@@ -292,4 +293,25 @@ parse_iso_datetime(Other) -> Other.
|
||||
%%%-------------------------------------------------------------------
|
||||
-spec count_subscription() -> non_neg_integer().
|
||||
count_subscription() ->
|
||||
mnesia:table_info(subscription, size).
|
||||
mnesia:table_info(subscription, size).
|
||||
|
||||
%%%-------------------------------------------------------------------
|
||||
%%% @doc Подсчёт подписок, созданных в заданном временном диапазоне.
|
||||
%%% @end
|
||||
%%%-------------------------------------------------------------------
|
||||
-spec count_subscriptions_by_date(From :: calendar:datetime(), To :: calendar:datetime()) ->
|
||||
[{{pos_integer(), pos_integer(), pos_integer()}, non_neg_integer()}].
|
||||
count_subscriptions_by_date(From, To) ->
|
||||
All = mnesia:dirty_match_object(#subscription{_ = '_'}),
|
||||
Filtered = lists:filter(fun(S) -> S#subscription.created_at >= From andalso
|
||||
S#subscription.created_at =< To end, All),
|
||||
Counts = lists:foldl(fun(S, Acc) ->
|
||||
Day = date_part(S#subscription.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).
|
||||
|
||||
date_part({{Y,M,D}, _}) -> {Y,M,D}.
|
||||
Reference in New Issue
Block a user