Skip to content

Commit

Permalink
fix:topo,evidence
Browse files Browse the repository at this point in the history
  • Loading branch information
AvantLiu committed Jan 6, 2022
1 parent 68d52c5 commit 753d140
Show file tree
Hide file tree
Showing 14 changed files with 260 additions and 159 deletions.
2 changes: 1 addition & 1 deletion apps/dgiot_evidence/etc/dgiot_evidence.conf
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# gofastdfs
gofastdfs.path = /data/dgiot/go_fastdfs/files/dgiot_file/pump_pytoh/
gofastdfs.path = /data/dgiot/go_fastdfs/files/dgiot_file/pump_python/
2 changes: 1 addition & 1 deletion apps/dgiot_evidence/priv/dgiot_evidence.schema
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
%%--------------------------------------------------------------------

{mapping, "gofastdfs.path", "dgiot_evidence.gofastdfs_path", [
{default, "/data/dgiot/go_fastdfs/files/dgiot_file/pump_pytoh/"},
{default, "/data/dgiot/go_fastdfs/files/dgiot_file/pump_python/"},
{datatype, string}
]}.
51 changes: 36 additions & 15 deletions apps/dgiot_evidence/priv/python/drawxnqx.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,59 +124,80 @@ def draw(flow1, head1, headparameters, power1, powerparameters, effect, effectpa
nm = math.ceil(max(effect))
nmin = math.floor(min(effect))

fig = plt.figure(1)
fig = plt.figure(figsize=(9, 5))
host = HostAxes(fig, [0.15, 0.1, 0.65, 0.8])
par1 = ParasiteAxes(host, sharex=host)
par2 = ParasiteAxes(host, sharex=host)
host.parasites.append(par1)
host.parasites.append(par2)
host.set_ylabel('扬程')
host.set_xlabel('流量')
host.set_ylabel('效率(E)(%)', color="blue")
host.set_xlabel('流量(Q)(m3/h)')
host.axis['right'].set_visible(False)
par1.axis['right'].set_visible(True)
par1.set_ylabel('功率')
par1.set_ylabel('功率(P)(kW)', color="red")

par1.axis['right'].major_ticklabels.set_visible(True)
par1.axis['right'].label.set_visible(True)

par2.set_ylabel('扬程')
par2.set_ylabel('效率(E)(%)', color="blue")
offset = (60, 0)
new_axisline = par2._grid_helper.new_fixed_axis
par2.axis['right2'] = new_axisline(loc='right', axes=par2, offset=offset)
fig.add_axes(host)
host.set_xlim(0, fm + 1)
# host.set_xlim(0, fm + 1)
plt.xticks(range(0, fm + 1, 1))
host.set_ylim(0, hm + 5)

host.set_xlabel('流量')
host.set_ylabel('功率')
host.set_ylabel('效率')
host.set_xlabel('流量(Q)(m3/h)')
host.set_ylabel('功率(P)(kW)', color="red")
host.set_ylabel('扬程(H)(m)', color="black")
x = np.linspace(0, fm, 500)
y = headparameters[0] * x ** 2 + headparameters[1] * x + headparameters[2]
p1, = host.plot(x, y, label="HQ拟合曲线", color="black")
host.scatter(flow1, head1, label="HQ离散数据")
host.scatter(flow1, head1, c='k', label="HQ离散数据")
x1 = np.linspace(0, fm, 500)
y1 = powerparameters[0] * x ** 2 + powerparameters[1] * x + powerparameters[2]
p2, = par1.plot(x, y1, label="PQ拟合曲线", color="red")
par1.scatter(flow1, power1, label="PQ离散数据")
par1.scatter(flow1, power1, c='r', label="PQ离散数据")
x2 = np.linspace(0, fm, 500)
y2 = effectparameters[0] * x ** 2 + effectparameters[1] * x + effectparameters[2]
p3, = par2.plot(x, y2, label="EQ拟合曲线", color="blue")
par2.scatter(flow1, effect, label="EQ离散数据")
par2.scatter(flow1, effect, c='b', label="EQ离散数据")
par1.set_ylim(0, pm * 2)
par2.set_ylim(0, nm + 5)
host.legend()
# host.legend()
par2.axis['right2'].major_ticklabels.set_color(p3.get_color()) # 刻度值颜色
par2.axis['right2'].set_axisline_style('-|>', size=1.5) # 轴的形状色

par1.axis['right'].major_ticklabels.set_color(p2.get_color()) # 刻度值颜色

if 'dgiot_testing_equipment_flowSet' in params:
flowSet = float(params['dgiot_testing_equipment_flowSet'])
if flowSet > 1 and flowSet < math.ceil(max(flow1)):
par2.axvline(flowSet, color='orange')
x_begin = flowSet - 0.5
x_end = flowSet + 0.5
fepoints = [t for t in zip(flow1, effect) if x_begin <= t[0] <= x_end]
fhpoints = [t for t in zip(flow1, head1) if x_begin <= t[0] <= x_end]
fppoints = [t for t in zip(flow1, power1) if x_begin <= t[0] <= x_end]
par2.text(fepoints[0][0], fepoints[0][1] + 0.5,
("流量" + str(fepoints[0][0]) + " m3/h", "效率" + str(fepoints[0][1]) + " %"),
ha='center', color='b')
host.text(fhpoints[0][0], fhpoints[0][1] + 1,
("流量" + str(fhpoints[0][0]) + " m3/h", "扬程" + str(fhpoints[0][1]) + " m"),
ha='center', color='k')
par1.text(fppoints[0][0], fppoints[0][1] + 0.1,
("流量" + str(fppoints[0][0]) + " m3/h", "功率" + str(fppoints[0][1]) + " kW"),
ha='center', color='r')

# 解决使用matplotliblib画图的时候出现中文或者是负号无法显示的情况
mpl.rcParams['font.sans-serif'] = ['SimHei']
mpl.rcParams['axes.unicode_minus'] = False

plt.title("性能曲线拟合数据")
plt.legend(loc="best")
plt.legend(loc=9, bbox_to_anchor=(-0.142, 1.1), borderaxespad=0., fontsize=8)
# 获取当前时间
# localtime = time.strftime("%Y-%m-%d-%H-%M-%S", time.localtime())

filename = params['path'] + params['name']
# print(filename)
plt.savefig(filename)
Expand Down
45 changes: 23 additions & 22 deletions apps/dgiot_evidence/src/handler/dgiot_evidence_handler.erl
Original file line number Diff line number Diff line change
Expand Up @@ -204,14 +204,14 @@ do_request(post_generatereport, #{<<"id">> := TaskId}, #{<<"sessionToken">> := _
<<"source">> => Sources,
<<"name">> => Identifier,
<<"url">> => Value,
<<"width">> => 500,
<<"height">> => 230
<<"width">> => 600,
<<"height">> => 360
}];
_ ->
Acc
end;
_ ->
case Step =< 1 of
case Step =< 0 of
true ->
Acc;
_ ->
Expand All @@ -232,15 +232,15 @@ do_request(post_generatereport, #{<<"id">> := TaskId}, #{<<"sessionToken">> := _
[]
end,
%% 采样参数
Parameter = maps:get(<<"parameter">>, Param, <<"flow,power,head,ratedspeed,pressure_in,pressure_out,conversion_flow,conversion_head,conversion_power,effect">>),
Parameter = maps:get(<<"parameter">>, Param, <<"flow,power,head,rotate,pressure_in,pressure_out,conversion_flow,conversion_head,conversion_power,effect">>),
{Tabledata, _} = dgiot_evidence:get_Tabledata(Parameter, Avgdatas),
Acc ++ [#{
<<"type">> => <<"dynamicTable">>,
<<"source">> => Sources,
<<"tablerow">> => Row,
<<"tablecolumn">> => Column,
<<"name">> => Identifier,
<<"data">> => Tabledata
<<"data">> => lists:reverse(Tabledata)
}];
<<"image">> ->
Repath =
Expand All @@ -255,9 +255,9 @@ do_request(post_generatereport, #{<<"id">> := TaskId}, #{<<"sessionToken">> := _
<<"type">> => <<"image">>,
<<"source">> => Sources,
<<"name">> => Identifier,
<<"url">> => Repath,
<<"url">> => <<Uri/binary, Repath/binary>>,
<<"width">> => 600,
<<"height">> => 330
<<"height">> => 360
}];
_ ->
Acc
Expand Down Expand Up @@ -309,16 +309,8 @@ do_request(post_generatereport, #{<<"id">> := TaskId}, #{<<"sessionToken">> := _
%% OperationId:post_drawxnqx
%% 请求:GET /iotapi/drawxnqx
do_request(post_drawxnqx, #{<<"taskid">> := TaskId, <<"data">> := Data}, #{<<"sessionToken">> := SessionToken} = _Context, _Req) ->
%% io:format("~s ~p Data = ~p.~n", [?FILE, ?LINE, Data]),
%% NewData = arrtojsonlist(Data),
%% AvgData =
%% maps:fold(fun(K, V, Avg) ->
%% SumV =
%% lists:foldl(fun(V1, VSum) ->
%% VSum + V1
%% end, 0, V),
%% Avg#{K => dgiot_utils:to_float(SumV / length(Data), 3)}
%% end, #{}, maps:without([<<"timestamp">>], NewData)),
%% dgiot_testing_equipment_flowSet
%% TaskId = ,
{NewEvidenceId, NewOriginal} =
case dgiot_parse:query_object(<<"Evidence">>, #{<<"limit">> => 1, <<"where">> => #{<<"reportId">> => TaskId, <<"original.type">> => <<"avgs">>, <<"original.taskid">> => TaskId}}) of
{ok, #{<<"results">> := Results}} when length(Results) > 0 ->
Expand Down Expand Up @@ -979,6 +971,7 @@ post_report(#{<<"name">> := Name, <<"product">> := ProductId, <<"parentId">> :=
end.



arrtojsonlist(Data) when length(Data) > 0 ->
[Da | _] = Data,
Keys = maps:keys(Da),
Expand All @@ -994,15 +987,23 @@ arrtojsonlist(_Data) ->
#{}.

python_drawxnqx(TaskId, NewData) ->
%% io:format("NewData ~p~n",[NewData]),
Dgiot_testing_equipment_flowSet =
case dgiot_parse:get_object(<<"Device">>, TaskId) of
{ok, #{<<"basedata">> := BaseData}} ->
dgiot_utils:to_float(maps:get(<<"dgiot_testing_equipment_flowSet">>, BaseData, <<>>));
_ ->
0
end,
Path = code:priv_dir(dgiot_evidence),
Python3path = Path ++ "/python/drawxnqx.py ",
Filepath = application:get_env(dgiot_evidence, gofastdfs_path, <<"/data/dgiot/go_fastdfs/files/dgiot_file/pump_pytoh/">>),
PythonBody = #{<<"name">> => <<TaskId/binary, ".png">>, <<"data">> => NewData, <<"path">> => Filepath},
Filepath = application:get_env(dgiot_evidence, gofastdfs_path, <<"/data/dgiot/go_fastdfs/files/dgiot_file/pump_python/">>),
PythonBody = #{<<"name">> => <<TaskId/binary, ".png">>, <<"data">> => NewData, <<"path">> => Filepath, <<"dgiot_testing_equipment_flowSet">> => Dgiot_testing_equipment_flowSet},
Imagepath =
case catch base64:decode(os:cmd("python3 "++ Python3path ++ dgiot_utils:to_list(base64:encode(jsx:encode(PythonBody))))) of
case catch base64:decode(os:cmd("python3 " ++ Python3path ++ dgiot_utils:to_list(base64:encode(jsx:encode(PythonBody))))) of
{'EXIT', _Error} ->
<<"">>;
Path ->
Path
NewPath ->
NewPath
end,
re:replace(dgiot_utils:to_list(Imagepath), "/data/dgiot/go_fastdfs/files", "", [global, {return, binary}, unicode]).
11 changes: 6 additions & 5 deletions apps/dgiot_license/src/license_loader.erl
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,14 @@
-record(state, {}).

start() ->
Env = #{},
emqx:hook('client.authenticate', fun ?MODULE:on_client_authenticate/3, [Env]),
emqx:hook('client.disconnected', fun ?MODULE:on_client_disconnected/4, [Env]).
%% Env = #{},
%% emqx:hook('client.authenticate', fun ?MODULE:on_client_authenticate/3, [Env]),
%% emqx:hook('client.disconnected', fun ?MODULE:on_client_disconnected/4, [Env]).
ok.

stop() ->
emqx:unhook('client.authenticate', fun ?MODULE:on_client_authenticate/3),
emqx:unhook('client.disconnected', fun ?MODULE:on_client_disconnected/4),
%% emqx:unhook('client.authenticate', fun ?MODULE:on_client_authenticate/3),
%% emqx:unhook('client.disconnected', fun ?MODULE:on_client_disconnected/4),
ok.

on_client_authenticate(#{clientid := <<"swlic_", Key/binary>>, peerhost := Peerhost, username := UserName, password := Password}, AuthResult, _Env) ->
Expand Down
4 changes: 4 additions & 0 deletions apps/dgiot_mqtt/etc/dgiot_mqtt.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
## Password hash.
##
## Value: plain | md5 | sha | sha256 | sha512
auth.password_hash = sha256
7 changes: 7 additions & 0 deletions apps/dgiot_mqtt/priv/dgiot_mqtt.schema
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
%%-*- mode: erlang -*-
%% dgiot_mqtt config mapping

{mapping, "auth.password_hash", "dgiot_mqtt.password_hash", [
{default, sha256},
{datatype, {enum, [plain, md5, sha, sha256, sha512]}}
]}.
6 changes: 2 additions & 4 deletions apps/dgiot_mqtt/src/dgiot_mqtt_channel.erl
Original file line number Diff line number Diff line change
Expand Up @@ -272,9 +272,7 @@ create_rules(RuleID, ChannelId, Description, Rawsql, Target_topic) ->


load_auth_hook() ->
%% emqx:hook('client.authenticate', fun dgiot_mqtt_auth:check/3, []).
ok.
emqx:hook('client.authenticate', fun dgiot_mqtt_auth:check/3, []).

load_acl_hook() ->
%% emqx:hook('client.check_acl', fun dgiot_mqtt_acl:check_acl/5, [#{}]).
ok.
emqx:hook('client.check_acl', fun dgiot_mqtt_acl:check_acl/5, [#{}]).
38 changes: 23 additions & 15 deletions apps/dgiot_opc/src/handler/dgiot_opc_handler.erl
Original file line number Diff line number Diff line change
Expand Up @@ -76,29 +76,37 @@ handle(OperationID, Args, Context, Req) ->
%%% 内部函数 Version:API版本
%%%===================================================================
do_request(post_head, #{<<"items">> := Items, <<"productid">> := ProductId}, _Context, _Req) ->
Head =
{Head, Table} =
case dgiot_product:lookup_prod(ProductId) of
{ok, #{<<"thing">> := #{<<"properties">> := Props}}} ->
lists:foldl(fun(Item, Acc) ->
lists:foldl(fun(Prop, Acc1) ->
case Prop of
#{<<"name">> := Name, <<"identifier">> := Identifier,
<<"dataType">> := #{<<"type">> := _Type, <<"das">> := Das}} ->
lists:foldl(fun(Prop, {Acc1, Acc2}) ->
case Prop of
#{<<"name">> := Name, <<"identifier">> := Identifier,
<<"dataType">> := #{<<"type">> := _Type, <<"das">> := Das} = DataType} ->
Specs = maps:get(<<"specs">>, DataType, #{}),
Unit =
case maps:find(<<"unit">>, Specs) of
error ->
<<>>;
{ok, Un} ->
<<"(", Un/binary, ")">>
end,
lists:foldl(fun(Item, {Acc, Acc3}) ->
case lists:member(Item, Das) of
true ->
Acc1#{Identifier => Name};
{Acc#{Identifier => <<Name/binary, Unit/binary>>}, Acc3 ++ [#{<<"prop">> => Identifier, <<"label">> => <<Name/binary, Unit/binary>>}]};
_ ->
Acc1
end;
_ ->
Acc1
end
end, Acc, Props)
end, #{}, Items);
{Acc, Acc3}
end
end, {Acc1, Acc2}, Items);
_ ->
{Acc1, Acc2}
end
end, {#{}, [#{<<"prop">> => <<"timestamp">>, <<"label">> => <<"时间"/utf8>>}]}, Props);
_Error ->
#{}
end,
{ok, #{<<"code">> => 200, <<"head">> => Head}};
{ok, #{<<"code">> => 200, <<"head">> => Head, <<"table">> => Table}};

%% 服务器不支持的API接口
do_request(_OperationId, _Args, _Context, _Req) ->
Expand Down
8 changes: 4 additions & 4 deletions apps/dgiot_parse/etc/dgiot_parse.conf
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ parse.delete_field = ACL,objectId,updatedAt,createdAt
##--------------------------------------------------------------------
parse.parse_server = http://prod.iotn2n.com:1337
parse.parse_path = /parse/
parse.parse_appid = 49aa5a778d7ad75444d6ec010df4c633
parse.parse_master_key = 44f4052cae56b51e097420d23844a6ef
parse.parse_js_key = 7f2cf7f9ee16fabfe48cc48feed72347
parse.parse_rest_key = 35f51e718318f432a41e8bd9453f0c03
parse.parse_appid = 4def2774e6404456e17f8f58295f5f09
parse.parse_master_key = 4d5d2aa27bc82eca4797a0ab73e85f43
parse.parse_js_key = 13d64975825ea872ea2f724887861edd
parse.parse_rest_key = a216e04802ca54f6e709e7fba1b2965b

##--------------------------------------------------------------------
## parse cache
Expand Down
11 changes: 11 additions & 0 deletions apps/dgiot_topo/priv/swagger/swagger_topo.json
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,13 @@
"type": "string",
"default": ""
},
{
"description": "视图ObjectId",
"in": "query",
"name": "viewid",
"type": "string",
"default": ""
},
{
"description": "shapeid",
"in": "query",
Expand Down Expand Up @@ -148,6 +155,10 @@
"productid": {
"type": "string"
},
"viewid": {
"type": "string",
"example": ""
},
"shapeid": {
"type": "string"
},
Expand Down
Loading

0 comments on commit 753d140

Please sign in to comment.