Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
O
OpenXG-WIC-Opencpc
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenXG
OpenXG-WIC-Opencpc
Commits
624f7017
Commit
624f7017
authored
Apr 15, 2018
by
joliu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加输入矩阵即datacach的处理函数
parent
d187bcec
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
81 additions
and
11 deletions
+81
-11
hfv/controllMatrix.py
hfv/controllMatrix.py
+81
-11
No files found.
hfv/controllMatrix.py
View file @
624f7017
...
@@ -10,13 +10,50 @@
...
@@ -10,13 +10,50 @@
import
sqlite3
import
sqlite3
import
numpy
as
np
import
numpy
as
np
import
json
import
json
import
time
# 更新设备输入数据信息
def
updateDataCach
(
device
,
decideValue
):
# 检查是否存在该设备在预接收的列表中,如果不存在则丢弃
sql
=
"select * from datacach where deviceid='%s'"
%
device
(
status
,
output
)
=
sendToDB
(
sql
)
if
status
==
-
1
:
return
(
-
1
,
output
)
if
output
==
[]:
return
(
-
1
,
"drop this data"
)
sql
=
"update datacach set data='%s', updatetime='%s' where deviceid='%s'"
\
%
(
decideValue
,
time
.
time
(),
device
)
return
sendToDB
(
sql
)
# 插入设备输入节点信息
def
insertDataIntoDataCach
(
device
):
# 检查是否存在当前输入,如果有则插入
sql
=
"select * from datacach where deviceid='%s'"
%
device
(
status
,
output
)
=
sendToDB
(
sql
)
if
status
==
-
1
:
return
(
status
,
output
)
if
output
!=
[]:
return
(
1
,
'device has been added'
)
# 在配置输入信息节点时,使用该函数插入
sql
=
"insert into datacach (deviceid, updatetime, groupid) values
\
('%s', '%s', %d)"
%
(
device
,
time
.
time
(),
1
)
return
sendToDB
(
sql
)
# 获取输入数据库的内容
def
getDataFromDataCach
(
device
):
sql
=
"select data from datacach where deviceid='%s'"
%
device
return
sendToDB
(
sql
)
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 以下都是对output的数据库,即存储任务矩阵的数据库的操作
# 插入任务到数据库
# 插入任务到数据库
def
insertDB
(
taskMatrix
,
inputTypeList
,
deviceList
,
status
):
def
insertDB
(
taskMatrix
,
inputTypeList
,
deviceList
,
status
,
ctime
):
sql
=
"insert into resulovetable
\
sql
=
"insert into resulovetable
\
(taskmatrix,inputtype, status, devicelist) values
\
(taskmatrix,inputtype, status, devicelist
, ctime
) values
\
('%s','%s',%d,'%s'
)"
%
(
taskMatrix
,
inputTypeList
,
status
,
deviceList
)
('%s','%s',%d,'%s'
,%d)"
%
(
taskMatrix
,
inputTypeList
,
status
,
deviceList
,
ctime
)
print
(
sendToDB
(
sql
))
print
(
sendToDB
(
sql
))
...
@@ -52,10 +89,33 @@ def getTaskFromDBByID(id):
...
@@ -52,10 +89,33 @@ def getTaskFromDBByID(id):
(
status
,
output
)
=
sendToDB
(
sql
)
(
status
,
output
)
=
sendToDB
(
sql
)
return
output
[
0
]
return
output
[
0
]
def
getValueByNodeID
(
nodeid
):
# 获取devicelist
(
id
,
inputTask
,
inputTypeList
,
status
,
deviceList
,
ctime
)
=
getTaskFromDB
()
device
=
json
.
loads
(
deviceList
)[
nodeid
]
if
device
==
-
1
:
return
(
-
1
,
"not a device"
)
data
=
getDataFromDataCach
(
device
)
if
data
[
1
]
==
[]:
return
(
-
1
,
"not found device"
)
if
data
[
1
][
0
][
0
]
==
'-'
:
# 这里将缺省值都默认设置为0
return
(
1
,
0
)
return
(
1
,
int
(
data
[
1
][
0
][
0
]))
# 获取循环时间
def
getCircleTime
():
data
=
getTaskFromDB
()
if
data
==
():
return
5
return
data
[
5
]
def
showDB
():
def
showDB
():
# 打印数据库内容
# 打印数据库内容
sql
=
"select * from resulovetable"
# sql = "select * from resulovetable"
sql
=
"select * from datacach"
print
(
sendToDB
(
sql
))
print
(
sendToDB
(
sql
))
...
@@ -63,10 +123,14 @@ def clearDB():
...
@@ -63,10 +123,14 @@ def clearDB():
# 清空数据库
# 清空数据库
sql
=
"delete from resulovetable"
sql
=
"delete from resulovetable"
print
(
sendToDB
(
sql
))
print
(
sendToDB
(
sql
))
sql
=
"delete from datacach"
print
(
sendToDB
(
sql
))
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
'''
clearDB()
inputTask = np.array([[0,0,1,0,0,0,0,0],
\
inputTask = np.array([[0,0,1,0,0,0,0,0],
\
[0,0,1,0,0,0,0,0],
\
[0,0,1,0,0,0,0,0],
\
[0,0,0,1,0,0,0,0],
\
[0,0,0,1,0,0,0,0],
\
...
@@ -75,14 +139,20 @@ if __name__ == '__main__':
...
@@ -75,14 +139,20 @@ if __name__ == '__main__':
[1,0,0,0,0,0,0,0],
\
[1,0,0,0,0,0,0,0],
\
[1,0,0,0,0,0,0,0],
\
[1,0,0,0,0,0,0,0],
\
[0,1,0,0,0,0,0,0]])
[0,1,0,0,0,0,0,0]])
inputTypeList
=
np
.
array
([
1
,
3
,
2
,
3
,
0
,
4
,
4
,
4
])
inputTypeList = np.array([1,3,2,
5
,0,4,4,4])
inputDeviceData
=
np
.
array
([
0
,
0
,
0
,
0
,
0
,
1
,
1
,
0
])
inputDeviceData = np.array([0,0,0,
5
,0,1,1,0])
jsnInputTask = json.dumps(inputTask.tolist())
jsnInputTask = json.dumps(inputTask.tolist())
jsnInputTypeList = json.dumps(inputTypeList.tolist())
jsnInputTypeList = json.dumps(inputTypeList.tolist())
deviceList
=
[
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
"dht102"
,
"dht103"
,
"dht104"
]
deviceList = [-1,-1,-1,
"delay1","switch103"
,"dht102","dht103","dht104"]
jsnDeviceList = json.dumps(deviceList)
jsnDeviceList = json.dumps(deviceList)
# insertDB(jsnInputTask, jsnInputTypeList, jsnDeviceList, 1)
insertDB(jsnInputTask, jsnInputTypeList, jsnDeviceList, 1, 2)
'''
# 添加输入信息到输入信息缓存中
data
=
[[
"delay1"
,
"dht102"
,
"dht103"
,
"dht104"
],[
10
,
1
,
0
,
1
]]
for
i
in
range
(
len
(
data
[
0
])):
insertDataIntoDataCach
(
data
[
0
][
i
])
updateDataCach
(
data
[
0
][
i
],
data
[
1
][
i
])
showDB
()
showDB
()
(
id
,
inputTask
,
inputTypeList
,
status
,
deviceList
)
=
getDataFromDB
(
8
)
(
id
,
inputTask
,
inputTypeList
,
status
,
deviceList
,
ctime
)
=
getTaskFromDB
(
)
print
(
inputTask
)
#
print(inputTask)
# clearDB(
)
print
(
getValueByNodeID
(
6
)
)
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