Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
O
Opencps
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
WirelessInformationCollaborate
Opencps
Commits
56bffe85
Commit
56bffe85
authored
Apr 15, 2018
by
joliu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
完成通过数据库获取计算任务的代码
parent
f654462d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
88 additions
and
0 deletions
+88
-0
hfv/controllMatrix.py
hfv/controllMatrix.py
+88
-0
No files found.
hfv/controllMatrix.py
0 → 100644
View file @
56bffe85
'''
***********************************************************
* 控制矩阵数据库的相关函数 *
* 1. resulovetable *
* author: joliu<joliu@s-an.org> *
* date: 2018-4-14 *
***********************************************************
'''
import
sqlite3
import
numpy
as
np
import
json
# 插入任务到数据库
def
insertDB
(
taskMatrix
,
inputTypeList
,
deviceList
,
status
):
sql
=
"insert into resulovetable
\
(taskmatrix,inputtype, status, devicelist) values
\
('%s','%s',%d,'%s')"
%
(
taskMatrix
,
inputTypeList
,
status
,
deviceList
)
print
(
sendToDB
(
sql
))
def
sendToDB
(
sql
):
try
:
conn
=
sqlite3
.
connect
(
"task.db"
)
cursor
=
conn
.
cursor
()
cursor
.
execute
(
sql
)
status
=
1
if
sql
.
split
(
' '
)[
0
]
==
'select'
:
output
=
cursor
.
fetchall
()
else
:
conn
.
commit
()
output
=
'success'
except
sqlite3
.
Error
as
err_msg
:
(
status
,
output
)
=
(
-
1
,
err_msg
)
except
Exception
.
Error
as
err_msg
:
(
status
,
output
)
=
(
-
1
,
err_msg
)
finally
:
cursor
.
close
()
conn
.
close
()
return
(
status
,
output
)
def
getTaskFromDB
():
# 查询最新一条可用任务
sql
=
'select * from resulovetable order by id desc limit 0,1'
(
status
,
output
)
=
sendToDB
(
sql
)
return
output
[
0
]
def
getTaskFromDBByID
(
id
):
# 从数据库中获取数据
sql
=
'select * from resulovetable where id=%d'
%
id
(
status
,
output
)
=
sendToDB
(
sql
)
return
output
[
0
]
def
showDB
():
# 打印数据库内容
sql
=
"select * from resulovetable"
print
(
sendToDB
(
sql
))
def
clearDB
():
# 清空数据库
sql
=
"delete from resulovetable"
print
(
sendToDB
(
sql
))
if
__name__
==
'__main__'
:
inputTask
=
np
.
array
([[
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
,
0
,
1
,
0
,
0
,
0
],
\
[
0
,
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
]])
inputTypeList
=
np
.
array
([
1
,
3
,
2
,
3
,
0
,
4
,
4
,
4
])
inputDeviceData
=
np
.
array
([
0
,
0
,
0
,
0
,
0
,
1
,
1
,
0
])
jsnInputTask
=
json
.
dumps
(
inputTask
.
tolist
())
jsnInputTypeList
=
json
.
dumps
(
inputTypeList
.
tolist
())
deviceList
=
[
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
"dht102"
,
"dht103"
,
"dht104"
]
jsnDeviceList
=
json
.
dumps
(
deviceList
)
# insertDB(jsnInputTask, jsnInputTypeList, jsnDeviceList, 1)
showDB
()
(
id
,
inputTask
,
inputTypeList
,
status
,
deviceList
)
=
getDataFromDB
(
8
)
print
(
inputTask
)
# clearDB()
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