Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
U
unify_api2
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
chaonan
unify_api2
Commits
4c7a3d80
Commit
4c7a3d80
authored
Jun 30, 2023
by
lcn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bug修复
parent
c3c7703f
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
63 additions
and
60 deletions
+63
-60
electric_service.py
unify_api/modules/electric/service/electric_service.py
+43
-40
electric.py
unify_api/modules/electric/views/electric.py
+20
-20
No files found.
unify_api/modules/electric/service/electric_service.py
View file @
4c7a3d80
...
@@ -20,7 +20,8 @@ from unify_api.modules.electric.procedures.electric_util import \
...
@@ -20,7 +20,8 @@ from unify_api.modules.electric.procedures.electric_util import \
load_point_ctnum
load_point_ctnum
from
datetime
import
datetime
from
datetime
import
datetime
from
unify_api.constants
import
REAL_EXP_TIME
from
unify_api.constants
import
REAL_EXP_TIME
from
unify_api.utils.time_format
import
CST
,
YMD_Hms
,
timestamp2dts
from
unify_api.utils.time_format
import
CST
,
YMD_Hms
,
timestamp2dts
,
\
time_pick_transf
from
unify_api.modules.common.procedures.location_temp_rcurrent
import
\
from
unify_api.modules.common.procedures.location_temp_rcurrent
import
\
location_stats_statics
location_stats_statics
from
unify_api.modules.electric.components.electric
import
(
from
unify_api.modules.electric.components.electric
import
(
...
@@ -76,12 +77,12 @@ async def elec_current_storeys_service(storeys):
...
@@ -76,12 +77,12 @@ async def elec_current_storeys_service(storeys):
"ua"
:
""
,
"ia"
:
""
,
"ub"
:
""
,
"ib"
:
""
,
"uc"
:
""
,
"ic"
:
""
,
"ua"
:
""
,
"ia"
:
""
,
"ub"
:
""
,
"ib"
:
""
,
"uc"
:
""
,
"ic"
:
""
,
"pttl"
:
""
,
"qttl"
:
""
,
"freq"
:
""
,
"costtl"
:
""
,
"lf"
:
""
,
"pttl"
:
""
,
"qttl"
:
""
,
"freq"
:
""
,
"costtl"
:
""
,
"lf"
:
""
,
"sdu_i"
:
""
,
"sdu_u"
:
""
,
}
"sdu_i"
:
""
,
"sdu_u"
:
""
,
}
if
storey_name
in
elec_data
:
if
storey_name
in
elec_data
:
elec_data
[
storey_name
]
.
append
(
res_dic
)
elec_data
[
storey_name
]
.
append
(
res_dic
)
else
:
else
:
elec_data
[
storey_name
]
=
[
res_dic
]
elec_data
[
storey_name
]
=
[
res_dic
]
# 转换成list格式, 可以按照storey_name排序
# 转换成list格式, 可以按照storey_name排序
if
elec_data
:
if
elec_data
:
# 房间排序, 并返回数据转化为list
# 房间排序, 并返回数据转化为list
...
@@ -148,7 +149,7 @@ async def qual_current_storeys_service(storeys):
...
@@ -148,7 +149,7 @@ async def qual_current_storeys_service(storeys):
qual_data
[
storey_name
]
.
append
(
res_dic
)
qual_data
[
storey_name
]
.
append
(
res_dic
)
else
:
else
:
qual_data
[
storey_name
]
=
[
res_dic
]
qual_data
[
storey_name
]
=
[
res_dic
]
# 转换成list格式, 可以按照storey_name排序
# 转换成list格式, 可以按照storey_name排序
if
qual_data
:
if
qual_data
:
# 房间排序, 并返回数据转化为list
# 房间排序, 并返回数据转化为list
...
@@ -229,7 +230,7 @@ async def elec_card_level_service(point_list):
...
@@ -229,7 +230,7 @@ async def elec_card_level_service(point_list):
"costtl_threshold"
:
COSTTL_THRESHOLD
,
"costtl_threshold"
:
COSTTL_THRESHOLD
,
"lf_threshold"
:
LF_THRESHOLD
,
"lf_threshold"
:
LF_THRESHOLD
,
}
}
ret_data
[
m_type
]
.
append
(
res_dic
)
ret_data
[
m_type
]
.
append
(
res_dic
)
return
EclResp
(
inline
=
ret_data
[
"inline"
],
return
EclResp
(
inline
=
ret_data
[
"inline"
],
transformer
=
ret_data
[
"transformer"
],
transformer
=
ret_data
[
"transformer"
],
...
@@ -263,15 +264,15 @@ async def qual_current_level_service(point_list):
...
@@ -263,15 +264,15 @@ async def qual_current_level_service(point_list):
# 初始化返回dic
# 初始化返回dic
rt_ele
=
get_sdu_i_and_u
(
rt_ele
,
ctnum
)
rt_ele
=
get_sdu_i_and_u
(
rt_ele
,
ctnum
)
time_str
=
timestamp2dts
(
rt_ele
[
"ts"
],
YMD_Hms
)
time_str
=
timestamp2dts
(
rt_ele
[
"ts"
],
YMD_Hms
)
fdia
=
round_2
(
rt_ele
.
get
(
"fdia"
))
fdia
=
round_2
(
rt_ele
.
get
(
"fdia"
))
fdib
=
round_2
(
rt_ele
.
get
(
"fdib"
))
fdib
=
round_2
(
rt_ele
.
get
(
"fdib"
))
fdic
=
round_2
(
rt_ele
.
get
(
"fdic"
))
fdic
=
round_2
(
rt_ele
.
get
(
"fdic"
))
thdia
=
round_4
(
rt_ele
.
get
(
"thdia"
))
thdia
=
round_4
(
rt_ele
.
get
(
"thdia"
))
thdib
=
round_4
(
rt_ele
.
get
(
"thdib"
))
thdib
=
round_4
(
rt_ele
.
get
(
"thdib"
))
thdic
=
round_4
(
rt_ele
.
get
(
"thdic"
))
thdic
=
round_4
(
rt_ele
.
get
(
"thdic"
))
res_dic
=
{
res_dic
=
{
"name"
:
m_name
,
"name"
:
m_name
,
"point_id"
:
point_id
,
"point_id"
:
point_id
,
...
@@ -279,7 +280,7 @@ async def qual_current_level_service(point_list):
...
@@ -279,7 +280,7 @@ async def qual_current_level_service(point_list):
"real_time"
:
time_str
,
"real_time"
:
time_str
,
# 电流/电压谐波畸变率
# 电流/电压谐波畸变率
"thdia"
:
thdia
,
"thdib"
:
thdib
,
"thdic"
:
thdic
,
"thdia"
:
thdia
,
"thdib"
:
thdib
,
"thdic"
:
thdic
,
"thdua"
:
round_4
(
rt_ele
.
get
(
"thdua"
)),
"thdua"
:
round_4
(
rt_ele
.
get
(
"thdua"
)),
"thdub"
:
round_4
(
rt_ele
.
get
(
"thdub"
)),
"thdub"
:
round_4
(
rt_ele
.
get
(
"thdub"
)),
"thduc"
:
round_4
(
rt_ele
.
get
(
"thduc"
)),
"thduc"
:
round_4
(
rt_ele
.
get
(
"thduc"
)),
...
@@ -296,7 +297,7 @@ async def qual_current_level_service(point_list):
...
@@ -296,7 +297,7 @@ async def qual_current_level_service(point_list):
"uc_dev"
:
round_4
(
rt_ele
.
get
(
"uc_dev"
)),
"uc_dev"
:
round_4
(
rt_ele
.
get
(
"uc_dev"
)),
"uab_dev"
:
round_4
(
rt_ele
.
get
(
"uab_dev"
)),
"uab_dev"
:
round_4
(
rt_ele
.
get
(
"uab_dev"
)),
"ucb_dev"
:
round_4
(
rt_ele
.
get
(
"ucb_dev"
)),
"ucb_dev"
:
round_4
(
rt_ele
.
get
(
"ucb_dev"
)),
# 电流总谐波有效值 = 基波电流 * 电流总谐波畸变率
# 电流总谐波有效值 = 基波电流 * 电流总谐波畸变率
"thdia_virtual"
:
round_2
(
multiplication_two
(
fdia
,
thdia
)),
"thdia_virtual"
:
round_2
(
multiplication_two
(
fdia
,
thdia
)),
"thdib_virtual"
:
round_2
(
multiplication_two
(
fdib
,
thdib
)),
"thdib_virtual"
:
round_2
(
multiplication_two
(
fdib
,
thdib
)),
...
@@ -316,7 +317,7 @@ async def qual_current_level_service(point_list):
...
@@ -316,7 +317,7 @@ async def qual_current_level_service(point_list):
"real_time"
:
""
,
"real_time"
:
""
,
# 电流/电压谐波畸变率
# 电流/电压谐波畸变率
"thdia"
:
""
,
"thdib"
:
""
,
"thdic"
:
""
,
"thdia"
:
""
,
"thdib"
:
""
,
"thdic"
:
""
,
"thdua"
:
""
,
"thdub"
:
""
,
"thduc"
:
""
,
"thdua"
:
""
,
"thdub"
:
""
,
"thduc"
:
""
,
"thduab"
:
""
,
"thducb"
:
""
,
"thduab"
:
""
,
"thducb"
:
""
,
# 基波电流
# 基波电流
...
@@ -332,7 +333,7 @@ async def qual_current_level_service(point_list):
...
@@ -332,7 +333,7 @@ async def qual_current_level_service(point_list):
"thdib_virtual"
:
""
,
"thdib_virtual"
:
""
,
"thdic_virtual"
:
""
,
"thdic_virtual"
:
""
,
}
}
ret_data
[
m_type
]
.
append
(
res_dic
)
ret_data
[
m_type
]
.
append
(
res_dic
)
return
QclResp
(
inline
=
ret_data
[
"inline"
],
return
QclResp
(
inline
=
ret_data
[
"inline"
],
transformer
=
ret_data
[
"transformer"
],
transformer
=
ret_data
[
"transformer"
],
...
@@ -346,12 +347,14 @@ async def elec_index_service(cid, point_id, start, end):
...
@@ -346,12 +347,14 @@ async def elec_index_service(cid, point_id, start, end):
ctnum
=
await
load_point_ctnum
(
point_id
)
ctnum
=
await
load_point_ctnum
(
point_id
)
ctnum
=
ctnum
if
ctnum
==
2
else
3
ctnum
=
ctnum
if
ctnum
==
2
else
3
now
=
str
(
datetime
.
now
())
now
=
str
(
datetime
.
now
())
if
start
[:
10
]
==
now
[:
10
]
and
end
[:
10
]
==
now
[:
10
]:
intervel
,
_
=
time_pick_transf
(
start
,
end
)
table_name
=
"point_15min_electric"
if
intervel
==
86400
:
redi_table_name
=
"location_15min_aiao"
else
:
table_name
=
"point_1day_electric"
table_name
=
"point_1day_electric"
redi_table_name
=
"location_1day_aiao"
redi_table_name
=
"location_1day_aiao"
else
:
table_name
=
"point_15min_electric"
redi_table_name
=
"location_15min_aiao"
if
ctnum
==
2
:
if
ctnum
==
2
:
common_items
=
[
"lf_mean"
,
"lf_min"
,
"lf_max"
,
"pttl_mean"
,
"pttl_min"
,
common_items
=
[
"lf_mean"
,
"lf_min"
,
"lf_max"
,
"pttl_mean"
,
"pttl_min"
,
"pttl_max"
,
"qttl_mean"
,
"qttl_min"
,
"qttl_max"
,
"pttl_max"
,
"qttl_mean"
,
"qttl_min"
,
"qttl_max"
,
...
@@ -514,7 +517,7 @@ async def elec_current_service(point_id):
...
@@ -514,7 +517,7 @@ async def elec_current_service(point_id):
if
not
p_info
or
not
p_info
[
"mtid"
]:
if
not
p_info
or
not
p_info
[
"mtid"
]:
msg
=
f
"没有监测点:{point_id} monitor信息,请联系运维人员!"
msg
=
f
"没有监测点:{point_id} monitor信息,请联系运维人员!"
raise
BusinessException
(
message
=
msg
)
raise
BusinessException
(
message
=
msg
)
now_ts
=
pendulum
.
now
(
tz
=
CST
)
.
int_timestamp
now_ts
=
pendulum
.
now
(
tz
=
CST
)
.
int_timestamp
d_rt_ele
,
ts
=
None
,
now_ts
d_rt_ele
,
ts
=
None
,
now_ts
try
:
try
:
...
@@ -529,27 +532,27 @@ async def elec_current_service(point_id):
...
@@ -529,27 +532,27 @@ async def elec_current_service(point_id):
for
k
in
rt_ele_hr
.
keys
():
for
k
in
rt_ele_hr
.
keys
():
if
k
not
in
rt_ele
.
keys
():
if
k
not
in
rt_ele
.
keys
():
rt_ele
[
k
]
=
rt_ele_hr
[
k
]
rt_ele
[
k
]
=
rt_ele_hr
[
k
]
d_rt_ele
,
ts
=
rt_ele
,
rt_ele
[
"ts"
]
d_rt_ele
,
ts
=
rt_ele
,
rt_ele
[
"ts"
]
elif
rt_ele
:
elif
rt_ele
:
rt_ele
=
json
.
loads
(
rt_ele
)
rt_ele
=
json
.
loads
(
rt_ele
)
if
now_ts
-
rt_ele
[
"ts"
]
<=
REAL_EXP_TIME
:
if
now_ts
-
rt_ele
[
"ts"
]
<=
REAL_EXP_TIME
:
d_rt_ele
,
ts
=
rt_ele
,
rt_ele
[
"ts"
]
d_rt_ele
,
ts
=
rt_ele
,
rt_ele
[
"ts"
]
elif
rt_ele_hr
:
elif
rt_ele_hr
:
rt_ele_hr
=
json
.
loads
(
rt_ele_hr
)
rt_ele_hr
=
json
.
loads
(
rt_ele_hr
)
if
now_ts
-
rt_ele_hr
[
"ts"
]
<=
REAL_EXP_TIME
:
if
now_ts
-
rt_ele_hr
[
"ts"
]
<=
REAL_EXP_TIME
:
d_rt_ele
,
ts
=
rt_ele_hr
,
rt_ele_hr
[
"ts"
]
d_rt_ele
,
ts
=
rt_ele_hr
,
rt_ele_hr
[
"ts"
]
except
Exception
as
e
:
except
Exception
as
e
:
log
.
error
(
f
"parse real time electric error, pid:{point_id}"
)
log
.
error
(
f
"parse real time electric error, pid:{point_id}"
)
log
.
exception
(
e
)
log
.
exception
(
e
)
time_str
=
timestamp2dts
(
ts
,
YMD_Hms
)
time_str
=
timestamp2dts
(
ts
,
YMD_Hms
)
if
d_rt_ele
is
None
:
if
d_rt_ele
is
None
:
return
time_str
,
None
return
time_str
,
None
# 识电U只有一项有数据,返回具体的项
# 识电U只有一项有数据,返回具体的项
ctnum
=
d_rt_ele
.
get
(
"ctnum"
)
or
3
ctnum
=
d_rt_ele
.
get
(
"ctnum"
)
or
3
return
time_str
,
get_sdu_i_and_u
(
d_rt_ele
,
ctnum
)
return
time_str
,
get_sdu_i_and_u
(
d_rt_ele
,
ctnum
)
...
@@ -561,27 +564,27 @@ async def batch_load_rt_ele(mtids):
...
@@ -561,27 +564,27 @@ async def batch_load_rt_ele(mtids):
try
:
try
:
db
=
SETTING
.
mysql_db
db
=
SETTING
.
mysql_db
keys
=
[
f
"real_time:electric:{db}:{mtid}"
for
mtid
in
mtids
]
keys
=
[
f
"real_time:electric:{db}:{mtid}"
for
mtid
in
mtids
]
i_size
=
500
i_size
=
500
lst_rt_ele
=
[]
lst_rt_ele
=
[]
for
i
in
range
(
math
.
ceil
(
len
(
mtids
)
/
i_size
)):
for
i
in
range
(
math
.
ceil
(
len
(
mtids
)
/
i_size
)):
pipe
=
await
RedisUtils
()
.
client
.
pipeline
()
pipe
=
await
RedisUtils
()
.
client
.
pipeline
()
for
key
in
keys
[
i_size
*
i
:
i_size
*
(
i
+
1
)]:
for
key
in
keys
[
i_size
*
i
:
i_size
*
(
i
+
1
)]:
await
pipe
.
get
(
key
)
await
pipe
.
get
(
key
)
lst_rt_ele
+=
await
pipe
.
execute
()
lst_rt_ele
+=
await
pipe
.
execute
()
for
rt_ele
in
lst_rt_ele
:
for
rt_ele
in
lst_rt_ele
:
if
rt_ele
is
None
:
if
rt_ele
is
None
:
continue
continue
rt_ele
=
json
.
loads
(
rt_ele
)
rt_ele
=
json
.
loads
(
rt_ele
)
if
now_ts
-
rt_ele
[
"ts"
]
<=
REAL_EXP_TIME
:
if
now_ts
-
rt_ele
[
"ts"
]
<=
REAL_EXP_TIME
:
d_rt_ele
[
rt_ele
[
"mtid"
]]
=
rt_ele
d_rt_ele
[
rt_ele
[
"mtid"
]]
=
rt_ele
except
Exception
as
e
:
except
Exception
as
e
:
log
.
error
(
f
"batch load real time electric error, mtids:{mtids}"
)
log
.
error
(
f
"batch load real time electric error, mtids:{mtids}"
)
log
.
exception
(
e
)
log
.
exception
(
e
)
return
d_rt_ele
return
d_rt_ele
...
@@ -592,22 +595,22 @@ async def batch_load_rt_ele_with_hr(mtids):
...
@@ -592,22 +595,22 @@ async def batch_load_rt_ele_with_hr(mtids):
db
=
SETTING
.
mysql_db
db
=
SETTING
.
mysql_db
keys
=
[
f
"real_time:electric:{db}:{mtid}"
for
mtid
in
mtids
]
keys
=
[
f
"real_time:electric:{db}:{mtid}"
for
mtid
in
mtids
]
key_hrs
=
[
f
"real_time:electric_hr:{db}:{mtid}"
for
mtid
in
mtids
]
key_hrs
=
[
f
"real_time:electric_hr:{db}:{mtid}"
for
mtid
in
mtids
]
i_size
=
500
i_size
=
500
lst_rt_ele
,
lst_rt_ele_hr
=
[],
[]
lst_rt_ele
,
lst_rt_ele_hr
=
[],
[]
for
i
in
range
(
math
.
ceil
(
len
(
mtids
)
/
i_size
)):
for
i
in
range
(
math
.
ceil
(
len
(
mtids
)
/
i_size
)):
pipe
=
await
RedisUtils
()
.
client
.
pipeline
()
pipe
=
await
RedisUtils
()
.
client
.
pipeline
()
for
key
in
keys
[
i_size
*
i
:
i_size
*
(
i
+
1
)]:
for
key
in
keys
[
i_size
*
i
:
i_size
*
(
i
+
1
)]:
await
pipe
.
get
(
key
)
await
pipe
.
get
(
key
)
lst_rt_ele
+=
await
pipe
.
execute
()
lst_rt_ele
+=
await
pipe
.
execute
()
pipe
=
await
RedisUtils
()
.
client
.
pipeline
()
pipe
=
await
RedisUtils
()
.
client
.
pipeline
()
for
key
in
key_hrs
[
i_size
*
i
:
i_size
*
(
i
+
1
)]:
for
key
in
key_hrs
[
i_size
*
i
:
i_size
*
(
i
+
1
)]:
await
pipe
.
get
(
key
)
await
pipe
.
get
(
key
)
lst_rt_ele_hr
+=
await
pipe
.
execute
()
lst_rt_ele_hr
+=
await
pipe
.
execute
()
for
i
,
mtid
in
enumerate
(
mtids
):
for
i
,
mtid
in
enumerate
(
mtids
):
rt_ele
,
rt_ele_hr
=
lst_rt_ele
[
i
],
lst_rt_ele_hr
[
i
]
rt_ele
,
rt_ele_hr
=
lst_rt_ele
[
i
],
lst_rt_ele_hr
[
i
]
if
rt_ele
and
rt_ele_hr
:
if
rt_ele
and
rt_ele_hr
:
...
@@ -615,36 +618,36 @@ async def batch_load_rt_ele_with_hr(mtids):
...
@@ -615,36 +618,36 @@ async def batch_load_rt_ele_with_hr(mtids):
if
rt_ele
[
"mtid"
]
!=
mtid
or
rt_ele_hr
[
"mtid"
]
!=
mtid
:
if
rt_ele
[
"mtid"
]
!=
mtid
or
rt_ele_hr
[
"mtid"
]
!=
mtid
:
log
.
error
(
f
"batch_load_rt_ele error, mtid:{mtid}"
)
log
.
error
(
f
"batch_load_rt_ele error, mtid:{mtid}"
)
continue
continue
if
now_ts
-
rt_ele
[
"ts"
]
<=
REAL_EXP_TIME
:
if
now_ts
-
rt_ele
[
"ts"
]
<=
REAL_EXP_TIME
:
if
now_ts
-
rt_ele_hr
[
"ts"
]
<=
REAL_EXP_TIME
:
if
now_ts
-
rt_ele_hr
[
"ts"
]
<=
REAL_EXP_TIME
:
for
k
in
rt_ele_hr
.
keys
():
for
k
in
rt_ele_hr
.
keys
():
if
k
not
in
rt_ele
.
keys
():
if
k
not
in
rt_ele
.
keys
():
rt_ele
[
k
]
=
rt_ele_hr
[
k
]
rt_ele
[
k
]
=
rt_ele_hr
[
k
]
d_rt_ele
[
mtid
]
=
rt_ele
d_rt_ele
[
mtid
]
=
rt_ele
elif
rt_ele
:
elif
rt_ele
:
rt_ele
=
json
.
loads
(
rt_ele
)
rt_ele
=
json
.
loads
(
rt_ele
)
if
rt_ele
[
"mtid"
]
!=
mtid
:
if
rt_ele
[
"mtid"
]
!=
mtid
:
log
.
error
(
f
"load_rt_ele error, mtid:{mtid}"
)
log
.
error
(
f
"load_rt_ele error, mtid:{mtid}"
)
continue
continue
if
now_ts
-
rt_ele
[
"ts"
]
<=
REAL_EXP_TIME
:
if
now_ts
-
rt_ele
[
"ts"
]
<=
REAL_EXP_TIME
:
d_rt_ele
[
mtid
]
=
rt_ele
d_rt_ele
[
mtid
]
=
rt_ele
elif
rt_ele_hr
:
elif
rt_ele_hr
:
rt_ele_hr
=
json
.
loads
(
rt_ele_hr
)
rt_ele_hr
=
json
.
loads
(
rt_ele_hr
)
if
rt_ele_hr
[
"mtid"
]
!=
mtid
:
if
rt_ele_hr
[
"mtid"
]
!=
mtid
:
log
.
error
(
f
"load_rt_ele_hr error, mtid:{mtid}"
)
log
.
error
(
f
"load_rt_ele_hr error, mtid:{mtid}"
)
continue
continue
if
now_ts
-
rt_ele_hr
[
"ts"
]
<=
REAL_EXP_TIME
:
if
now_ts
-
rt_ele_hr
[
"ts"
]
<=
REAL_EXP_TIME
:
d_rt_ele
[
mtid
]
=
rt_ele_hr
d_rt_ele
[
mtid
]
=
rt_ele_hr
except
Exception
as
e
:
except
Exception
as
e
:
log
.
error
(
f
"batch load real time electric error, mtids:{mtids}"
)
log
.
error
(
f
"batch load real time electric error, mtids:{mtids}"
)
log
.
exception
(
e
)
log
.
exception
(
e
)
return
d_rt_ele
return
d_rt_ele
...
...
unify_api/modules/electric/views/electric.py
View file @
4c7a3d80
...
@@ -53,15 +53,15 @@ async def post_elec_history(req, body: PageRequest) -> ElecHistoryResponse:
...
@@ -53,15 +53,15 @@ async def post_elec_history(req, body: PageRequest) -> ElecHistoryResponse:
except
:
except
:
log
.
error
(
"param error, ranges is NULL"
)
log
.
error
(
"param error, ranges is NULL"
)
raise
ParamException
(
message
=
"param error, ranges is NULL"
)
raise
ParamException
(
message
=
"param error, ranges is NULL"
)
try
:
try
:
intervel
,
slots
=
time_format
.
time_pick_transf
(
date_start
,
date_end
)
intervel
,
slots
=
time_format
.
time_pick_transf
(
date_start
,
date_end
)
except
:
except
:
log
.
error
(
"param error, date format error"
)
log
.
error
(
"param error, date format error"
)
raise
ParamException
(
message
=
"param error, date format error"
)
raise
ParamException
(
message
=
"param error, date format error"
)
point_id
=
filed_value_from_list
(
body
.
filter
.
equals
,
"point_id"
)
point_id
=
filed_value_from_list
(
body
.
filter
.
equals
,
"point_id"
)
if
point_id
<=
0
or
not
point_id
:
if
point_id
<=
0
or
not
point_id
:
log
.
warning
(
"param exception, equals is NULL, no point_id"
)
log
.
warning
(
"param exception, equals is NULL, no point_id"
)
raise
ParamException
(
raise
ParamException
(
...
@@ -162,12 +162,12 @@ async def post_elec_current(req, body: PageRequest) -> ElecCurrentResponse:
...
@@ -162,12 +162,12 @@ async def post_elec_current(req, body: PageRequest) -> ElecCurrentResponse:
for
k
,
v
in
res
.
items
():
for
k
,
v
in
res
.
items
():
if
isinstance
(
v
,
(
str
,
int
)):
if
isinstance
(
v
,
(
str
,
int
)):
continue
continue
res
[
k
]
=
add_random_change
(
v
)
res
[
k
]
=
add_random_change
(
v
)
except
Exception
as
e
:
except
Exception
as
e
:
log
.
error
(
f
"post_elec_current service error:{str(e)}"
)
log
.
error
(
f
"post_elec_current service error:{str(e)}"
)
raise
BusinessException
(
message
=
f
"{str(e)}"
)
raise
BusinessException
(
message
=
f
"{str(e)}"
)
return
ElecCurrentResponse
(
real_time
=
time_str
,
return
ElecCurrentResponse
(
real_time
=
time_str
,
**
{
k
:
v
for
k
,
v
in
res
.
items
()
**
{
k
:
v
for
k
,
v
in
res
.
items
()
if
k
in
[
field
.
name
for
field
in
if
k
in
[
field
.
name
for
field
in
...
@@ -181,7 +181,7 @@ async def post_elec_index(req, body: PageRequest) -> ElecIndexResponse:
...
@@ -181,7 +181,7 @@ async def post_elec_index(req, body: PageRequest) -> ElecIndexResponse:
cid
=
req
.
json
.
get
(
"cid"
)
cid
=
req
.
json
.
get
(
"cid"
)
# 1. 获取point_id
# 1. 获取point_id
point_id
=
filed_value_from_list
(
body
.
filter
.
equals
,
"point_id"
)
point_id
=
filed_value_from_list
(
body
.
filter
.
equals
,
"point_id"
)
if
not
point_id
or
point_id
<=
0
:
if
not
point_id
or
point_id
<=
0
:
msg
=
"param exception, equals is NULL, no point_id"
msg
=
"param exception, equals is NULL, no point_id"
log
.
warning
(
msg
)
log
.
warning
(
msg
)
...
@@ -208,20 +208,20 @@ async def post_qual_history(req, body: PageRequest) -> QualHistoryResponse:
...
@@ -208,20 +208,20 @@ async def post_qual_history(req, body: PageRequest) -> QualHistoryResponse:
except
:
except
:
log
.
error
(
"param error, ranges is NULL"
)
log
.
error
(
"param error, ranges is NULL"
)
raise
ParamException
(
message
=
"param error, ranges is NULL"
)
raise
ParamException
(
message
=
"param error, ranges is NULL"
)
try
:
try
:
intervel
,
slots
=
time_format
.
time_pick_transf
(
date_start
,
date_end
)
intervel
,
slots
=
time_format
.
time_pick_transf
(
date_start
,
date_end
)
except
:
except
:
log
.
error
(
"param error, date format error"
)
log
.
error
(
"param error, date format error"
)
raise
ParamException
(
message
=
"param error, date format error"
)
raise
ParamException
(
message
=
"param error, date format error"
)
point_id
=
filed_value_from_list
(
body
.
filter
.
equals
,
"point_id"
)
point_id
=
filed_value_from_list
(
body
.
filter
.
equals
,
"point_id"
)
if
not
point_id
or
point_id
<=
0
:
if
not
point_id
or
point_id
<=
0
:
msg
=
"param exception, equals is NULL, no point_id"
msg
=
"param exception, equals is NULL, no point_id"
log
.
warning
(
msg
)
log
.
warning
(
msg
)
raise
ParamException
(
message
=
msg
)
raise
ParamException
(
message
=
msg
)
return
await
qual_history_service
(
date_start
,
date_end
,
intervel
,
slots
,
return
await
qual_history_service
(
date_start
,
date_end
,
intervel
,
slots
,
point_id
)
point_id
)
...
@@ -280,7 +280,7 @@ async def qual_history_service(start, end, intervel, slots, pid):
...
@@ -280,7 +280,7 @@ async def qual_history_service(start, end, intervel, slots, pid):
else
:
else
:
for
stats_item
in
stats_items
:
for
stats_item
in
stats_items
:
elec_data
[
stats_item
]
.
append
(
""
)
elec_data
[
stats_item
]
.
append
(
""
)
voltage_dev
=
VoltageDev
(
voltage_dev
=
VoltageDev
(
**
{
**
{
k
.
rsplit
(
"_"
,
1
)[
0
]:
v
k
.
rsplit
(
"_"
,
1
)[
0
]:
v
...
@@ -343,7 +343,7 @@ async def qual_history_service(start, end, intervel, slots, pid):
...
@@ -343,7 +343,7 @@ async def qual_history_service(start, end, intervel, slots, pid):
):
):
sdu_i
=
"ic"
sdu_i
=
"ic"
sdu_u
=
"uc"
sdu_u
=
"uc"
return
QualHistoryResponse
(
return
QualHistoryResponse
(
ctnum
=
ctnum
,
ctnum
=
ctnum
,
voltage_dev
=
voltage_dev
,
voltage_dev
=
voltage_dev
,
...
@@ -367,40 +367,40 @@ async def post_qual_current(req, body: PageRequest) -> QualCurrentResponse:
...
@@ -367,40 +367,40 @@ async def post_qual_current(req, body: PageRequest) -> QualCurrentResponse:
except
Exception
as
e
:
except
Exception
as
e
:
log
.
warning
(
f
"param exception, equals is NULL, no pid, e:{e}"
)
log
.
warning
(
f
"param exception, equals is NULL, no pid, e:{e}"
)
raise
ParamException
(
message
=
"param exception, equals is NULL, no pid"
)
raise
ParamException
(
message
=
"param exception, equals is NULL, no pid"
)
if
point_id
<=
0
or
not
point_id
or
cid
<=
0
:
if
point_id
<=
0
or
not
point_id
or
cid
<=
0
:
log
.
warning
(
"param exception, equals is NULL, no point_id"
)
log
.
warning
(
"param exception, equals is NULL, no point_id"
)
raise
ParamException
(
message
=
"param exception, equals is NULL, no pid"
)
raise
ParamException
(
message
=
"param exception, equals is NULL, no pid"
)
try
:
try
:
time_str
,
d_rt_ele
=
await
elec_current_service
(
point_id
)
time_str
,
d_rt_ele
=
await
elec_current_service
(
point_id
)
if
d_rt_ele
is
None
:
if
d_rt_ele
is
None
:
d_rt_ele
=
{}
d_rt_ele
=
{}
# 加些随机变化(防止数据一直不变化)
# 加些随机变化(防止数据一直不变化)
for
k
,
v
in
d_rt_ele
.
items
():
for
k
,
v
in
d_rt_ele
.
items
():
if
isinstance
(
v
,
(
str
,
int
)):
if
isinstance
(
v
,
(
str
,
int
)):
continue
continue
d_rt_ele
[
k
]
=
add_random_change
(
v
)
d_rt_ele
[
k
]
=
add_random_change
(
v
)
except
Exception
as
e
:
except
Exception
as
e
:
log
.
error
(
f
"post_qual_current service error:{str(e)}"
)
log
.
error
(
f
"post_qual_current service error:{str(e)}"
)
raise
BusinessException
(
message
=
f
"{str(e)}"
)
raise
BusinessException
(
message
=
f
"{str(e)}"
)
d_vol_harm
,
d_cur_harm
=
{},
{}
d_vol_harm
,
d_cur_harm
=
{},
{}
for
k
in
[
field
.
name
for
field
in
fields
(
VoltageHarmonicRate
)]:
for
k
in
[
field
.
name
for
field
in
fields
(
VoltageHarmonicRate
)]:
d_vol_harm
[
k
]
=
d_rt_ele
.
get
(
k
)
or
""
d_vol_harm
[
k
]
=
d_rt_ele
.
get
(
k
)
or
""
voltage_harmonic
=
VoltageHarmonicRate
(
**
d_vol_harm
)
voltage_harmonic
=
VoltageHarmonicRate
(
**
d_vol_harm
)
for
k
in
[
field
.
name
for
field
in
fields
(
CurrentHarmonicRate
)]:
for
k
in
[
field
.
name
for
field
in
fields
(
CurrentHarmonicRate
)]:
d_cur_harm
[
k
]
=
d_rt_ele
.
get
(
k
)
or
""
d_cur_harm
[
k
]
=
d_rt_ele
.
get
(
k
)
or
""
current_harmonic
=
CurrentHarmonicRate
(
**
d_cur_harm
)
current_harmonic
=
CurrentHarmonicRate
(
**
d_cur_harm
)
health_index
=
await
health_score
.
load_health_index
(
cid
,
point_id
)
health_index
=
await
health_score
.
load_health_index
(
cid
,
point_id
)
ret_items
=
[
"ua_dev"
,
"ub_dev"
,
"uc_dev"
,
"uab_dev"
,
"ucb_dev"
,
ret_items
=
[
"ua_dev"
,
"ub_dev"
,
"uc_dev"
,
"uab_dev"
,
"ucb_dev"
,
"freq_dev"
,
"ubl"
,
"ibl"
,
"sdu_i"
,
"sdu_u"
]
"freq_dev"
,
"ubl"
,
"ibl"
,
"sdu_i"
,
"sdu_u"
]
return
QualCurrentResponse
(
return
QualCurrentResponse
(
ctnum
=
d_rt_ele
[
"ctnum"
]
,
ctnum
=
d_rt_ele
.
get
(
"ctnum"
)
or
3
,
real_time
=
time_str
,
real_time
=
time_str
,
health_index
=
health_index
,
health_index
=
health_index
,
voltage_harmonic
=
voltage_harmonic
,
voltage_harmonic
=
voltage_harmonic
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment