Skip to content

Commit

Permalink
cleaning up the api
Browse files Browse the repository at this point in the history
  • Loading branch information
nisbus committed Nov 1, 2012
1 parent 89393d0 commit a0866fc
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/monterl_carlo.erl
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,12 @@ start(Symbol,UpdateFun) when is_binary(Symbol) ->
start(Symbol,UpdateFun) when is_list(Symbol) ->
start(list_to_atom(Symbol),UpdateFun).

graph(Symbol,Points,Type) when is_atom(Symbol) ->
graph(Symbol,Points,Type) when is_atom(Symbol) and is_atom(Type) ->
gen_server:call(Symbol, {graph,Type,Points});
graph(Symbol,Points,Type) when is_list(Symbol) ->
graph(list_to_atom(Symbol),Points,Type);
graph(Symbol,Points,Type) when is_binary(Symbol) ->
graph(list_to_atom(binary_to_list(Symbol)),Points,Type).
graph(Symbol,Points,Type) when is_list(Symbol) and is_list(Type) ->
graph(list_to_atom(Symbol),Points,list_to_atom(Type));
graph(Symbol,Points,Type) when is_binary(Symbol) and is_binary(Type) ->
graph(list_to_atom(binary_to_list(Symbol)),Points,list_to_atom(binary_to_list(Type))).



Expand All @@ -98,6 +98,7 @@ stop(Symbol) when is_binary(Symbol) ->
init([State]) ->
{ok, State}.


handle_call({graph,Type,Points}, _From, State) ->
P = lists:seq(1,Points),
{Result,NewState} = lists:foldl(fun(X,Acc) ->
Expand All @@ -124,7 +125,7 @@ handle_call({graph,Type,Points}, _From, State) ->
_ -> {[[{<<"counter">>,X},{<<"bid">>,NS#state.bid}]|L],NS}
end
end,{[],State},P),
{reply, Result, NewState};
{reply, [{<<"graph">>,Result}], NewState};

handle_call(_Request, _From, State) ->
Reply = ok,
Expand Down Expand Up @@ -153,7 +154,7 @@ handle_info(interval,#state{updatefun=Update} = State) ->
{<<"max_bp_change">>,NS#state.max_bp_change},
{<<"min_bp_change">>,NS#state.min_bp_change},
{<<"bp_diff">>,NS#state.bp_diff}],
Update(Reply),
Update([{<<"point">>,Reply}]),
{noreply, NS}.


Expand Down

0 comments on commit a0866fc

Please sign in to comment.