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
9d4a6d83
Commit
9d4a6d83
authored
Apr 25, 2023
by
wang.wenrong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix_shiduanu
parent
9f80a08f
Show whitespace changes
Inline
Side-by-side
Showing
16 changed files
with
488 additions
and
345 deletions
+488
-345
common_dao.py
unify_api/modules/common/dao/common_dao.py
+2
-2
health_score_dao.py
unify_api/modules/common/dao/health_score_dao.py
+23
-75
health_score.py
unify_api/modules/common/procedures/health_score.py
+12
-12
electric_util.py
unify_api/modules/electric/procedures/electric_util.py
+6
-15
IntergratePipe.py
unify_api/modules/shidianu/service/IntergratePipe.py
+0
-2
aircondAnalysis.py
unify_api/modules/shidianu/service/aircondAnalysis.py
+34
-20
componentStage.py
unify_api/modules/shidianu/service/componentStage.py
+66
-44
decomp_main.py
unify_api/modules/shidianu/service/decomp_main.py
+32
-8
electricProportion.py
unify_api/modules/shidianu/service/electricProportion.py
+153
-83
electroAnalysis.py
unify_api/modules/shidianu/service/electroAnalysis.py
+38
-20
heaterAnalysis.py
unify_api/modules/shidianu/service/heaterAnalysis.py
+38
-19
highPower.py
unify_api/modules/shidianu/service/highPower.py
+2
-3
open_data_service.py
unify_api/modules/shidianu/service/open_data_service.py
+4
-3
paramAnaly.py
unify_api/modules/shidianu/service/paramAnaly.py
+1
-1
pieceClassify.py
unify_api/modules/shidianu/service/pieceClassify.py
+28
-14
refrigAnalysis.py
unify_api/modules/shidianu/service/refrigAnalysis.py
+49
-24
No files found.
unify_api/modules/common/dao/common_dao.py
View file @
9d4a6d83
...
...
@@ -63,8 +63,8 @@ async def points_monitor_by_cid(cids):
async
def
mid_by_pid
(
pid
):
"""根据pid查询mid"""
sql
=
"select m
id from change_meter_record
where pid=
%
s "
\
"order by
start
_time desc limit 1 "
sql
=
"select m
tid from point
where pid=
%
s "
\
"order by
create
_time desc limit 1 "
async
with
MysqlUtil
()
as
conn
:
mid_dic
=
await
conn
.
fetchone
(
sql
,
args
=
(
pid
,))
return
mid_dic
...
...
unify_api/modules/common/dao/health_score_dao.py
View file @
9d4a6d83
...
...
@@ -30,78 +30,26 @@ async def get_mean_datas_dao(pids, words, start, end):
async
def
health_score_points_aggs
(
start
,
end
,
point_list
):
"""根据points分组, 再求平均值"""
# start_es = convert_es_str(start)
# end_es = convert_es_str(end)
# 所有报警类型
query_body
=
{
"query"
:
{
"bool"
:
{
"filter"
:
[
{
"terms"
:
{
"pid"
:
point_list
}
},
{
"range"
:
{
"quarter_time"
:
{
"gte"
:
start
,
"lte"
:
end
}
}
}
]
}
},
"size"
:
0
,
"aggs"
:
{
"points"
:
{
"terms"
:
{
"field"
:
"pid"
,
"size"
:
1000
},
"aggs"
:
{
"ua_mean_avg"
:
{
"avg"
:
{
"field"
:
"ua_mean"
}
},
"freq_mean_avg"
:
{
"avg"
:
{
"field"
:
"freq_mean"
}
},
"ubl_mean_avg"
:
{
"avg"
:
{
"field"
:
"ubl_mean"
}
},
"costtl_mean_avg"
:
{
"avg"
:
{
"field"
:
"costtl_mean"
}
},
"thdua_mean_avg"
:
{
"avg"
:
{
"field"
:
"thdua_mean"
}
},
"lf_mean_avg"
:
{
"avg"
:
{
"field"
:
"lf_mean"
}
},
"uab_mean_avg"
:
{
"avg"
:
{
"field"
:
"ua_mean"
}
}
}
}
}
}
log
.
info
(
"query_body={}"
.
format
(
query_body
))
async
with
EsUtil
()
as
es
:
es_result
=
await
es
.
search_origin
(
body
=
query_body
,
index
=
constants
.
POINT_15MIN_INDEX
)
return
es_result
[
"aggregations"
][
"points"
][
"buckets"
]
sql
=
f
"""
SELECT
pid,
avg( uab_mean ) uab_mean_avg,
avg( costtl_mean ) costtl_mean_avg,
avg( lf_mean ) lf_mean_avg,
avg( thduab_mean ) thduab_mean_avg,
avg( ubl_mean ) ubl_mean_avg,
avg( freq_mean ) freq_mean_avg,
avg( ua_mean ) ua_mean_avg
FROM
point_15min_electric
WHERE
create_time > "{start}"
AND create_time < "{end}"
AND pid in
%
s
GROUP BY
pid
"""
async
with
MysqlUtil
()
as
conn
:
datas
=
await
conn
.
fetchall
(
sql
,
args
=
(
tuple
(
point_list
),))
if
point_list
else
[]
return
datas
unify_api/modules/common/procedures/health_score.py
View file @
9d4a6d83
...
...
@@ -55,7 +55,7 @@ async def load_health_radar(cid, param_point_id=None):
es_health
=
await
health_score_points_aggs
(
start_time
,
end_time
,
inline_point_ids
+
point_ids
)
es_dic
=
{
i
[
"
key"
]:
i
for
i
in
es_health
}
es_dic
=
{
i
[
"
pid"
]:
i
for
i
in
es_health
if
es_health
}
# 统计所有点所有平均值
for
point_id
in
inline_point_ids
+
point_ids
:
ctnum
=
point_info_map
[
point_id
][
"ctnum"
]
...
...
@@ -71,7 +71,7 @@ async def load_health_radar(cid, param_point_id=None):
if
not
point_v
:
stats
[
point_id
][
item
]
=
None
else
:
stats
[
point_id
][
item
]
=
point_v
[
item
+
'_avg'
]
.
get
(
"value"
)
stats
[
point_id
][
item
]
=
point_v
[
item
+
'_avg'
]
'''
range = Range(field="quarter_time", start=start_time, end=end_time)
stats = {point_id: {} for point_id in inline_point_ids + point_ids}
...
...
@@ -109,17 +109,17 @@ async def load_health_radar(cid, param_point_id=None):
avg = aggregations.get("
%
s_avg"
%
item, {}).get("value")
stats[point_id][item] = avg
'''
# 获取所有poin_id和mid对应关系
# 获取所有poin_id和m
t
id对应关系
all_point_ids
=
inline_point_ids
+
point_ids
point_mid_map
=
{}
if
all_point_ids
:
sql
=
(
"SELECT pid, m
id FROM change_meter_record WHERE pid IN
%
s order by pid, start
_time asc"
"SELECT pid, m
tid FROM point WHERE pid IN
%
s order by pid, create
_time asc"
)
async
with
MysqlUtil
()
as
conn
:
change_meter_records
=
await
conn
.
fetchall
(
sql
,
args
=
(
tuple
(
all_point_ids
),))
point_mid_map
=
{
i
[
"pid"
]:
i
[
"m
id"
]
for
i
in
change_meter_records
if
i
[
"m
id"
]
is
not
None
i
[
"pid"
]:
i
[
"m
tid"
]
for
i
in
change_meter_records
if
i
[
"mt
id"
]
is
not
None
}
# 获取meter_param_record中的标准电压
...
...
@@ -127,9 +127,9 @@ async def load_health_radar(cid, param_point_id=None):
meter_param_map
=
{}
if
all_mids
:
async
with
MysqlUtil
()
as
conn
:
sql
=
"SELECT m
id, vc, voltage_side, ctnum FROM meter_param_record WHERE mid IN
%
s order by mid, start
_time asc"
sql
=
"SELECT m
tid, vc, voltage_side, ctnum FROM point WHERE mtid IN
%
s order by mtid, create
_time asc"
meter_param_records
=
await
conn
.
fetchall
(
sql
,
args
=
(
tuple
(
all_mids
),))
meter_param_map
=
{
i
[
"mid"
]:
i
for
i
in
meter_param_records
}
meter_param_map
=
{
i
[
"m
t
id"
]:
i
for
i
in
meter_param_records
}
log
.
info
(
f
"all_mids={all_mids}"
)
# 电压偏差评分
...
...
@@ -139,14 +139,14 @@ async def load_health_radar(cid, param_point_id=None):
if
ua_mean
is
None
:
continue
mid
=
point_mid_map
.
get
(
point_id
)
if
not
mid
:
m
t
id
=
point_mid_map
.
get
(
point_id
)
if
not
m
t
id
:
# pid没有mid,拆了
log
.
warning
(
f
"pid={point_id} m
id={m
id} mid无效"
)
log
.
warning
(
f
"pid={point_id} m
tid={mt
id} mid无效"
)
continue
meter_param
=
meter_param_map
.
get
(
mid
)
meter_param
=
meter_param_map
.
get
(
m
t
id
)
if
not
meter_param
:
log
.
warning
(
f
"pid={point_id} m
id={m
id} 没有表参数"
)
log
.
warning
(
f
"pid={point_id} m
tid={mt
id} 没有表参数"
)
continue
meter_vc
,
ctnum
=
meter_param
.
get
(
"vc"
),
meter_param
.
get
(
"ctnum"
)
or
3
if
meter_vc
:
...
...
unify_api/modules/electric/procedures/electric_util.py
View file @
9d4a6d83
...
...
@@ -45,25 +45,16 @@ async def batch_get_wiring_type(point_ids):
:return: ctnum, mid
"""
# 根据point_id去change_meter_record查询最新的mid
sql
=
"SELECT pid, m
id FROM change_meter_record
WHERE "
\
"pid in
%
s ORDER BY pid,
start
_time"
sql
=
"SELECT pid, m
tid, ctnum FROM point
WHERE "
\
"pid in
%
s ORDER BY pid,
create
_time"
async
with
MysqlUtil
()
as
conn
:
change_meter_records
=
await
conn
.
fetchall
(
sql
,
args
=
(
point_ids
,))
if
point_ids
else
[]
new_meter_id_map
=
{
i
[
"pid"
]:
i
[
"mid"
]
for
i
in
change_meter_records
}
change_meter_records
=
await
conn
.
fetchall
(
sql
,
args
=
(
point_ids
,))
if
point_ids
else
[]
newest_mids
=
[
i
for
i
in
new_meter_id_map
.
values
()
if
i
]
# 2. 根据mid去meter_param_record查最新ctnum
sql
=
"SELECT mid, ctnum FROM meter_param_record "
\
"WHERE mid in
%
s ORDER BY mid, start_time"
point_info_map
=
{
i
[
"pid"
]:
i
for
i
in
change_meter_records
if
i
.
get
(
"pid"
)}
async
with
MysqlUtil
()
as
conn
:
meter_param_records
=
await
conn
.
fetchall
(
sql
,
args
=
(
newest_mids
,))
if
newest_mids
else
[]
meter_param_map
=
{
i
[
"mid"
]:
i
[
"ctnum"
]
for
i
in
meter_param_records
}
point_info_map
=
defaultdict
(
dict
)
for
pid
,
mid
in
new_meter_id_map
.
items
():
point_info_map
[
pid
]
=
{
"mid"
:
mid
,
"ctnum"
:
meter_param_map
.
get
(
mid
)}
return
point_info_map
...
...
unify_api/modules/shidianu/service/IntergratePipe.py
View file @
9d4a6d83
...
...
@@ -7,7 +7,6 @@ import os
import
pandas
as
pd
import
matplotlib.pyplot
as
plt
plt
.
rcParams
[
'font.sans-serif'
]
=
[
'SimHei'
]
plt
.
rcParams
[
'axes.unicode_minus'
]
=
False
illegalConfig_hold
=
2500
...
...
@@ -100,4 +99,3 @@ def addLabels(sid="sid", aircondRunStages="", electroRunStages="",
x
=
[
each
.
split
(
" "
)[
1
][:
-
3
]
for
each
in
timeAll
]
plt
.
show
()
return
0
unify_api/modules/shidianu/service/aircondAnalysis.py
View file @
9d4a6d83
...
...
@@ -2,40 +2,54 @@ import time
def
findStart
(
timeaircond
=
"timeaircond"
,
timeaircond_last
=
""
,
ahead
=
0
):
timeaircond_last_stemp
=
int
(
time
.
mktime
(
time
.
strptime
(
timeaircond_last
,
"
%
Y-
%
m-
%
d
%
H:
%
M:
%
S"
)))
timeaircond_stemp
=
[
int
(
time
.
mktime
(
time
.
strptime
(
each_time
,
"
%
Y-
%
m-
%
d
%
H:
%
M:
%
S"
)))
for
each_time
in
timeaircond
]
timeaircond_last_stemp
=
int
(
time
.
mktime
(
time
.
strptime
(
timeaircond_last
,
"
%
Y-
%
m-
%
d
%
H:
%
M:
%
S"
)))
timeaircond_stemp
=
[
int
(
time
.
mktime
(
time
.
strptime
(
each_time
,
"
%
Y-
%
m-
%
d
%
H:
%
M:
%
S"
)))
for
each_time
in
timeaircond
]
if
ahead
<
len
(
timeaircond
)
-
1
:
time_substruct
=
[
1000000
if
timeaircond_stemp
[
each_timeaircond_stemp
]
-
timeaircond_last_stemp
<=
0
or
each_timeaircond_stemp
<
ahead
else
timeaircond_stemp
[
each_timeaircond_stemp
]
-
timeaircond_last_stemp
for
each_timeaircond_stemp
timeaircond_stemp
[
each_timeaircond_stemp
]
-
timeaircond_last_stemp
for
each_timeaircond_stemp
in
range
(
len
(
timeaircond_stemp
))]
else
:
time_substruct
=
[
1000000
if
timeaircond_last_stemp
-
timeaircond_stemp
[
time_substruct
=
[
1000000
if
timeaircond_last_stemp
-
timeaircond_stemp
[
each_timeaircond_stemp
]
<=
0
or
each_timeaircond_stemp
<
ahead
else
timeaircond_last_stemp
-
timeaircond_stemp
[
each_timeaircond_stemp
]
for
each_timeaircond_stemp
]
for
each_timeaircond_stemp
in
range
(
len
(
timeaircond_stemp
))]
index
=
time_substruct
.
index
(
min
(
time_substruct
))
return
index
def
aircondAnalysis
(
statesaircond
=
""
,
statesaircond_off
=
""
,
timeaircond
=
""
,
timeaircond_off
=
""
,
eachdata_pow
=
""
,
eachdata_cur
=
""
,
timer
=
""
):
timeaircond_off_chang
=
[
each
.
split
(
" "
)[
1
][:
-
3
]
.
split
(
":"
)
for
each
in
timeaircond_off
]
timeaircond_off_hour
=
[
each
[
0
]
for
each
in
timeaircond_off_chang
]
def
aircondAnalysis
(
statesaircond
=
""
,
statesaircond_off
=
""
,
timeaircond
=
""
,
timeaircond_off
=
""
,
eachdata_pow
=
""
,
eachdata_cur
=
""
,
timer
=
""
):
timeaircond_off_chang
=
[
each
.
split
(
" "
)[
1
][:
-
3
]
.
split
(
":"
)
for
each
in
timeaircond_off
]
timeaircond_off_hour
=
[
each
[
0
]
for
each
in
timeaircond_off_chang
]
aircondRunStages
=
[]
aircondRunStages
=
[]
aircondRunStages
.
append
(
timeaircond
[
0
])
for
each_off
in
range
(
1
,
len
(
timeaircond_off
)):
if
int
(
timeaircond_off_hour
[
-
1
])
-
int
(
timeaircond_off_hour
[
-
2
])
<=
2
and
each_off
==
len
(
timeaircond_off_hour
)
-
1
:
for
each_off
in
range
(
1
,
len
(
timeaircond_off
)):
if
int
(
timeaircond_off_hour
[
-
1
])
-
int
(
timeaircond_off_hour
[
-
2
])
<=
2
and
each_off
==
len
(
timeaircond_off_hour
)
-
1
:
aircondRunStages
.
append
(
timeaircond_off
[
each_off
])
if
int
(
timeaircond_off_hour
[
each_off
])
-
int
(
timeaircond_off_hour
[
each_off
-
1
])
<=
2
:
if
int
(
timeaircond_off_hour
[
each_off
])
-
int
(
timeaircond_off_hour
[
each_off
-
1
])
<=
2
:
continue
else
:
if
each_off
<
len
(
timeaircond
)
-
1
:
aircondRunStages
.
append
(
timeaircond_off
[
each_off
-
1
])
findStart1
=
findStart
(
timeaircond
=
timeaircond
,
timeaircond_last
=
timeaircond_off
[
each_off
-
1
],
ahead
=
each_off
)
if
each_off
<
len
(
timeaircond
)
-
1
:
aircondRunStages
.
append
(
timeaircond_off
[
each_off
-
1
])
findStart1
=
findStart
(
timeaircond
=
timeaircond
,
timeaircond_last
=
timeaircond_off
[
each_off
-
1
],
ahead
=
each_off
)
aircondRunStages
.
append
(
timeaircond
[
findStart1
])
else
:
aircondRunStages
.
append
(
timeaircond_off
[
each_off
])
...
...
unify_api/modules/shidianu/service/componentStage.py
View file @
9d4a6d83
import
time
def
componentStage
(
aircondRunStages
=
""
,
electroRunStages
=
""
,
heaterRunStages
=
""
,
refrigRunStages
=
""
):
def
componentStage
(
aircondRunStages
=
""
,
electroRunStages
=
""
,
heaterRunStages
=
""
,
refrigRunStages
=
""
):
stageComponent
=
[]
stampDict
=
{}
if
len
(
aircondRunStages
)
>
1
:
aircondRunStages_stemp
=
[
int
(
time
.
mktime
(
time
.
strptime
(
each
,
"
%
Y-
%
m-
%
d
%
H:
%
M:
%
S"
)))
for
each
in
aircondRunStages_stemp
=
[
int
(
time
.
mktime
(
time
.
strptime
(
each
,
"
%
Y-
%
m-
%
d
%
H:
%
M:
%
S"
)))
for
each
in
aircondRunStages
]
for
each_i
in
range
(
len
(
aircondRunStages_stemp
)):
if
each_i
%
2
==
0
:
stampDict
[
aircondRunStages_stemp
[
each_i
]]
=
"开启空调"
if
each_i
%
2
==
0
:
stampDict
[
aircondRunStages_stemp
[
each_i
]]
=
"开启空调"
else
:
stampDict
[
aircondRunStages_stemp
[
each_i
]]
=
"关闭空调"
stampDict
[
aircondRunStages_stemp
[
each_i
]]
=
"关闭空调"
if
len
(
electroRunStages
)
>
1
:
electroRunStages_stemp
=
[
int
(
time
.
mktime
(
time
.
strptime
(
each
,
"
%
Y-
%
m-
%
d
%
H:
%
M:
%
S"
)))
for
each
in
electroRunStages_stemp
=
[
int
(
time
.
mktime
(
time
.
strptime
(
each
,
"
%
Y-
%
m-
%
d
%
H:
%
M:
%
S"
)))
for
each
in
electroRunStages
]
for
each_i
in
range
(
len
(
electroRunStages_stemp
)):
if
each_i
%
2
==
0
:
stampDict
[
electroRunStages_stemp
[
each_i
]]
=
"开启电磁炉"
if
each_i
%
2
==
0
:
stampDict
[
electroRunStages_stemp
[
each_i
]]
=
"开启电磁炉"
else
:
stampDict
[
electroRunStages_stemp
[
each_i
]]
=
"关闭电磁炉"
stampDict
[
electroRunStages_stemp
[
each_i
]]
=
"关闭电磁炉"
if
len
(
heaterRunStages
)
>
1
:
heaterRunStages_stemp
=
[
int
(
time
.
mktime
(
time
.
strptime
(
each
,
"
%
Y-
%
m-
%
d
%
H:
%
M:
%
S"
)))
for
each
in
heaterRunStages
]
heaterRunStages_stemp
=
[
int
(
time
.
mktime
(
time
.
strptime
(
each
,
"
%
Y-
%
m-
%
d
%
H:
%
M:
%
S"
)))
for
each
in
heaterRunStages
]
for
each_i
in
range
(
len
(
heaterRunStages_stemp
)):
if
each_i
%
2
==
0
:
stampDict
[
heaterRunStages_stemp
[
each_i
]]
=
"开启热水器"
if
each_i
%
2
==
0
:
stampDict
[
heaterRunStages_stemp
[
each_i
]]
=
"开启热水器"
else
:
stampDict
[
heaterRunStages_stemp
[
each_i
]]
=
"关闭热水器"
stampDict
[
heaterRunStages_stemp
[
each_i
]]
=
"关闭热水器"
if
len
(
refrigRunStages
)
>
1
:
refrigRunStages_stemp
=
[
int
(
time
.
mktime
(
time
.
strptime
(
each
,
"
%
Y-
%
m-
%
d
%
H:
%
M:
%
S"
)))
for
each
in
refrigRunStages
]
refrigRunStages_stemp
=
[
int
(
time
.
mktime
(
time
.
strptime
(
each
,
"
%
Y-
%
m-
%
d
%
H:
%
M:
%
S"
)))
for
each
in
refrigRunStages
]
for
each_i
in
range
(
len
(
refrigRunStages_stemp
)):
if
each_i
%
2
==
0
:
stampDict
[
refrigRunStages_stemp
[
each_i
]]
=
"开启电冰箱"
if
each_i
%
2
==
0
:
stampDict
[
refrigRunStages_stemp
[
each_i
]]
=
"开启电冰箱"
else
:
stampDict
[
refrigRunStages_stemp
[
each_i
]]
=
"关闭电冰箱"
stampDict
[
refrigRunStages_stemp
[
each_i
]]
=
"关闭电冰箱"
stampDict
=
sorted
(
stampDict
.
items
(),
key
=
lambda
d
:
d
[
0
])
timeOrder
=
[
each
[
0
]
for
each
in
stampDict
]
actionOrder
=
[
each
[
1
]
for
each
in
stampDict
]
timeOrder
=
[
time
.
strftime
(
"
%
Y-
%
m-
%
d
%
H:
%
M:
%
S"
,
time
.
localtime
(
each
))
for
each
in
timeOrder
]
timestage
=
[]
stampDict
=
sorted
(
stampDict
.
items
(),
key
=
lambda
d
:
d
[
0
])
timeOrder
=
[
each
[
0
]
for
each
in
stampDict
]
actionOrder
=
[
each
[
1
]
for
each
in
stampDict
]
timeOrder
=
[
time
.
strftime
(
"
%
Y-
%
m-
%
d
%
H:
%
M:
%
S"
,
time
.
localtime
(
each
))
for
each
in
timeOrder
]
timestage
=
[]
for
each_i
in
range
(
len
(
actionOrder
)):
stageComponent
.
append
([])
if
each_i
==
0
and
actionOrder
[
0
][:
2
]
==
"开启"
:
if
each_i
==
0
and
actionOrder
[
0
][:
2
]
==
"开启"
:
if
stageComponent
[
-
1
]
==
[]:
stageComponent
.
pop
(
-
1
)
continue
else
:
if
actionOrder
[
each_i
-
1
][:
2
]
==
"开启"
:
stageComponent
[
-
1
]
.
append
(
actionOrder
[
each_i
-
1
][
2
:]
+
"运行"
)
timestage
.
append
([
timeOrder
[
each_i
-
1
],
timeOrder
[
each_i
]])
if
len
(
timestage
)
>
1
and
timestage
[
-
2
]
==
timestage
[
-
1
]:
if
actionOrder
[
each_i
-
1
][:
2
]
==
"开启"
:
stageComponent
[
-
1
]
.
append
(
actionOrder
[
each_i
-
1
][
2
:]
+
"运行"
)
timestage
.
append
([
timeOrder
[
each_i
-
1
],
timeOrder
[
each_i
]])
if
len
(
timestage
)
>
1
and
timestage
[
-
2
]
==
timestage
[
-
1
]:
timestage
.
pop
(
-
1
)
if
actionOrder
[:
each_i
]
.
count
(
"开启电冰箱"
)
>
actionOrder
[:
each_i
]
.
count
(
"关闭电冰箱"
)
and
actionOrder
[
each_i
-
1
]
!=
"开启电冰箱"
and
"电冰箱运行"
not
in
stageComponent
:
if
actionOrder
[:
each_i
]
.
count
(
"开启电冰箱"
)
>
actionOrder
[
:
each_i
]
.
count
(
"关闭电冰箱"
)
and
actionOrder
[
each_i
-
1
]
!=
"开启电冰箱"
and
"电冰箱运行"
not
in
stageComponent
:
stageComponent
[
-
1
]
.
append
(
"电冰箱运行"
)
timestage
.
append
([
timeOrder
[
each_i
-
1
],
timeOrder
[
each_i
]])
if
len
(
timestage
)
>
1
and
timestage
[
-
2
]
==
timestage
[
-
1
]:
timestage
.
append
([
timeOrder
[
each_i
-
1
],
timeOrder
[
each_i
]])
if
len
(
timestage
)
>
1
and
timestage
[
-
2
]
==
timestage
[
-
1
]:
timestage
.
pop
(
-
1
)
if
actionOrder
[:
each_i
]
.
count
(
"开启电磁炉"
)
>
actionOrder
[:
each_i
]
.
count
(
"关闭电磁炉"
)
and
actionOrder
[
each_i
-
1
]
!=
"开启电磁炉"
and
"电磁炉运行"
not
in
stageComponent
:
if
actionOrder
[:
each_i
]
.
count
(
"开启电磁炉"
)
>
actionOrder
[
:
each_i
]
.
count
(
"关闭电磁炉"
)
and
actionOrder
[
each_i
-
1
]
!=
"开启电磁炉"
and
"电磁炉运行"
not
in
stageComponent
:
stageComponent
[
-
1
]
.
append
(
"电磁炉运行"
)
timestage
.
append
([
timeOrder
[
each_i
-
1
],
timeOrder
[
each_i
]])
if
len
(
timestage
)
>
1
and
timestage
[
-
2
]
==
timestage
[
-
1
]:
timestage
.
append
([
timeOrder
[
each_i
-
1
],
timeOrder
[
each_i
]])
if
len
(
timestage
)
>
1
and
timestage
[
-
2
]
==
timestage
[
-
1
]:
timestage
.
pop
(
-
1
)
if
actionOrder
[:
each_i
]
.
count
(
"开启热水器"
)
>
actionOrder
[:
each_i
]
.
count
(
"关闭热水器"
)
and
actionOrder
[
each_i
-
1
]
!=
"开启热水器"
and
"热水器运行"
not
in
stageComponent
:
if
actionOrder
[:
each_i
]
.
count
(
"开启热水器"
)
>
actionOrder
[
:
each_i
]
.
count
(
"关闭热水器"
)
and
actionOrder
[
each_i
-
1
]
!=
"开启热水器"
and
"热水器运行"
not
in
stageComponent
:
stageComponent
[
-
1
]
.
append
(
"热水器运行"
)
timestage
.
append
([
timeOrder
[
each_i
-
1
],
timeOrder
[
each_i
]])
if
len
(
timestage
)
>
1
and
timestage
[
-
2
]
==
timestage
[
-
1
]:
timestage
.
append
([
timeOrder
[
each_i
-
1
],
timeOrder
[
each_i
]])
if
len
(
timestage
)
>
1
and
timestage
[
-
2
]
==
timestage
[
-
1
]:
timestage
.
pop
(
-
1
)
if
actionOrder
[:
each_i
]
.
count
(
"开启空调"
)
>
actionOrder
[:
each_i
]
.
count
(
"关闭空调"
)
and
actionOrder
[
each_i
-
1
]
!=
"开启空调"
and
"空调运行"
not
in
stageComponent
:
if
actionOrder
[:
each_i
]
.
count
(
"开启空调"
)
>
actionOrder
[:
each_i
]
.
count
(
"关闭空调"
)
and
actionOrder
[
each_i
-
1
]
!=
"开启空调"
and
"空调运行"
not
in
stageComponent
:
stageComponent
[
-
1
]
.
append
(
"空调运行"
)
timestage
.
append
([
timeOrder
[
each_i
-
1
],
timeOrder
[
each_i
]])
if
len
(
timestage
)
>
1
and
timestage
[
-
2
]
==
timestage
[
-
1
]:
timestage
.
append
([
timeOrder
[
each_i
-
1
],
timeOrder
[
each_i
]])
if
len
(
timestage
)
>
1
and
timestage
[
-
2
]
==
timestage
[
-
1
]:
timestage
.
pop
(
-
1
)
if
stageComponent
[
-
1
]
==
[]:
if
stageComponent
[
-
1
]
==
[]:
stageComponent
.
pop
(
-
1
)
return
stageComponent
,
timestage
,
timeOrder
,
actionOrder
return
stageComponent
,
timestage
,
timeOrder
,
actionOrder
unify_api/modules/shidianu/service/decomp_main.py
View file @
9d4a6d83
...
...
@@ -23,16 +23,40 @@ def pieceWise(eachdata, params="params"):
heaterRunStages
=
[]
statesaircond
,
statesrefrig
,
stateselectro
,
statesricecook
,
statesheater
,
timeaircond
,
timerefrig
,
timericecook
,
timeelectro
,
timeheater
,
statesaircond_off
,
statesrefrig_off
,
stateselectro_off
,
statesricecook_off
,
statesheater_off
,
timeaircond_off
,
timerefrig_off
,
timericecook_off
,
timeelectro_off
,
timeheater_off
=
piececlassfy
(
current
=
eachdata_cur
,
power
=
eachdata_pow
,
timer
=
timer
,
params
=
params
)
if
len
(
statesaircond_off
)
>
0
:
aircondRunStages
=
aircondAnalysis
(
statesaircond
=
statesaircond
,
statesaircond_off
=
statesaircond_off
,
timeaircond
=
timeaircond
,
timeaircond_off
=
timeaircond_off
,
eachdata_pow
=
eachdata_pow
,
eachdata_cur
=
eachdata_cur
,
timer
=
timer
)
if
len
(
statesaircond_off
)
>
0
:
aircondRunStages
=
aircondAnalysis
(
statesaircond
=
statesaircond
,
statesaircond_off
=
statesaircond_off
,
timeaircond
=
timeaircond
,
timeaircond_off
=
timeaircond_off
,
eachdata_pow
=
eachdata_pow
,
eachdata_cur
=
eachdata_cur
,
timer
=
timer
)
#
if
len
(
stateselectro
)
>
0
:
electroRunStages
=
electroAnalysis
(
stateselectro
=
stateselectro
,
stateselectro_off
=
stateselectro_off
,
timeelectro
=
timeelectro
,
timeelectro_off
=
timeelectro_off
,
eachdata_pow
=
eachdata_pow
,
eachdata_cur
=
eachdata_cur
,
timer
=
timer
)
if
len
(
stateselectro
)
>
0
:
electroRunStages
=
electroAnalysis
(
stateselectro
=
stateselectro
,
stateselectro_off
=
stateselectro_off
,
timeelectro
=
timeelectro
,
timeelectro_off
=
timeelectro_off
,
eachdata_pow
=
eachdata_pow
,
eachdata_cur
=
eachdata_cur
,
timer
=
timer
)
if
len
(
statesheater
)
>
0
:
heaterRunStages
=
heaterAnalysis
(
statesheater
=
statesheater
,
statesheater_off
=
statesheater_off
,
timeheater
=
timeheater
,
timeheater_off
=
timeheater_off
,
eachdata_pow
=
eachdata_pow
,
eachdata_cur
=
eachdata_cur
,
timer
=
timer
)
if
len
(
statesheater
)
>
0
:
heaterRunStages
=
heaterAnalysis
(
statesheater
=
statesheater
,
statesheater_off
=
statesheater_off
,
timeheater
=
timeheater
,
timeheater_off
=
timeheater_off
,
eachdata_pow
=
eachdata_pow
,
eachdata_cur
=
eachdata_cur
,
timer
=
timer
)
if
len
(
statesrefrig
)
>
0
:
refrigRunStages
=
refrigAnalysis
(
statesrefrig
=
statesrefrig
,
statesrefrig_off
=
statesrefrig_off
,
timerefrig
=
timerefrig
,
timerefrig_off
=
timerefrig_off
,
eachdata_pow
=
eachdata_pow
,
eachdata_cur
=
eachdata_cur
,
timer
=
timer
)
if
len
(
statesrefrig
)
>
0
:
refrigRunStages
=
refrigAnalysis
(
statesrefrig
=
statesrefrig
,
statesrefrig_off
=
statesrefrig_off
,
timerefrig
=
timerefrig
,
timerefrig_off
=
timerefrig_off
,
eachdata_pow
=
eachdata_pow
,
eachdata_cur
=
eachdata_cur
,
timer
=
timer
)
return
aircondRunStages
,
electroRunStages
,
heaterRunStages
,
refrigRunStages
unify_api/modules/shidianu/service/electricProportion.py
View file @
9d4a6d83
...
...
@@ -11,8 +11,10 @@ def timeCalc(time=""):
return
timer
def
electQuar
(
stateDict
=
""
,
stageComponent
=
""
,
timestage
=
""
,
type
=
""
,
timeAll
=
""
,
power
=
""
):
affects
=
[
i
for
i
in
range
(
len
(
stageComponent
))
if
stageComponent
[
i
]
==
type
]
def
electQuar
(
stateDict
=
""
,
stageComponent
=
""
,
timestage
=
""
,
type
=
""
,
timeAll
=
""
,
power
=
""
):
affects
=
[
i
for
i
in
range
(
len
(
stageComponent
))
if
stageComponent
[
i
]
==
type
]
equipQuar
=
[]
timerUse
=
[]
for
each
in
affects
:
...
...
@@ -21,34 +23,40 @@ def electQuar(stateDict="",stageComponent="", timestage="", type="",timeAll="",p
timerUse
.
append
(
timeCalc
(
time
=
timestage
[
each
]))
equipQuar
.
append
(
np
.
mean
(
power
[
startIndex
:
endIndex
])
*
timerUse
[
-
1
])
stateDict
[
type
[
0
]]
=
[
equipQuar
,
timerUse
]
stateDict
[
type
[
0
]]
=
[
equipQuar
,
timerUse
]
return
stateDict
def
twoQuar
(
stateDict
=
{},
elems
=
[],
onetype
=
""
,
timeOccur
=
""
,
timeAll
=
""
,
power
=
""
):
if
onetype
==
[
"空调运行"
]:
def
twoQuar
(
stateDict
=
{},
elems
=
[],
onetype
=
""
,
timeOccur
=
""
,
timeAll
=
""
,
power
=
""
):
if
onetype
==
[
"空调运行"
]:
pass
elif
onetype
==
[
"电冰箱运行"
]:
elif
onetype
==
[
"电冰箱运行"
]:
if
"电冰箱运行"
in
stateDict
.
keys
():
timer
=
timeCalc
(
time
=
timeOccur
)
totalQuar
=
np
.
mean
(
power
[
timeAll
.
index
(
timeOccur
[
0
]):
timeAll
.
index
(
timeOccur
[
1
])])
*
timer
refrigSingle
=
timer
*
stateDict
[
"电冰箱运行"
][
0
][
-
1
]
/
stateDict
[
"电冰箱运行"
][
1
][
-
1
]
timer
=
timeCalc
(
time
=
timeOccur
)
totalQuar
=
np
.
mean
(
power
[
timeAll
.
index
(
timeOccur
[
0
]):
timeAll
.
index
(
timeOccur
[
1
])])
*
timer
refrigSingle
=
timer
*
stateDict
[
"电冰箱运行"
][
0
][
-
1
]
/
\
stateDict
[
"电冰箱运行"
][
1
][
-
1
]
stateDict
[
"电冰箱运行"
][
0
]
.
append
(
refrigSingle
)
stateDict
[
"电冰箱运行"
][
1
]
.
append
(
timer
)
another
=
list
(
set
(
elems
)
-
set
(
onetype
))
another
=
list
(
set
(
elems
)
-
set
(
onetype
))
if
another
[
0
]
not
in
stateDict
.
keys
():
if
totalQuar
-
refrigSingle
>
0
:
stateDict
[
another
[
0
]]
=
[[
totalQuar
-
refrigSingle
],[
timer
]]
if
totalQuar
-
refrigSingle
>
0
:
stateDict
[
another
[
0
]]
=
[[
totalQuar
-
refrigSingle
],
[
timer
]]
else
:
stateDict
[
another
[
0
]]
=
[[
totalQuar
*
0.1
],
[
timer
]]
stateDict
[
another
[
0
]]
=
[[
totalQuar
*
0.1
],
[
timer
]]
else
:
if
totalQuar
-
refrigSingle
>
0
:
stateDict
[
another
[
0
]][
0
]
.
append
(
totalQuar
-
refrigSingle
)
stateDict
[
another
[
0
]][
0
]
.
append
(
totalQuar
-
refrigSingle
)
stateDict
[
another
[
0
]][
1
]
.
append
(
timer
)
else
:
stateDict
[
another
[
0
]][
0
]
.
append
(
totalQuar
*
0.1
)
stateDict
[
another
[
0
]][
0
]
.
append
(
totalQuar
*
0.1
)
stateDict
[
another
[
0
]][
1
]
.
append
(
timer
)
elif
onetype
==
[
"电磁炉运行"
]:
pass
...
...
@@ -59,14 +67,20 @@ def twoQuar(stateDict={},elems=[],onetype="",timeOccur="",timeAll="",power=""):
return
stateDict
def
threeQuar
(
stateDict
=
{},
elems
=
""
,
onetype
=
""
,
timeOccur
=
""
,
timeAll
=
""
,
power
=
""
):
if
onetype
==
[
"电冰箱运行"
,
"空调运行"
]:
def
threeQuar
(
stateDict
=
{},
elems
=
""
,
onetype
=
""
,
timeOccur
=
""
,
timeAll
=
""
,
power
=
""
):
if
onetype
==
[
"电冰箱运行"
,
"空调运行"
]:
if
"电冰箱运行"
in
stateDict
.
keys
()
and
"空调运行"
in
stateDict
.
keys
():
timer
=
timeCalc
(
time
=
timeOccur
)
totalQuar
=
np
.
mean
(
power
[
timeAll
.
index
(
timeOccur
[
0
]):
timeAll
.
index
(
timeOccur
[
1
])])
*
timer
refrigSingle
=
timer
*
stateDict
[
"电冰箱运行"
][
0
][
-
1
]
/
stateDict
[
"电冰箱运行"
][
1
][
-
1
]
aircondSingle
=
timer
*
stateDict
[
"空调运行"
][
0
][
-
1
]
/
stateDict
[
"空调运行"
][
1
][
-
1
]
totalQuar
=
np
.
mean
(
power
[
timeAll
.
index
(
timeOccur
[
0
]):
timeAll
.
index
(
timeOccur
[
1
])])
*
timer
refrigSingle
=
timer
*
stateDict
[
"电冰箱运行"
][
0
][
-
1
]
/
\
stateDict
[
"电冰箱运行"
][
1
][
-
1
]
aircondSingle
=
timer
*
stateDict
[
"空调运行"
][
0
][
-
1
]
/
\
stateDict
[
"空调运行"
][
1
][
-
1
]
stateDict
[
"电冰箱运行"
][
0
]
.
append
(
refrigSingle
)
stateDict
[
"电冰箱运行"
][
1
]
.
append
(
timer
)
...
...
@@ -74,24 +88,30 @@ def threeQuar(stateDict={},elems="",onetype="",timeOccur="",timeAll="",power="")
stateDict
[
"空调运行"
][
1
]
.
append
(
timer
)
another
=
list
(
set
(
elems
)
-
set
(
onetype
))
if
another
[
0
]
not
in
stateDict
.
keys
():
if
totalQuar
-
refrigSingle
-
aircondSingle
>
0
:
stateDict
[
another
[
0
]]
=
[[
totalQuar
-
refrigSingle
-
aircondSingle
],
[
timer
]]
if
totalQuar
-
refrigSingle
-
aircondSingle
>
0
:
stateDict
[
another
[
0
]]
=
[
[
totalQuar
-
refrigSingle
-
aircondSingle
],
[
timer
]]
else
:
stateDict
[
another
[
0
]]
=
[[
totalQuar
*
0.1
],
[
timer
]]
stateDict
[
another
[
0
]]
=
[[
totalQuar
*
0.1
],
[
timer
]]
else
:
if
totalQuar
-
refrigSingle
-
aircondSingle
>
0
:
stateDict
[
another
[
0
]][
0
]
.
append
(
totalQuar
-
refrigSingle
-
aircondSingle
)
stateDict
[
another
[
0
]][
0
]
.
append
(
totalQuar
-
refrigSingle
-
aircondSingle
)
stateDict
[
another
[
0
]][
1
]
.
append
(
timer
)
else
:
stateDict
[
another
[
0
]][
0
]
.
append
(
totalQuar
*
0.1
)
stateDict
[
another
[
0
]][
0
]
.
append
(
totalQuar
*
0.1
)
stateDict
[
another
[
0
]][
1
]
.
append
(
timer
)
elif
onetype
==
[
"电冰箱运行"
,
"热水器运行"
]:
elif
onetype
==
[
"电冰箱运行"
,
"热水器运行"
]:
if
"电冰箱运行"
in
stateDict
.
keys
()
and
"热水器运行"
in
stateDict
.
keys
():
timer
=
timeCalc
(
time
=
timeOccur
)
totalQuar
=
np
.
mean
(
power
[
timeAll
.
index
(
timeOccur
[
0
]):
timeAll
.
index
(
timeOccur
[
1
])])
*
timer
refrigSingle
=
timer
*
stateDict
[
"电冰箱运行"
][
0
][
-
1
]
/
stateDict
[
"电冰箱运行"
][
1
][
-
1
]
heaterSingle
=
timer
*
stateDict
[
"热水器运行"
][
0
][
-
1
]
/
stateDict
[
"热水器运行"
][
1
][
-
1
]
totalQuar
=
np
.
mean
(
power
[
timeAll
.
index
(
timeOccur
[
0
]):
timeAll
.
index
(
timeOccur
[
1
])])
*
timer
refrigSingle
=
timer
*
stateDict
[
"电冰箱运行"
][
0
][
-
1
]
/
\
stateDict
[
"电冰箱运行"
][
1
][
-
1
]
heaterSingle
=
timer
*
stateDict
[
"热水器运行"
][
0
][
-
1
]
/
\
stateDict
[
"热水器运行"
][
1
][
-
1
]
stateDict
[
"电冰箱运行"
][
0
]
.
append
(
refrigSingle
)
stateDict
[
"电冰箱运行"
][
1
]
.
append
(
timer
)
...
...
@@ -99,27 +119,32 @@ def threeQuar(stateDict={},elems="",onetype="",timeOccur="",timeAll="",power="")
stateDict
[
"热水器运行"
][
1
]
.
append
(
timer
)
another
=
list
(
set
(
elems
)
-
set
(
onetype
))
if
another
[
0
]
not
in
stateDict
.
keys
():
if
totalQuar
-
refrigSingle
-
heaterSingle
>
0
:
stateDict
[
another
[
0
]]
=
[[
totalQuar
-
refrigSingle
-
heaterSingle
],
[
timer
]]
if
totalQuar
-
refrigSingle
-
heaterSingle
>
0
:
stateDict
[
another
[
0
]]
=
[
[
totalQuar
-
refrigSingle
-
heaterSingle
],
[
timer
]]
else
:
stateDict
[
another
[
0
]]
=
[[
totalQuar
*
0.1
],
[
timer
]]
stateDict
[
another
[
0
]]
=
[[
totalQuar
*
0.1
],
[
timer
]]
else
:
if
totalQuar
-
refrigSingle
-
heaterSingle
>
0
:
if
totalQuar
-
refrigSingle
-
heaterSingle
>
0
:
stateDict
[
another
[
0
]][
0
]
.
append
(
totalQuar
-
heaterSingle
-
refrigSingle
)
stateDict
[
another
[
0
]][
0
]
.
append
(
totalQuar
-
heaterSingle
-
refrigSingle
)
stateDict
[
another
[
0
]][
1
]
.
append
(
timer
)
else
:
stateDict
[
another
[
0
]][
0
]
.
append
(
totalQuar
*
0.1
)
stateDict
[
another
[
0
]][
0
]
.
append
(
totalQuar
*
0.1
)
stateDict
[
another
[
0
]][
1
]
.
append
(
timer
)
elif
onetype
==
[
"电冰箱运行"
,
"电磁炉运行"
]:
elif
onetype
==
[
"电冰箱运行"
,
"电磁炉运行"
]:
if
"电冰箱运行"
in
stateDict
.
keys
()
and
"电磁炉运行"
in
stateDict
.
keys
():
timer
=
timeCalc
(
time
=
timeOccur
)
totalQuar
=
np
.
mean
(
power
[
timeAll
.
index
(
timeOccur
[
0
]):
timeAll
.
index
(
timeOccur
[
1
])])
*
timer
refrigSingle
=
timer
*
stateDict
[
"电冰箱运行"
][
0
][
-
1
]
/
stateDict
[
"电冰箱运行"
][
1
][
-
1
]
electroSingle
=
timer
*
stateDict
[
"电磁炉运行"
][
0
][
-
1
]
/
stateDict
[
"电磁炉运行"
][
1
][
-
1
]
totalQuar
=
np
.
mean
(
power
[
timeAll
.
index
(
timeOccur
[
0
]):
timeAll
.
index
(
timeOccur
[
1
])])
*
timer
refrigSingle
=
timer
*
stateDict
[
"电冰箱运行"
][
0
][
-
1
]
/
\
stateDict
[
"电冰箱运行"
][
1
][
-
1
]
electroSingle
=
timer
*
stateDict
[
"电磁炉运行"
][
0
][
-
1
]
/
\
stateDict
[
"电磁炉运行"
][
1
][
-
1
]
stateDict
[
"电冰箱运行"
][
0
]
.
append
(
refrigSingle
)
stateDict
[
"电冰箱运行"
][
1
]
.
append
(
timer
)
...
...
@@ -127,28 +152,37 @@ def threeQuar(stateDict={},elems="",onetype="",timeOccur="",timeAll="",power="")
stateDict
[
"电磁炉运行"
][
1
]
.
append
(
timer
)
another
=
list
(
set
(
elems
)
-
set
(
onetype
))
if
another
[
0
]
not
in
stateDict
.
keys
():
if
totalQuar
-
refrigSingle
-
electroSingle
>
0
:
stateDict
[
another
[
0
]]
=
[[
totalQuar
-
refrigSingle
-
electroSingle
],
[
timer
]]
if
totalQuar
-
refrigSingle
-
electroSingle
>
0
:
stateDict
[
another
[
0
]]
=
[
[
totalQuar
-
refrigSingle
-
electroSingle
],
[
timer
]]
else
:
stateDict
[
another
[
0
]]
=
[[
totalQuar
*
0.1
],
[
timer
]]
stateDict
[
another
[
0
]]
=
[[
totalQuar
*
0.1
],
[
timer
]]
else
:
if
totalQuar
-
refrigSingle
-
electroSingle
>
0
:
if
totalQuar
-
refrigSingle
-
electroSingle
>
0
:
stateDict
[
another
[
0
]][
0
]
.
append
(
totalQuar
-
electroSingle
-
refrigSingle
)
stateDict
[
another
[
0
]][
0
]
.
append
(
totalQuar
-
electroSingle
-
refrigSingle
)
stateDict
[
another
[
0
]][
1
]
.
append
(
timer
)
else
:
stateDict
[
another
[
0
]][
0
]
.
append
(
totalQuar
*
0.1
)
stateDict
[
another
[
0
]][
0
]
.
append
(
totalQuar
*
0.1
)
stateDict
[
another
[
0
]][
1
]
.
append
(
timer
)
return
stateDict
def
fourQuar
(
stateDict
=
{},
elems
=
""
,
onetype
=
""
,
timeOccur
=
""
,
timeAll
=
""
,
power
=
""
):
if
onetype
==
[
"电冰箱运行"
,
"空调运行"
,
"电磁炉运行"
]:
def
fourQuar
(
stateDict
=
{},
elems
=
""
,
onetype
=
""
,
timeOccur
=
""
,
timeAll
=
""
,
power
=
""
):
if
onetype
==
[
"电冰箱运行"
,
"空调运行"
,
"电磁炉运行"
]:
if
"电冰箱运行"
in
stateDict
.
keys
()
and
"空调运行"
in
stateDict
.
keys
()
and
"电磁炉运行"
in
stateDict
.
keys
():
timer
=
timeCalc
(
time
=
timeOccur
)
totalQuar
=
np
.
mean
(
power
[
timeAll
.
index
(
timeOccur
[
0
]):
timeAll
.
index
(
timeOccur
[
1
])])
*
timer
refrigSingle
=
timer
*
stateDict
[
"电冰箱运行"
][
0
][
-
1
]
/
stateDict
[
"电冰箱运行"
][
1
][
-
1
]
aircondSingle
=
timer
*
stateDict
[
"空调运行"
][
0
][
-
1
]
/
stateDict
[
"空调运行"
][
1
][
-
1
]
electroSingle
=
timer
*
stateDict
[
"电磁炉运行"
][
0
][
-
1
]
/
stateDict
[
"电磁炉运行"
][
1
][
-
1
]
totalQuar
=
np
.
mean
(
power
[
timeAll
.
index
(
timeOccur
[
0
]):
timeAll
.
index
(
timeOccur
[
1
])])
*
timer
refrigSingle
=
timer
*
stateDict
[
"电冰箱运行"
][
0
][
-
1
]
/
\
stateDict
[
"电冰箱运行"
][
1
][
-
1
]
aircondSingle
=
timer
*
stateDict
[
"空调运行"
][
0
][
-
1
]
/
\
stateDict
[
"空调运行"
][
1
][
-
1
]
electroSingle
=
timer
*
stateDict
[
"电磁炉运行"
][
0
][
-
1
]
/
\
stateDict
[
"电磁炉运行"
][
1
][
-
1
]
stateDict
[
"电冰箱运行"
][
0
]
.
append
(
refrigSingle
)
stateDict
[
"电冰箱运行"
][
1
]
.
append
(
timer
)
...
...
@@ -158,57 +192,93 @@ def fourQuar(stateDict={},elems="",onetype="",timeOccur="",timeAll="",power=""):
stateDict
[
"电磁炉运行"
][
1
]
.
append
(
timer
)
another
=
list
(
set
(
elems
)
-
set
(
onetype
))
if
another
[
0
]
not
in
stateDict
.
keys
():
if
totalQuar
-
refrigSingle
-
aircondSingle
-
electroSingle
>
0
:
stateDict
[
another
[
0
]]
=
[[
totalQuar
-
refrigSingle
-
aircondSingle
-
electroSingle
],
[
timer
]]
if
totalQuar
-
refrigSingle
-
aircondSingle
-
electroSingle
>
0
:
stateDict
[
another
[
0
]]
=
[[
totalQuar
-
refrigSingle
-
aircondSingle
-
electroSingle
],
[
timer
]]
else
:
stateDict
[
another
[
0
]]
=
[[
totalQuar
*
0.1
],
[
timer
]]
stateDict
[
another
[
0
]]
=
[[
totalQuar
*
0.1
],
[
timer
]]
else
:
if
totalQuar
-
refrigSingle
-
aircondSingle
-
electroSingle
>
0
:
if
totalQuar
-
refrigSingle
-
aircondSingle
-
electroSingle
>
0
:
stateDict
[
another
[
0
]][
0
]
.
append
(
totalQuar
-
refrigSingle
-
aircondSingle
-
electroSingle
)
stateDict
[
another
[
0
]][
0
]
.
append
(
totalQuar
-
refrigSingle
-
aircondSingle
-
electroSingle
)
stateDict
[
another
[
0
]][
1
]
.
append
(
timer
)
else
:
stateDict
[
another
[
0
]][
0
]
.
append
(
totalQuar
*
0.1
)
stateDict
[
another
[
0
]][
0
]
.
append
(
totalQuar
*
0.1
)
stateDict
[
another
[
0
]][
1
]
.
append
(
timer
)
return
stateDict
def
electricProportion
(
stageComponent
=
"stageComponent"
,
timestage
=
"timestage"
,
power
=
"power_pa"
,
timeAll
=
"day_time"
):
def
electricProportion
(
stageComponent
=
"stageComponent"
,
timestage
=
"timestage"
,
power
=
"power_pa"
,
timeAll
=
"day_time"
):
equipClass
=
set
([
each2
for
each
in
stageComponent
for
each2
in
each
])
stateDict
=
{}
flag
=
[
0
,
0
,
0
,
0
,
0
]
statisResDict
=
{}
stateDict
=
{}
flag
=
[
0
,
0
,
0
,
0
,
0
]
statisResDict
=
{}
if
[
"电冰箱运行"
]
in
stageComponent
:
stateDict
=
electQuar
(
stateDict
=
stateDict
,
stageComponent
=
stageComponent
,
timestage
=
timestage
,
type
=
[
"电冰箱运行"
],
timeAll
=
timeAll
,
power
=
power
)
flag
[
0
]
=
1
stateDict
=
electQuar
(
stateDict
=
stateDict
,
stageComponent
=
stageComponent
,
timestage
=
timestage
,
type
=
[
"电冰箱运行"
],
timeAll
=
timeAll
,
power
=
power
)
flag
[
0
]
=
1
if
[
"空调运行"
]
in
stageComponent
:
stateDict
=
electQuar
(
stateDict
=
stateDict
,
stageComponent
=
stageComponent
,
timestage
=
timestage
,
type
=
[
"电冰箱运行"
],
timeAll
=
timeAll
,
power
=
power
)
flag
[
1
]
=
1
stateDict
=
electQuar
(
stateDict
=
stateDict
,
stageComponent
=
stageComponent
,
timestage
=
timestage
,
type
=
[
"电冰箱运行"
],
timeAll
=
timeAll
,
power
=
power
)
flag
[
1
]
=
1
if
[
"电磁炉运行"
]
in
stageComponent
:
stateDict
=
electQuar
(
stateDict
=
stateDict
,
stageComponent
=
stageComponent
,
timestage
=
timestage
,
type
=
[
"电磁炉运行"
],
timeAll
=
timeAll
,
power
=
power
)
flag
[
2
]
=
1
stateDict
=
electQuar
(
stateDict
=
stateDict
,
stageComponent
=
stageComponent
,
timestage
=
timestage
,
type
=
[
"电磁炉运行"
],
timeAll
=
timeAll
,
power
=
power
)
flag
[
2
]
=
1
if
[
"热水器运行"
]
in
stageComponent
:
stateDict
=
electQuar
(
stateDict
=
stateDict
,
stageComponent
=
stageComponent
,
timestage
=
timestage
,
type
=
[
"热水器运行"
],
timeAll
=
timeAll
,
power
=
power
)
flag
[
3
]
=
1
stateDict
=
electQuar
(
stateDict
=
stateDict
,
stageComponent
=
stageComponent
,
timestage
=
timestage
,
type
=
[
"热水器运行"
],
timeAll
=
timeAll
,
power
=
power
)
flag
[
3
]
=
1
if
[
"电饭煲运行"
]
in
stageComponent
:
stateDict
=
electQuar
(
stateDict
=
stateDict
,
stageComponent
=
stageComponent
,
timestage
=
timestage
,
type
=
[
"电饭煲运行"
],
timeAll
=
timeAll
,
power
=
power
)
flag
[
4
]
=
1
affects
=
[
i
for
i
in
range
(
len
(
stageComponent
))
if
len
(
stageComponent
[
i
])
==
2
]
stateDict
=
electQuar
(
stateDict
=
stateDict
,
stageComponent
=
stageComponent
,
timestage
=
timestage
,
type
=
[
"电饭煲运行"
],
timeAll
=
timeAll
,
power
=
power
)
flag
[
4
]
=
1
affects
=
[
i
for
i
in
range
(
len
(
stageComponent
))
if
len
(
stageComponent
[
i
])
==
2
]
for
each
in
affects
:
if
flag
[
0
]
==
1
and
"电冰箱运行"
in
stageComponent
[
each
]:
stateDict
=
twoQuar
(
stateDict
=
stateDict
,
elems
=
stageComponent
[
each
],
onetype
=
[
"电冰箱运行"
],
timeOccur
=
timestage
[
each
],
timeAll
=
timeAll
,
power
=
power
)
if
flag
[
0
]
==
1
and
"电冰箱运行"
in
stageComponent
[
each
]:
stateDict
=
twoQuar
(
stateDict
=
stateDict
,
elems
=
stageComponent
[
each
],
onetype
=
[
"电冰箱运行"
],
timeOccur
=
timestage
[
each
],
timeAll
=
timeAll
,
power
=
power
)
affects
=
[
i
for
i
in
range
(
len
(
stageComponent
))
if
len
(
stageComponent
[
i
])
==
3
]
affects
=
[
i
for
i
in
range
(
len
(
stageComponent
))
if
len
(
stageComponent
[
i
])
==
3
]
for
each
in
affects
:
if
flag
[
0
]
==
1
and
"电冰箱运行"
in
stageComponent
[
each
]
and
"空调运行"
in
stageComponent
[
each
]:
stateDict
=
threeQuar
(
stateDict
=
stateDict
,
elems
=
stageComponent
[
each
],
onetype
=
[
"电冰箱运行"
,
"空调运行"
],
timeOccur
=
timestage
[
each
],
timeAll
=
timeAll
,
power
=
power
)
if
flag
[
0
]
==
1
and
"电冰箱运行"
in
stageComponent
[
each
]
and
"空调运行"
in
\
stageComponent
[
each
]:
stateDict
=
threeQuar
(
stateDict
=
stateDict
,
elems
=
stageComponent
[
each
],
onetype
=
[
"电冰箱运行"
,
"空调运行"
],
timeOccur
=
timestage
[
each
],
timeAll
=
timeAll
,
power
=
power
)
affects
=
[
i
for
i
in
range
(
len
(
stageComponent
))
if
len
(
stageComponent
[
i
])
==
4
]
affects
=
[
i
for
i
in
range
(
len
(
stageComponent
))
if
len
(
stageComponent
[
i
])
==
4
]
for
each
in
affects
:
if
flag
[
0
]
==
1
and
"电冰箱运行"
in
stageComponent
[
each
]
and
"空调运行"
in
stageComponent
[
each
]
and
"电磁炉运行"
in
stageComponent
[
each
]:
stateDict
=
fourQuar
(
stateDict
=
stateDict
,
elems
=
stageComponent
[
each
],
onetype
=
[
"电冰箱运行"
,
"空调运行"
,
"电磁炉运行"
],
timeOccur
=
timestage
[
each
],
timeAll
=
timeAll
,
power
=
power
)
statisResDict
[
"电量与时长"
]
=
stateDict
statisResDict
[
"波动"
]
=
{
"电冰箱"
:
60
,
"空调"
:
20
,
"电磁炉"
:
3
,
"热水器"
:
2
}
if
flag
[
0
]
==
1
and
"电冰箱运行"
in
stageComponent
[
each
]
and
"空调运行"
in
\
stageComponent
[
each
]
and
"电磁炉运行"
in
stageComponent
[
each
]:
stateDict
=
fourQuar
(
stateDict
=
stateDict
,
elems
=
stageComponent
[
each
],
onetype
=
[
"电冰箱运行"
,
"空调运行"
,
"电磁炉运行"
],
timeOccur
=
timestage
[
each
],
timeAll
=
timeAll
,
power
=
power
)
statisResDict
[
"电量与时长"
]
=
stateDict
statisResDict
[
"波动"
]
=
{
"电冰箱"
:
60
,
"空调"
:
20
,
"电磁炉"
:
3
,
"热水器"
:
2
}
return
statisResDict
unify_api/modules/shidianu/service/electroAnalysis.py
View file @
9d4a6d83
...
...
@@ -2,36 +2,46 @@ import time
def
findStart
(
timeelectro
=
"timeelectro"
,
timeelectro_last
=
""
,
ahead
=
0
):
timeelectro_last_stemp
=
int
(
time
.
mktime
(
time
.
strptime
(
timeelectro_last
,
"
%
Y-
%
m-
%
d
%
H:
%
M:
%
S"
)))
timeelectro_stemp
=
[
int
(
time
.
mktime
(
time
.
strptime
(
each_time
,
"
%
Y-
%
m-
%
d
%
H:
%
M:
%
S"
)))
for
each_time
in
timeelectro
]
timeelectro_last_stemp
=
int
(
time
.
mktime
(
time
.
strptime
(
timeelectro_last
,
"
%
Y-
%
m-
%
d
%
H:
%
M:
%
S"
)))
timeelectro_stemp
=
[
int
(
time
.
mktime
(
time
.
strptime
(
each_time
,
"
%
Y-
%
m-
%
d
%
H:
%
M:
%
S"
)))
for
each_time
in
timeelectro
]
if
ahead
<
len
(
timeelectro
)
-
1
:
time_substruct
=
[
1000000
if
timeelectro_stemp
[
each_timeelectro_stemp
]
-
timeelectro_last_stemp
<=
0
or
each_timeelectro_stemp
<
ahead
else
timeelectro_stemp
[
each_timeelectro_stemp
]
-
timeelectro_last_stemp
for
each_timeelectro_stemp
timeelectro_stemp
[
each_timeelectro_stemp
]
-
timeelectro_last_stemp
for
each_timeelectro_stemp
in
range
(
len
(
timeelectro_stemp
))]
else
:
time_substruct
=
[
1000000
if
timeelectro_last_stemp
-
timeelectro_stemp
[
time_substruct
=
[
1000000
if
timeelectro_last_stemp
-
timeelectro_stemp
[
each_timeelectro_stemp
]
<=
0
or
each_timeelectro_stemp
<
ahead
else
timeelectro_last_stemp
-
timeelectro_stemp
[
each_timeelectro_stemp
]
for
each_timeelectro_stemp
]
for
each_timeelectro_stemp
in
range
(
len
(
timeelectro_stemp
))]
index
=
time_substruct
.
index
(
min
(
time_substruct
))
return
index
def
electroAnalysis
(
stateselectro
=
"stateselectro"
,
stateselectro_off
=
"stateselectro_off"
,
timeelectro
=
"timeelectro"
,
timeelectro_off
=
"timeelectro_off"
,
eachdata_pow
=
"eachdata_pow"
def
electroAnalysis
(
stateselectro
=
"stateselectro"
,
stateselectro_off
=
"stateselectro_off"
,
timeelectro
=
"timeelectro"
,
timeelectro_off
=
"timeelectro_off"
,
eachdata_pow
=
"eachdata_pow"
,
eachdata_cur
=
"eachdata_cur"
,
timer
=
"timer"
):
electroRunStages
=
[]
timeelectro_chang
=
[
each
.
split
(
" "
)[
1
][:
-
3
]
.
split
(
":"
)
for
each
in
timeelectro
]
timeelectro_chang
=
[
each
.
split
(
" "
)[
1
][:
-
3
]
.
split
(
":"
)
for
each
in
timeelectro
]
timeelectro_hour
=
[
each
[
0
]
for
each
in
timeelectro_chang
]
timeelectro_minute
=
[
each
[
1
]
for
each
in
timeelectro_chang
]
timeelectro_off_chang
=
[
each
.
split
(
" "
)[
1
][:
-
3
]
.
split
(
":"
)
for
each
in
timeelectro_off
]
timeelectro_off_chang
=
[
each
.
split
(
" "
)[
1
][:
-
3
]
.
split
(
":"
)
for
each
in
timeelectro_off
]
timeelectro_off_hour
=
[
each
[
0
]
for
each
in
timeelectro_off_chang
]
timeelectro_off_minute
=
[
each
[
1
]
for
each
in
timeelectro_off_chang
]
...
...
@@ -40,22 +50,30 @@ def electroAnalysis(stateselectro="stateselectro", stateselectro_off="stateselec
electroRunStages
.
append
(
timeelectro
[
0
])
for
each_off
in
range
(
1
,
len
(
timeelectro_off
)):
# if each_off==len(timeaircond_off)-1:
if
int
(
timeelectro_off_hour
[
-
1
])
-
int
(
timeelectro_off_hour
[
-
2
])
>
2
and
each_off
==
len
(
if
int
(
timeelectro_off_hour
[
-
1
])
-
int
(
timeelectro_off_hour
[
-
2
])
>
2
and
each_off
==
len
(
timeelectro_off_hour
)
-
1
:
if
flag
==
1
:
index
=
findStart
(
timeelectro
=
timeelectro
,
timeelectro_last
=
timeelectro_off
[
each_off
],
ahead
=
each_off
)
index
=
findStart
(
timeelectro
=
timeelectro
,
timeelectro_last
=
timeelectro_off
[
each_off
],
ahead
=
each_off
)
electroRunStages
.
append
(
timeelectro
[
index
])
electroRunStages
.
append
(
timeelectro_off
[
each_off
])
elif
int
(
timeelectro_off_hour
[
each_off
])
-
int
(
timeelectro_off_hour
[
each_off
-
1
])
<=
1
:
elif
int
(
timeelectro_off_hour
[
each_off
])
-
int
(
timeelectro_off_hour
[
each_off
-
1
])
<=
1
:
continue
else
:
if
each_off
<
len
(
timeelectro_off_hour
)
-
1
:
electroRunStages
.
append
(
timeelectro_off
[
each_off
-
1
])
index
=
findStart
(
timeelectro
=
timeelectro
,
timeelectro_last
=
timeelectro_off
[
each_off
-
1
],
index
=
findStart
(
timeelectro
=
timeelectro
,
timeelectro_last
=
timeelectro_off
[
each_off
-
1
],
ahead
=
each_off
)
electroRunStages
.
append
(
timeelectro
[
index
])
if
int
(
timeelectro_off_hour
[
each_off
])
-
int
(
timeelectro_hour
[
index
])
<=
1
and
int
(
timeelectro_off_hour
[
each_off
])
-
int
(
timeelectro_off_hour
[
each_off
+
1
])
<
-
1
:
if
int
(
timeelectro_off_hour
[
each_off
])
-
int
(
timeelectro_hour
[
index
])
<=
1
and
int
(
timeelectro_off_hour
[
each_off
])
-
int
(
timeelectro_off_hour
[
each_off
+
1
])
<
-
1
:
electroRunStages
.
append
(
timeelectro_off
[
each_off
])
flag
=
1
...
...
unify_api/modules/shidianu/service/heaterAnalysis.py
View file @
9d4a6d83
import
time
def
findStart
(
timeheater
=
"timeheater"
,
timeheater_last
=
""
,
ahead
=
0
):
timeelectro_last_stemp
=
int
(
time
.
mktime
(
time
.
strptime
(
timeheater_last
,
"
%
Y-
%
m-
%
d
%
H:
%
M:
%
S"
)))
timeelectro_stemp
=
[
int
(
time
.
mktime
(
time
.
strptime
(
each_time
,
"
%
Y-
%
m-
%
d
%
H:
%
M:
%
S"
)))
for
each_time
in
timeheater
]
def
findStart
(
timeheater
=
"timeheater"
,
timeheater_last
=
""
,
ahead
=
0
):
timeelectro_last_stemp
=
int
(
time
.
mktime
(
time
.
strptime
(
timeheater_last
,
"
%
Y-
%
m-
%
d
%
H:
%
M:
%
S"
)))
timeelectro_stemp
=
[
int
(
time
.
mktime
(
time
.
strptime
(
each_time
,
"
%
Y-
%
m-
%
d
%
H:
%
M:
%
S"
)))
for
each_time
in
timeheater
]
if
ahead
<
len
(
timeheater
)
-
1
:
time_substruct
=
[
1000000
if
timeelectro_stemp
[
each_timeelectro_stemp
]
-
timeelectro_last_stemp
<=
0
or
each_timeelectro_stemp
<
ahead
else
timeelectro_stemp
[
each_timeelectro_stemp
]
-
timeelectro_last_stemp
for
each_timeelectro_stemp
timeelectro_stemp
[
each_timeelectro_stemp
]
-
timeelectro_last_stemp
for
each_timeelectro_stemp
in
range
(
len
(
timeelectro_stemp
))]
else
:
time_substruct
=
[
1000000
if
timeelectro_last_stemp
-
timeelectro_stemp
[
time_substruct
=
[
1000000
if
timeelectro_last_stemp
-
timeelectro_stemp
[
each_timeelectro_stemp
]
<=
0
or
each_timeelectro_stemp
<
ahead
else
timeelectro_last_stemp
-
timeelectro_stemp
[
each_timeelectro_stemp
]
for
each_timeelectro_stemp
]
for
each_timeelectro_stemp
in
range
(
len
(
timeelectro_stemp
))]
index
=
time_substruct
.
index
(
min
(
time_substruct
))
return
index
def
heaterAnalysis
(
statesheater
=
"statesheater"
,
statesheater_off
=
""
,
timeheater
=
"timeheater"
,
timeheater_off
=
"timeheater_off"
,
eachdata_pow
=
"eachdata_pow"
,
eachdata_cur
=
"eachdata_cur"
,
def
heaterAnalysis
(
statesheater
=
"statesheater"
,
statesheater_off
=
""
,
timeheater
=
"timeheater"
,
timeheater_off
=
"timeheater_off"
,
eachdata_pow
=
"eachdata_pow"
,
eachdata_cur
=
"eachdata_cur"
,
timer
=
"timer"
):
heaterRunStages
=
[]
timeheater_chang
=
[
each
.
split
(
" "
)[
1
][:
-
3
]
.
split
(
":"
)
for
each
in
timeheater
]
timeheater_chang
=
[
each
.
split
(
" "
)[
1
][:
-
3
]
.
split
(
":"
)
for
each
in
timeheater
]
timeheater_hour
=
[
each
[
0
]
for
each
in
timeheater_chang
]
timeheater_minute
=
[
each
[
1
]
for
each
in
timeheater_chang
]
timeheater_off_chang
=
[
each
.
split
(
" "
)[
1
][:
-
3
]
.
split
(
":"
)
for
each
in
timeheater_off
]
timeheater_off_chang
=
[
each
.
split
(
" "
)[
1
][:
-
3
]
.
split
(
":"
)
for
each
in
timeheater_off
]
timeheater_off_hour
=
[
each
[
0
]
for
each
in
timeheater_off_chang
]
timeheater_off_minute
=
[
each
[
1
]
for
each
in
timeheater_off_chang
]
...
...
@@ -39,22 +50,30 @@ def heaterAnalysis(statesheater="statesheater", statesheater_off="", timeheater=
for
each_off
in
range
(
1
,
len
(
timeheater_off
)):
# if each_off==len(timeaircond_off)-1:
if
int
(
timeheater_off_hour
[
-
1
])
-
int
(
timeheater_off_hour
[
-
2
])
>
2
and
each_off
==
len
(
if
int
(
timeheater_off_hour
[
-
1
])
-
int
(
timeheater_off_hour
[
-
2
])
>
2
and
each_off
==
len
(
timeheater_off_hour
)
-
1
:
if
flag
==
1
:
index
=
findStart
(
timeheater
=
timeheater
,
timeheater_last
=
timeheater_off
[
each_off
],
ahead
=
each_off
)
index
=
findStart
(
timeheater
=
timeheater
,
timeheater_last
=
timeheater_off
[
each_off
],
ahead
=
each_off
)
heaterRunStages
.
append
(
timeheater
[
index
])
heaterRunStages
.
append
(
timeheater_off
[
each_off
])
elif
int
(
timeheater_off_hour
[
each_off
])
-
int
(
timeheater_off_hour
[
each_off
-
1
])
<=
1
:
elif
int
(
timeheater_off_hour
[
each_off
])
-
int
(
timeheater_off_hour
[
each_off
-
1
])
<=
1
:
continue
else
:
if
each_off
<
len
(
timeheater
)
-
1
:
heaterRunStages
.
append
(
timeheater_off
[
each_off
-
1
])
index
=
findStart
(
timeheater
=
timeheater
,
timeheater_last
=
timeheater_off
[
each_off
-
1
],
index
=
findStart
(
timeheater
=
timeheater
,
timeheater_last
=
timeheater_off
[
each_off
-
1
],
ahead
=
each_off
)
heaterRunStages
.
append
(
timeheater
[
index
])
if
int
(
timeheater_off_hour
[
each_off
])
-
int
(
timeheater_hour
[
index
])
<=
1
and
int
(
timeheater_off_hour
[
each_off
])
-
int
(
timeheater_off_hour
[
each_off
+
1
])
<
-
1
:
if
int
(
timeheater_off_hour
[
each_off
])
-
int
(
timeheater_hour
[
index
])
<=
1
and
int
(
timeheater_off_hour
[
each_off
])
-
int
(
timeheater_off_hour
[
each_off
+
1
])
<
-
1
:
heaterRunStages
.
append
(
timeheater_off
[
each_off
])
flag
=
1
...
...
unify_api/modules/shidianu/service/highPower.py
View file @
9d4a6d83
...
...
@@ -94,7 +94,7 @@ def bigPowerReg(eachdata="powerdata", key="a"):
timethr
=
timethr
+
1
flag3
=
1
equips
=
likesEquip
(
time
=
res
[
0
::
2
])
timer
=
[
str
(
each
)
for
each
in
res
[
0
::
2
]]
timer
=
[
str
(
each
)
for
each
in
res
[
0
::
2
]]
return
timer
,
equips
...
...
@@ -199,10 +199,9 @@ def vioPowerReg(eachdata="powerdata", key="a"):
if
flag1
==
1
and
powerdata
[
i
]
*
1000
>
viopowerone
[
1
]:
timeone
=
timeone
+
1
continue
timer
=
[
str
(
each
)
for
each
in
res
]
timer
=
[
str
(
each
)
for
each
in
res
]
return
timer
,
equips
# plt.rcParams['font.sans-serif'] = ['SimHei']
# plt.rcParams['axes.unicode_minus'] = False
#
...
...
unify_api/modules/shidianu/service/open_data_service.py
View file @
9d4a6d83
...
...
@@ -236,7 +236,8 @@ async def result_longgang_service(user_id, importance, page_size, page_num):
is_auth
=
await
get_power
(
user_id
,
cids
)
if
not
is_auth
:
return
success_res
(
code
=
4001
,
msg
=
"您没有权限访问"
)
es_res
=
await
result_longgang_by_cid
(
cids
,
page_num
,
page_size
,
importance
)
es_res
=
await
result_longgang_by_cid
(
cids
,
page_num
,
page_size
,
importance
)
if
not
es_res
[
"hits"
][
"hits"
]:
return
ListAlarmResponse
(
total
=
0
,
rows
=
[])
# 2. 构建返回数据
...
...
unify_api/modules/shidianu/service/paramAnaly.py
View file @
9d4a6d83
...
...
@@ -198,7 +198,7 @@ async def params_mining(date_time_list, sid, sn):
pd
.
to_datetime
(
day_time_all
[
i
],
format
=
'
%
Y-
%
m-
%
d
%
H:
%
M:
%
S'
)
for
i
in
range
(
len
(
day_time_all
))]
power_pa_Series
=
pd
.
Series
(
power_pa
,
index
=
day_time_all
)
power_pa_Series
=
power_pa_Series
.
interpolate
(
method
=
'nearest'
)
power_pa_Series
=
power_pa_Series
.
interpolate
(
method
=
'nearest'
)
# power_pb_Series = pd.Series(power_pb, index=day_time_all)
# power_pc_Series = pd.Series(power_pc, index=day_time_all)
...
...
unify_api/modules/shidianu/service/pieceClassify.py
View file @
9d4a6d83
...
...
@@ -2,7 +2,8 @@ import numpy as np
import
re
def
piececlassfy
(
current
=
"eachnode_cur"
,
power
=
"eachnode_pow"
,
timer
=
"timer"
,
params
=
"params"
):
def
piececlassfy
(
current
=
"eachnode_cur"
,
power
=
"eachnode_pow"
,
timer
=
"timer"
,
params
=
"params"
):
month
=
timer
[
0
]
.
split
(
" "
)[
0
]
.
split
(
"-"
)[
1
]
day
=
timer
[
0
]
.
split
(
" "
)[
0
]
.
split
(
"-"
)[
2
]
hours
=
[
each
.
split
(
" "
)[
1
]
.
split
(
":"
)[
0
]
for
each
in
timer
]
...
...
@@ -35,7 +36,8 @@ def piececlassfy(current="eachnode_cur", power="eachnode_pow", timer="timer", pa
timeelectro_off
=
[]
timeheater_off
=
[]
quannums
=
[
.01
,
.03
,
.05
,
.1
,
.2
,
.3
,
.4
,
.5
,
.6
,
.7
,
.8
,
.9
,
.95
,
.98
,
.99
]
quannums
=
[
.01
,
.03
,
.05
,
.1
,
.2
,
.3
,
.4
,
.5
,
.6
,
.7
,
.8
,
.9
,
.95
,
.98
,
.99
]
opernumstate
=
[]
for
i
in
range
(
dataLen
):
if
i
==
0
:
...
...
@@ -55,48 +57,60 @@ def piececlassfy(current="eachnode_cur", power="eachnode_pow", timer="timer", pa
his_p
.
append
(
now_p
[
0
])
now_p
=
now_p
[
-
5
:]
now_i
=
now_i
[
-
5
:]
if
1000
*
(
now_p
[
0
]
-
his_p
[
-
1
])
>
params
[
0
]
-
50
and
1000
*
(
now_p
[
0
]
-
his_p
[
-
1
])
<
min
(
params
[
1
:])
+
50
:
if
1000
*
(
now_p
[
0
]
-
his_p
[
-
1
])
>
params
[
0
]
-
50
and
1000
*
(
now_p
[
0
]
-
his_p
[
-
1
])
<
min
(
params
[
1
:])
+
50
:
statesrefrig
.
append
(
"电冰箱运行"
)
timerefrig
.
append
(
timer
[
i
])
if
1000
*
(
now_p
[
0
]
-
his_p
[
-
1
])
>
params
[
1
]
-
50
and
1000
*
(
now_p
[
0
]
-
his_p
[
-
1
])
<
min
(
params
[
2
:])
+
50
:
if
1000
*
(
now_p
[
0
]
-
his_p
[
-
1
])
>
params
[
1
]
-
50
and
1000
*
(
now_p
[
0
]
-
his_p
[
-
1
])
<
min
(
params
[
2
:])
+
50
:
statesaircond
.
append
(
"空调运行"
)
timeaircond
.
append
(
timer
[
i
])
if
1000
*
(
now_p
[
0
]
-
his_p
[
-
1
])
>
min
(
params
[
2
:])
-
50
and
(
int
(
hours
[
i
])
>=
22
or
int
(
hours
[
i
])
<
5
or
int
(
hours
[
i
])
>=
19
):
int
(
hours
[
i
])
>=
22
or
int
(
hours
[
i
])
<
5
or
int
(
hours
[
i
])
>=
19
):
statesheater
.
append
(
"热水器启动"
)
timeheater
.
append
(
timer
[
i
])
if
1000
*
(
now_p
[
0
]
-
his_p
[
-
1
])
>
min
(
params
[
3
:])
-
50
and
1000
*
(
now_p
[
0
]
-
his_p
[
-
1
])
<
max
(
if
1000
*
(
now_p
[
0
]
-
his_p
[
-
1
])
>
min
(
params
[
3
:])
-
50
and
1000
*
(
now_p
[
0
]
-
his_p
[
-
1
])
<
max
(
params
[
3
:])
+
50
and
(
int
(
hours
[
i
])
>=
10
and
int
(
hours
[
i
])
<
14
or
int
(
hours
[
i
])
>=
17
and
int
(
hours
[
i
])
<
20
or
int
(
int
(
hours
[
i
])
>=
10
and
int
(
hours
[
i
])
<
14
or
int
(
hours
[
i
])
>=
17
and
int
(
hours
[
i
])
<
20
or
int
(
hours
[
i
])
>=
5
and
int
(
hours
[
i
])
<
10
):
statesricecook
.
append
(
"电饭煲启动"
)
timericecook
.
append
(
timer
[
i
])
if
1000
*
(
now_p
[
0
]
-
his_p
[
-
1
])
>
max
(
params
[
3
:])
-
50
and
(
int
(
hours
[
i
])
>=
10
and
int
(
hours
[
i
])
<
14
or
int
(
hours
[
i
])
>=
17
and
int
(
hours
[
i
])
<
20
or
int
(
int
(
hours
[
i
])
>=
10
and
int
(
hours
[
i
])
<
14
or
int
(
hours
[
i
])
>=
17
and
int
(
hours
[
i
])
<
20
or
int
(
hours
[
i
])
>=
5
and
int
(
hours
[
i
])
<
10
):
stateselectro
.
append
(
"电磁炉运行"
)
timeelectro
.
append
(
timer
[
i
])
# return 0
if
1000
*
(
his_p
[
-
1
]
-
now_p
[
0
])
>
params
[
0
]
-
50
and
1000
*
(
his_p
[
-
1
]
-
now_p
[
0
])
<
min
(
params
[
1
:])
+
50
:
if
1000
*
(
his_p
[
-
1
]
-
now_p
[
0
])
>
params
[
0
]
-
50
and
1000
*
(
his_p
[
-
1
]
-
now_p
[
0
])
<
min
(
params
[
1
:])
+
50
:
statesrefrig_off
.
append
(
"电冰箱关闭"
)
timerefrig_off
.
append
(
timer
[
i
])
if
1000
*
(
his_p
[
-
1
]
-
now_p
[
0
])
>
params
[
1
]
-
50
and
1000
*
(
his_p
[
-
1
]
-
now_p
[
0
])
<
min
(
params
[
2
:])
+
50
:
if
1000
*
(
his_p
[
-
1
]
-
now_p
[
0
])
>
params
[
1
]
-
50
and
1000
*
(
his_p
[
-
1
]
-
now_p
[
0
])
<
min
(
params
[
2
:])
+
50
:
statesaircond_off
.
append
(
"空调关闭"
)
timeaircond_off
.
append
(
timer
[
i
])
if
1000
*
(
his_p
[
-
1
]
-
now_p
[
0
])
>
min
(
params
[
2
:])
-
50
and
(
int
(
hours
[
i
])
>=
22
or
int
(
hours
[
i
])
<
5
or
int
(
hours
[
i
])
>=
19
):
int
(
hours
[
i
])
>=
22
or
int
(
hours
[
i
])
<
5
or
int
(
hours
[
i
])
>=
19
):
statesheater_off
.
append
(
"热水器关闭"
)
timeheater_off
.
append
(
timer
[
i
])
if
1000
*
(
his_p
[
-
1
]
-
now_p
[
0
])
>
min
(
params
[
3
:])
-
50
and
1000
*
(
his_p
[
-
1
]
-
now_p
[
0
])
<
max
(
if
1000
*
(
his_p
[
-
1
]
-
now_p
[
0
])
>
min
(
params
[
3
:])
-
50
and
1000
*
(
his_p
[
-
1
]
-
now_p
[
0
])
<
max
(
params
[
3
:])
+
50
and
(
int
(
hours
[
i
])
>=
10
and
int
(
hours
[
i
])
<
14
or
int
(
hours
[
i
])
>=
17
and
int
(
hours
[
i
])
<
20
or
int
(
int
(
hours
[
i
])
>=
10
and
int
(
hours
[
i
])
<
14
or
int
(
hours
[
i
])
>=
17
and
int
(
hours
[
i
])
<
20
or
int
(
hours
[
i
])
>=
5
and
int
(
hours
[
i
])
<
10
):
statesricecook_off
.
append
(
"电饭煲关闭"
)
timericecook_off
.
append
(
timer
[
i
])
if
1000
*
(
his_p
[
-
1
]
-
now_p
[
0
])
>
max
(
params
[
3
:])
-
50
and
(
int
(
hours
[
i
])
>=
10
and
int
(
hours
[
i
])
<
14
or
int
(
hours
[
i
])
>=
17
and
int
(
hours
[
i
])
<
20
or
int
(
int
(
hours
[
i
])
>=
10
and
int
(
hours
[
i
])
<
14
or
int
(
hours
[
i
])
>=
17
and
int
(
hours
[
i
])
<
20
or
int
(
hours
[
i
])
>=
5
and
int
(
hours
[
i
])
<
10
):
stateselectro_off
.
append
(
"电磁炉关闭"
)
timeelectro_off
.
append
(
timer
[
i
])
...
...
unify_api/modules/shidianu/service/refrigAnalysis.py
View file @
9d4a6d83
...
...
@@ -2,51 +2,76 @@ import time
def
findStart
(
timerefrig
=
"timerefrig"
,
timerefrig_last
=
""
,
ahead
=
0
):
timerefrig_last_stemp
=
int
(
time
.
mktime
(
time
.
strptime
(
timerefrig_last
,
"
%
Y-
%
m-
%
d
%
H:
%
M:
%
S"
)))
timerefrig_stemp
=
[
int
(
time
.
mktime
(
time
.
strptime
(
each_time
,
"
%
Y-
%
m-
%
d
%
H:
%
M:
%
S"
)))
for
each_time
in
timerefrig
]
timerefrig_last_stemp
=
int
(
time
.
mktime
(
time
.
strptime
(
timerefrig_last
,
"
%
Y-
%
m-
%
d
%
H:
%
M:
%
S"
)))
timerefrig_stemp
=
[
int
(
time
.
mktime
(
time
.
strptime
(
each_time
,
"
%
Y-
%
m-
%
d
%
H:
%
M:
%
S"
)))
for
each_time
in
timerefrig
]
if
ahead
<
len
(
timerefrig
)
-
1
:
time_substruct
=
[
1000000
if
timerefrig_stemp
[
each_timerefrig_stemp
]
-
timerefrig_last_stemp
<=
0
or
each_timerefrig_stemp
<
ahead
else
timerefrig_stemp
[
each_timerefrig_stemp
]
-
timerefrig_last_stemp
for
each_timerefrig_stemp
timerefrig_stemp
[
each_timerefrig_stemp
]
-
timerefrig_last_stemp
for
each_timerefrig_stemp
in
range
(
len
(
timerefrig_stemp
))]
else
:
time_substruct
=
[
1000000
if
timerefrig_last_stemp
-
timerefrig_stemp
[
each_timerefrig_stemp
]
<=
0
or
each_timerefrig_stemp
<
ahead
else
timerefrig_last_stemp
-
timerefrig_stemp
[
each_timerefrig_stemp
]
for
each_timerefrig_stemp
in
range
(
len
(
timerefrig_stemp
))]
each_timerefrig_stemp
]
for
each_timerefrig_stemp
in
range
(
len
(
timerefrig_stemp
))]
index
=
time_substruct
.
index
(
min
(
time_substruct
))
return
index
def
refrigAnalysis
(
statesrefrig
=
""
,
statesrefrig_off
=
""
,
timerefrig
=
""
,
timerefrig_off
=
""
,
eachdata_pow
=
""
,
eachdata_cur
=
""
,
timer
=
""
):
timerefrig_chang
=
[
each
.
split
(
" "
)[
1
][:
-
3
]
.
split
(
":"
)
for
each
in
timerefrig
]
timerefrig_hour
=
[
each
[
0
]
for
each
in
timerefrig_chang
]
timerefrig_minute
=
[
each
[
1
]
for
each
in
timerefrig_chang
]
timerefrig_off_chang
=
[
each
.
split
(
" "
)[
1
][:
-
3
]
.
split
(
":"
)
for
each
in
timerefrig_off
]
timerefrig_off_hour
=
[
each
[
0
]
for
each
in
timerefrig_off_chang
]
timerefrig_off_minute
=
[
each
[
1
]
for
each
in
timerefrig_off_chang
]
refrigRunStages
=
[]
if
int
(
timerefrig_off_hour
[
-
1
])
>=
22
and
int
(
timerefrig_off_hour
[
0
])
<=
2
:
def
refrigAnalysis
(
statesrefrig
=
""
,
statesrefrig_off
=
""
,
timerefrig
=
""
,
timerefrig_off
=
""
,
eachdata_pow
=
""
,
eachdata_cur
=
""
,
timer
=
""
):
timerefrig_chang
=
[
each
.
split
(
" "
)[
1
][:
-
3
]
.
split
(
":"
)
for
each
in
timerefrig
]
timerefrig_hour
=
[
each
[
0
]
for
each
in
timerefrig_chang
]
timerefrig_minute
=
[
each
[
1
]
for
each
in
timerefrig_chang
]
timerefrig_off_chang
=
[
each
.
split
(
" "
)[
1
][:
-
3
]
.
split
(
":"
)
for
each
in
timerefrig_off
]
timerefrig_off_hour
=
[
each
[
0
]
for
each
in
timerefrig_off_chang
]
timerefrig_off_minute
=
[
each
[
1
]
for
each
in
timerefrig_off_chang
]
refrigRunStages
=
[]
if
int
(
timerefrig_off_hour
[
-
1
])
>=
22
and
int
(
timerefrig_off_hour
[
0
])
<=
2
:
refrigRunStages
.
append
(
timerefrig
[
0
])
refrigRunStages
.
append
(
timerefrig_off
[
-
1
])
else
:
refrigRunStages
.
append
(
timerefrig
[
0
])
for
each_off
in
range
(
1
,
len
(
timerefrig_off
)):
for
each_off
in
range
(
1
,
len
(
timerefrig_off
)):
# if each_off==len(timerefrig_off)-1:
print
(
"timerefrig_off_hour"
,
timerefrig_off_hour
)
print
(
"timerefrig_off_hour"
,
timerefrig_off_hour
)
if
len
(
timerefrig_off_hour
)
>=
3
and
int
(
timerefrig_off_hour
[
-
1
])
-
int
(
timerefrig_off_hour
[
-
2
])
<=
2
and
int
(
timerefrig_off_hour
[
-
2
])
-
int
(
timerefrig_off_hour
[
-
3
])
<=
2
and
each_off
==
len
(
timerefrig_off_hour
)
-
1
:
if
len
(
timerefrig_off_hour
)
>=
3
and
int
(
timerefrig_off_hour
[
-
1
])
-
int
(
timerefrig_off_hour
[
-
2
])
<=
2
and
int
(
timerefrig_off_hour
[
-
2
])
-
int
(
timerefrig_off_hour
[
-
3
])
<=
2
and
each_off
==
len
(
timerefrig_off_hour
)
-
1
:
refrigRunStages
.
append
(
timerefrig_off
[
each_off
])
if
len
(
timerefrig_off_hour
)
>=
2
and
int
(
timerefrig_off_hour
[
-
1
])
-
int
(
timerefrig_off_hour
[
-
2
])
<=
2
and
each_off
==
len
(
timerefrig_off_hour
)
-
1
:
if
len
(
timerefrig_off_hour
)
>=
2
and
int
(
timerefrig_off_hour
[
-
1
])
-
int
(
timerefrig_off_hour
[
-
2
])
<=
2
and
each_off
==
len
(
timerefrig_off_hour
)
-
1
:
refrigRunStages
.
append
(
timerefrig_off
[
each_off
])
if
int
(
timerefrig_off_hour
[
each_off
])
-
int
(
timerefrig_off_hour
[
each_off
-
1
])
<=
2
or
int
(
timerefrig_off_hour
[
each_off
])
<
6
or
int
(
timerefrig_off_hour
[
each_off
])
>
21
:
if
int
(
timerefrig_off_hour
[
each_off
])
-
int
(
timerefrig_off_hour
[
each_off
-
1
])
<=
2
or
int
(
timerefrig_off_hour
[
each_off
])
<
6
or
int
(
timerefrig_off_hour
[
each_off
])
>
21
:
continue
else
:
if
each_off
<
len
(
timerefrig
)
-
1
:
refrigRunStages
.
append
(
timerefrig_off
[
each_off
-
1
])
findStart1
=
findStart
(
timerefrig
=
timerefrig
,
timerefrig_last
=
timerefrig_off
[
each_off
-
1
],
ahead
=
each_off
)
if
each_off
<
len
(
timerefrig
)
-
1
:
refrigRunStages
.
append
(
timerefrig_off
[
each_off
-
1
])
findStart1
=
findStart
(
timerefrig
=
timerefrig
,
timerefrig_last
=
timerefrig_off
[
each_off
-
1
],
ahead
=
each_off
)
refrigRunStages
.
append
(
timerefrig
[
findStart1
])
else
:
refrigRunStages
.
append
(
timerefrig_off
[
each_off
])
...
...
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