Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Aggregate count

  • Loading branch information...
commit 20ce972b6e15c422f14fd6bbfad29b8ac09defef 1 parent 7c2de89
@MasseR authored
Showing with 10 additions and 0 deletions.
  1. +10 −0 src/itemstats_srv.erl
View
10 src/itemstats_srv.erl
@@ -82,6 +82,8 @@ init([]) ->
%% {stop, Reason, State}
%% @end
%%--------------------------------------------------------------------
+handle_call({get, Key}, _From, State) ->
+ {reply, internal_aggregate_value(Key), State};
handle_call({get, Key, TurtleId}, _From, State) ->
{reply, internal_value(Key, TurtleId), State};
handle_call(_Request, _From, State) ->
@@ -186,4 +188,12 @@ internal_value(Key, TurtleId) ->
_Res -> 0
end.
+% Full scan for now
+internal_aggregate_value(Key) ->
+ Turtles = case dets:lookup(?MODULE, turtles) of
+ [ {turtles, X} ] -> X;
+ [] -> sets:new()
+ end,
+ sets:fold(fun(Turtle, Acc) -> Acc + internal_value(Key, Turtle) end, 0, Turtles).
+
make_key(Key, TurtleId) -> TurtleId ++ "-" ++ Key.
Please sign in to comment.
Something went wrong with that request. Please try again.