[api] move base and night paths to defines
This commit is contained in:
parent
c9f3eb8431
commit
d767c50287
|
@ -16,6 +16,9 @@
|
||||||
%%%
|
%%%
|
||||||
%% @doc Common record definitions and helper functions for the Flukso API.
|
%% @doc Common record definitions and helper functions for the Flukso API.
|
||||||
|
|
||||||
|
-define(BASE_PATH, "var/data/base/").
|
||||||
|
-define(NIGHT_PATH, "var/data/night/").
|
||||||
|
|
||||||
-define(MINUTE, 60).
|
-define(MINUTE, 60).
|
||||||
-define(QUARTER, 900).
|
-define(QUARTER, 900).
|
||||||
-define(HOUR, 3600).
|
-define(HOUR, 3600).
|
||||||
|
|
|
@ -115,8 +115,8 @@ content_types_provided(ReqData, State) ->
|
||||||
|
|
||||||
to_json(ReqData, #state{rrdSensor = RrdSensor, rrdStart = RrdStart, rrdEnd = RrdEnd, rrdResolution = RrdResolution, rrdFactor = RrdFactor, jsonpCallback = JsonpCallback} = State) ->
|
to_json(ReqData, #state{rrdSensor = RrdSensor, rrdStart = RrdStart, rrdEnd = RrdEnd, rrdResolution = RrdResolution, rrdFactor = RrdFactor, jsonpCallback = JsonpCallback} = State) ->
|
||||||
case wrq:get_qs_value("interval", ReqData) of
|
case wrq:get_qs_value("interval", ReqData) of
|
||||||
"night" -> Path = "var/data/night/";
|
"night" -> Path = NIGHT_PATH;
|
||||||
_Interval -> Path = "var/data/base/"
|
_Interval -> Path = BASE_PATH
|
||||||
end,
|
end,
|
||||||
|
|
||||||
%% debugging: io:format("~s~n", [erlrrd:c([[Path, [RrdSensor|".rrd"]], "AVERAGE", ["-s ", RrdStart], ["-e ", RrdEnd], ["-r ", RrdResolution]])]),
|
%% debugging: io:format("~s~n", [erlrrd:c([[Path, [RrdSensor|".rrd"]], "AVERAGE", ["-s ", RrdStart], ["-e ", RrdEnd], ["-r ", RrdResolution]])]),
|
||||||
|
@ -140,15 +140,13 @@ to_json(ReqData, #state{rrdSensor = RrdSensor, rrdStart = RrdStart, rrdEnd = Rrd
|
||||||
% JSON: {"measurements":[[<TS1>,<VALUE1>],...,[<TSn>,<VALUEn>]]}
|
% JSON: {"measurements":[[<TS1>,<VALUE1>],...,[<TSn>,<VALUEn>]]}
|
||||||
% Mochijson2: {struct,[{<<"measurements">>,[[<TS1>,<VALUE1>],...,[<TSn>,<VALUEn>]]}]}
|
% Mochijson2: {struct,[{<<"measurements">>,[[<TS1>,<VALUE1>],...,[<TSn>,<VALUEn>]]}]}
|
||||||
process_post(ReqData, #state{rrdSensor = RrdSensor} = State) ->
|
process_post(ReqData, #state{rrdSensor = RrdSensor} = State) ->
|
||||||
Path = "var/data/base/",
|
|
||||||
|
|
||||||
{struct, JsonData} = mochijson2:decode(wrq:req_body(ReqData)),
|
{struct, JsonData} = mochijson2:decode(wrq:req_body(ReqData)),
|
||||||
Measurements = proplists:get_value(<<"measurements">>, JsonData),
|
Measurements = proplists:get_value(<<"measurements">>, JsonData),
|
||||||
RrdData = [[integer_to_list(Time), ":", integer_to_list(Counter), " "] || [Time, Counter] <- Measurements],
|
RrdData = [[integer_to_list(Time), ":", integer_to_list(Counter), " "] || [Time, Counter] <- Measurements],
|
||||||
|
|
||||||
%debugging: io:format("~s~n", [[Path, [RrdSensor|".rrd"], " ", RrdData]]),
|
%debugging: io:format("~s~n", [[Path, [RrdSensor|".rrd"], " ", RrdData]]),
|
||||||
|
|
||||||
case erlrrd:update([Path, [RrdSensor|".rrd"], " ", RrdData]) of
|
case erlrrd:update([BASE_PATH, [RrdSensor|".rrd"], " ", RrdData]) of
|
||||||
{ok, _RrdResponse} -> RrdResponse = "ok";
|
{ok, _RrdResponse} -> RrdResponse = "ok";
|
||||||
{error, RrdResponse} -> true
|
{error, RrdResponse} -> true
|
||||||
end,
|
end,
|
||||||
|
|
Loading…
Reference in New Issue