fake data

This commit is contained in:
anlicheng 2024-09-12 15:37:21 +08:00
parent 49a73ad88f
commit 6c9f8549d0
4 changed files with 32 additions and 32 deletions

View File

@ -93,16 +93,11 @@ handle_call(_Request, _From, State = #state{}) ->
{noreply, NewState :: #state{}, timeout() | hibernate} |
{stop, Reason :: term(), NewState :: #state{}}).
handle_cast({forward, LocationCode, DynamicLocationCode, EventType, Params}, State = #state{id = Id, timer_map = TimerMap, pri_key = PriKey, url = Url}) ->
try
ReqBody = format_event(LocationCode, DynamicLocationCode, EventType, Params, PriKey),
catch do_post(Url, Id, ReqBody),
TimerRef = erlang:start_timer(?RETRY_INTERVAL, self(), {repost_ticker, Id, ReqBody}),
ReqBody = format_event(LocationCode, DynamicLocationCode, EventType, Params, PriKey),
catch do_post(Url, Id, ReqBody),
TimerRef = erlang:start_timer(?RETRY_INTERVAL, self(), {repost_ticker, Id, ReqBody}),
{noreply, State#state{id = Id + 1, timer_map = maps:put(Id, TimerRef, TimerMap)}}
catch _:Err:Stack ->
lager:notice("[iot_jinzhi_endpoint] format_event get error: ~p, stack: ~p", [Err, Stack]),
{noreply, State}
end.
{noreply, State#state{id = Id + 1, timer_map = maps:put(Id, TimerRef, TimerMap)}}.
%% @private
%% @doc Handling all non call/cast messages
@ -190,20 +185,9 @@ format_event(LocationCode, DynamicLocationCode, EventType, #{<<"event_code">> :=
end, Attachments0),
% <<"occurrenceTime">> => <<"2023-06-10 12:00:00">>,
% TODO delete
FakeLocationCodes = application:get_env(iot, fake_location_codes, []),
LocationCode1 = case length(FakeLocationCodes) > 0 of
true ->
Len = length(FakeLocationCodes),
RandomIndex = rand:uniform(Len),
Code = lists:nth(RandomIndex, FakeLocationCodes),
list_to_binary(Code);
false ->
LocationCode
end,
DeviceInfo = #{
% <<"location">> => LocationCode,
<<"location">> => LocationCode1,
<<"location">> => fake_location_code(EventCode, LocationCode),
<<"category">> => EventCode,
<<"description">> => Description,
<<"occurrenceTime">> => Datetime,
@ -277,4 +261,10 @@ serialize0([{K, V}|T], Target) ->
<<$[, V0/binary, $]>>
end,
Item = <<$", K/binary, $", $:, V1/binary>>,
serialize0(T, [Item|Target]).
serialize0(T, [Item|Target]).
fake_location_code(EventCode, LocationCode) when is_binary(EventCode), is_binary(LocationCode) ->
% TODO delete
FakeLocationCodes = application:get_env(iot, fake_location_codes, []),
proplists:get_value(EventCode, FakeLocationCodes, LocationCode).

View File

@ -15,7 +15,11 @@
{device_cache_size, 200},
{fake_location_codes, [
"0508103010001050300001"
{<<"23103">>, <<"0508103010001050300001">>},
{<<"20407">>, <<"0512104030001050400003">>},
{<<"10404">>, <<"0507106030001050600003">>},
{<<"22503">>, <<"0500000000001022700537">>},
{<<"23104">>, <<"0500000000001022700538">>}
]},
{watchdog, [

15
docs/jinzhi.md Normal file
View File

@ -0,0 +1,15 @@
# 事件分类
```text
23103 鼠类监测 event_code:
20407 异物占道 event_code:
10404 垃圾溢满 event_code:
22503 后厨非标着装 event_code:
23104 动火离人 event_code:
```
1、鼠类检测 0508103010001050300001 朴苑餐厅
2、异物占道 0512104030001050400003 行政楼B楼
3、垃圾溢满 0507106030001050600003 朴苑3舍
4、后厨非标着装 0500000000001022700537 监控摄像头532诚苑餐厅 北侧)
5、动火离人 0500000000001022700538 监控摄像头533诚苑餐厅 北侧)

View File

@ -1,9 +0,0 @@
# 事件分类
```text
23103 鼠类监测
20407 异物占道
10404 垃圾溢满
22503 后厨非标着装
23104 动火离人
```