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
2e78d4a7
Commit
2e78d4a7
authored
Apr 21, 2023
by
lcn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修复Bug
parent
313d2526
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
106 additions
and
84 deletions
+106
-84
electric_service.py
unify_api/modules/electric/service/electric_service.py
+106
-84
No files found.
unify_api/modules/electric/service/electric_service.py
View file @
2e78d4a7
...
...
@@ -212,7 +212,8 @@ async def elec_card_level_service(point_list):
# point_mid = await batch_get_wiring_type(point_list)
# # 3. 获取redis数据
# res_redis = await elec_current_data(point_mid)
mtids
=
[
monitor
[
"mtid"
]
for
monitor
in
monitor_point_list
if
monitor
[
"mtid"
]]
mtids
=
[
monitor
[
"mtid"
]
for
monitor
in
monitor_point_list
if
monitor
[
"mtid"
]]
cid
=
monitor_point_list
[
0
][
'cid'
]
if
len
(
monitor_point_list
)
>
0
else
0
results
=
await
elec_current_data_new15
(
mtids
,
cid
)
# 4. 返回数据
...
...
@@ -286,7 +287,7 @@ async def elec_card_level_service(point_list):
"ub_dev"
:
""
,
"uc_dev"
:
""
,
}
ret_data
[
m_type
]
.
append
(
res_dic
)
return
EclResp
(
inline
=
ret_data
[
"inline"
],
...
...
@@ -326,15 +327,15 @@ async def qual_current_level_service(point_list):
# 初始化返回dic
if
res
.
get
(
mtid
):
time_str
=
res
[
mtid
][
"ts"
][:
-
4
]
fdia
=
round_2
(
res
[
mtid
]
.
get
(
"fdia"
))
fdib
=
round_2
(
res
[
mtid
]
.
get
(
"fdib"
))
fdic
=
round_2
(
res
[
mtid
]
.
get
(
"fdic"
))
thdia
=
round_4
(
res
[
mtid
]
.
get
(
"thdia"
))
thdib
=
round_4
(
res
[
mtid
]
.
get
(
"thdib"
))
thdic
=
round_4
(
res
[
mtid
]
.
get
(
"thdic"
))
res_dic
=
{
"name"
:
m_name
,
"point_id"
:
point_id
,
...
...
@@ -344,7 +345,7 @@ async def qual_current_level_service(point_list):
"thdia"
:
thdia
,
"thdib"
:
thdib
,
"thdic"
:
thdic
,
"thdua"
:
round_4
(
res
[
mtid
]
.
get
(
"thdua"
)),
"thdub"
:
round_4
(
res
[
mtid
]
.
get
(
"thdub"
)),
"thduc"
:
round_4
(
res
[
mtid
]
.
get
(
"thduc"
)),
...
...
@@ -385,7 +386,7 @@ async def qual_current_level_service(point_list):
"thdia"
:
""
,
"thdib"
:
""
,
"thdic"
:
""
,
"thdua"
:
""
,
"thdub"
:
""
,
"thduc"
:
""
,
...
...
@@ -409,7 +410,7 @@ async def qual_current_level_service(point_list):
"thdib_virtual"
:
""
,
"thdic_virtual"
:
""
,
}
ret_data
[
m_type
]
.
append
(
res_dic
)
return
QclResp
(
inline
=
ret_data
[
"inline"
],
...
...
@@ -562,14 +563,14 @@ async def elec_index_service(cid, point_id, date_start, date_end):
"freq_dev_min"
,
"freq_dev_max"
,
]
query_body
=
EsQuery
.
aggr_index
(
page_request
,
stats_items
=
common_items
+
elec_qual_items
)
async
with
EsUtil
()
as
es
:
es_results
=
await
es
.
search_origin
(
body
=
query_body
,
index
=
constants
.
POINT_15MIN_INDEX
)
aggregations
=
es_results
.
get
(
"aggregations"
,
{})
# 常规参数统计
common_indexes
=
[]
...
...
@@ -593,7 +594,7 @@ async def elec_index_service(cid, point_id, date_start, date_end):
else
:
max_value
=
""
max_value_time
=
""
# 最小值
min_info
=
aggregations
.
get
(
f
"{item}_min_min"
,
{})
hits
=
min_info
.
get
(
"hits"
,
{})
.
get
(
"hits"
)
...
...
@@ -609,10 +610,10 @@ async def elec_index_service(cid, point_id, date_start, date_end):
else
:
min_value
=
""
min_value_time
=
""
avg
=
aggregations
.
get
(
f
"{item}_mean_avg"
,
{})
.
get
(
"value"
)
avg
=
round
(
avg
,
2
)
if
avg
is
not
None
else
""
elec_index
=
ElecIndex
(
stats_index
=
item
,
max
=
max_value
,
...
...
@@ -622,7 +623,7 @@ async def elec_index_service(cid, point_id, date_start, date_end):
avg
=
avg
,
)
common_indexes
.
append
(
elec_index
)
# 电能质量统计
elec_qual_indexes
=
[]
_elec_qual_items
=
{
i
.
rsplit
(
"_"
,
1
)[
0
]
for
i
in
elec_qual_items
}
...
...
@@ -641,7 +642,7 @@ async def elec_index_service(cid, point_id, date_start, date_end):
else
:
max_value
=
""
max_value_time
=
""
# 最小值
min_info
=
aggregations
.
get
(
f
"{item}_min_min"
,
{})
hits
=
min_info
.
get
(
"hits"
,
{})
.
get
(
"hits"
)
...
...
@@ -656,10 +657,10 @@ async def elec_index_service(cid, point_id, date_start, date_end):
else
:
min_value
=
""
min_value_time
=
""
avg
=
aggregations
.
get
(
f
"{item}_mean_avg"
,
{})
.
get
(
"value"
)
avg
=
avg
if
avg
is
not
None
else
""
elec_index
=
ElecIndex
(
stats_index
=
item
,
max
=
max_value
,
...
...
@@ -669,7 +670,7 @@ async def elec_index_service(cid, point_id, date_start, date_end):
avg
=
avg
,
)
elec_qual_indexes
.
append
(
elec_index
)
if
cid
:
# 小程序需要这漏电流和温度
residual_current_map
=
await
location_stats_statics
(
...
...
@@ -698,7 +699,7 @@ async def elec_index_service(cid, point_id, date_start, date_end):
else
None
,
)
)
temp_map
=
await
location_stats_statics
(
cid
,
point_id
,
start_tt
,
end_tt
,
_type
=
"temperature"
)
...
...
@@ -773,83 +774,103 @@ async def elec_index_service_new15(cid, point_id, start, end):
"ua_dev_mean"
,
"ua_dev_min"
,
"ua_dev_max"
,
"freq_dev_mean"
,
"freq_dev_min"
,
"freq_dev_max"
]
datas
=
await
get_electric_datas_dao
(
table_name
,
point_id
,
start
,
end
)
if
not
datas
:
return
ElecIndexResponse
(
ctnum
=
ctnum
,
common_indexes
=
[],
elec_qual_indexes
=
[]
)
#
if not datas:
#
return ElecIndexResponse(
#
ctnum=ctnum, common_indexes=[],
#
elec_qual_indexes=[]
#
)
df
=
pd
.
DataFrame
(
list
(
datas
))
# 常规参数统计
common_indexes
=
[]
_common_items
=
{
i
.
rsplit
(
"_"
,
1
)[
0
]
for
i
in
common_items
}
for
item
in
_common_items
:
item_name
=
item
.
rsplit
(
"_"
,
1
)[
0
]
max_item_name
=
f
"{item}_max"
max_value
=
df
[
max_item_name
]
.
max
()
if
not
pd
.
isna
(
max_value
):
max_datas
=
df
.
loc
[
df
[
max_item_name
]
.
idxmax
()]
.
to_dict
()
max_time
=
max_datas
.
get
(
f
"{item_name}_max_time"
)
max_time
=
''
if
pd
.
isnull
(
max_time
)
else
str
(
max_time
)
else
:
max_value
,
max_time
=
""
,
""
min_item_name
=
f
"{item}_min"
min_value
=
df
[
min_item_name
]
.
min
()
if
not
pd
.
isna
(
min_value
):
min_datas
=
df
.
loc
[
df
[
min_item_name
]
.
idxmin
()]
.
to_dict
()
min_time
=
min_datas
.
get
(
f
"{item_name}_min_time"
)
min_time
=
''
if
pd
.
isnull
(
min_time
)
else
str
(
min_time
)
else
:
min_value
,
min_time
=
""
,
""
mean_item_name
=
f
"{item}_mean"
avg_value
=
df
[
mean_item_name
]
.
mean
()
if
not
pd
.
isna
(
avg_value
):
avg_value
=
round
(
avg_value
,
2
)
if
avg_value
else
""
if
datas
:
max_item_name
=
f
"{item}_max"
max_value
=
df
[
max_item_name
]
.
max
()
if
not
pd
.
isna
(
max_value
):
max_datas
=
df
.
loc
[
df
[
max_item_name
]
.
idxmax
()]
.
to_dict
()
max_time
=
max_datas
.
get
(
f
"{item_name}_max_time"
)
max_time
=
''
if
pd
.
isnull
(
max_time
)
else
str
(
max_time
)
else
:
max_value
,
max_time
=
""
,
""
min_item_name
=
f
"{item}_min"
min_value
=
df
[
min_item_name
]
.
min
()
if
not
pd
.
isna
(
min_value
):
min_datas
=
df
.
loc
[
df
[
min_item_name
]
.
idxmin
()]
.
to_dict
()
min_time
=
min_datas
.
get
(
f
"{item_name}_min_time"
)
min_time
=
''
if
pd
.
isnull
(
min_time
)
else
str
(
min_time
)
else
:
min_value
,
min_time
=
""
,
""
mean_item_name
=
f
"{item}_mean"
avg_value
=
df
[
mean_item_name
]
.
mean
()
if
not
pd
.
isna
(
avg_value
):
avg_value
=
round
(
avg_value
,
2
)
if
avg_value
else
""
else
:
avg_value
=
""
elec_index
=
ElecIndex
(
stats_index
=
item_name
,
max
=
max_value
,
max_time
=
max_time
or
""
,
min
=
min_value
,
min_time
=
min_time
or
""
,
avg
=
avg_value
,
)
else
:
avg_value
=
""
elec_index
=
ElecIndex
(
stats_index
=
item_name
,
max
=
max_value
,
max_time
=
max_time
or
""
,
min
=
min_value
,
min_time
=
min_time
or
""
,
avg
=
avg_value
,
)
elec_index
=
ElecIndex
(
stats_index
=
item_name
,
max
=
""
,
max_time
=
""
,
min
=
""
,
min_time
=
""
,
avg
=
""
,
)
common_indexes
.
append
(
elec_index
)
# 电能质量统计
elec_qual_indexes
=
[]
_elec_qual_items
=
{
i
.
rsplit
(
"_"
,
1
)[
0
]
for
i
in
elec_qual_items
}
for
item
in
_elec_qual_items
:
item_name
=
item
.
rsplit
(
"_"
,
1
)[
0
]
max_item_name
=
f
"{item}_max"
max_value
=
df
[
max_item_name
]
.
max
()
if
not
pd
.
isna
(
max_value
):
max_datas
=
df
.
loc
[
df
[
max_item_name
]
.
idxmax
()]
.
to_dict
()
max_time
=
max_datas
.
get
(
f
"{item_name}_max_time"
)
max_time
=
''
if
pd
.
isnull
(
max_time
)
else
str
(
max_time
)
else
:
max_value
,
max_time
=
""
,
""
min_item_name
=
f
"{item}_min"
min_value
=
df
[
min_item_name
]
.
min
()
if
not
pd
.
isna
(
min_value
):
min_datas
=
df
.
loc
[
df
[
min_item_name
]
.
idxmin
()]
.
to_dict
()
min_time
=
min_datas
.
get
(
f
"{item_name}_min_time"
)
min_time
=
''
if
pd
.
isnull
(
min_time
)
else
str
(
min_time
)
else
:
min_value
,
min_time
=
""
,
""
mean_item_name
=
f
"{item}_mean"
avg_value
=
df
[
mean_item_name
]
.
mean
()
if
not
pd
.
isna
(
avg_value
):
avg_value
=
round
(
avg_value
,
2
)
if
avg_value
else
""
if
datas
:
max_item_name
=
f
"{item}_max"
max_value
=
df
[
max_item_name
]
.
max
()
if
not
pd
.
isna
(
max_value
):
max_datas
=
df
.
loc
[
df
[
max_item_name
]
.
idxmax
()]
.
to_dict
()
max_time
=
max_datas
.
get
(
f
"{item_name}_max_time"
)
max_time
=
''
if
pd
.
isnull
(
max_time
)
else
str
(
max_time
)
else
:
max_value
,
max_time
=
""
,
""
min_item_name
=
f
"{item}_min"
min_value
=
df
[
min_item_name
]
.
min
()
if
not
pd
.
isna
(
min_value
):
min_datas
=
df
.
loc
[
df
[
min_item_name
]
.
idxmin
()]
.
to_dict
()
min_time
=
min_datas
.
get
(
f
"{item_name}_min_time"
)
min_time
=
''
if
pd
.
isnull
(
min_time
)
else
str
(
min_time
)
else
:
min_value
,
min_time
=
""
,
""
mean_item_name
=
f
"{item}_mean"
avg_value
=
df
[
mean_item_name
]
.
mean
()
if
not
pd
.
isna
(
avg_value
):
avg_value
=
round
(
avg_value
,
2
)
if
avg_value
else
""
else
:
avg_value
=
""
elec_index
=
ElecIndex
(
stats_index
=
item_name
,
max
=
max_value
,
max_time
=
max_time
,
min
=
min_value
,
min_time
=
min_time
,
avg
=
avg_value
,
)
else
:
avg_value
=
""
elec_index
=
ElecIndex
(
stats_index
=
item_name
,
max
=
max_value
,
max_time
=
max_time
,
min
=
min_value
,
min_time
=
min_time
,
avg
=
avg_value
,
)
elec_index
=
ElecIndex
(
stats_index
=
item_name
,
max
=
""
,
max_time
=
""
,
min
=
""
,
min_time
=
""
,
avg
=
""
,
)
elec_qual_indexes
.
append
(
elec_index
)
# 小程序需要这漏电流和温度
if
cid
:
...
...
@@ -877,6 +898,7 @@ async def elec_index_service_new15(cid, point_id, start, end):
elec_qual_indexes
=
elec_qual_indexes
)
async
def
elec_current_service_new15
(
point_id
):
# 获取mtid
meter_info
=
await
get_meter_by_point_new15
(
point_id
)
...
...
@@ -903,7 +925,7 @@ async def elec_current_service_new15(point_id):
time_str
=
str
(
res
[
"ts"
])[
0
:
19
]
else
:
time_str
=
time_format
.
get_datetime_str
(
0
)
return
time_str
,
res
return
time_str
,
res
def
get_sdu_i_and_u
(
res
,
ctnum
):
...
...
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