Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
anselm
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
vaclab
anselm
Commits
875a208e
Commit
875a208e
authored
6 years ago
by
wactbprot
Browse files
Options
Downloads
Patches
Plain Diff
redis
parent
e141e54c
No related branches found
No related tags found
No related merge requests found
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
README.rst
+2
-1
2 additions, 1 deletion
README.rst
anselm.py
+2
-9
2 additions, 9 deletions
anselm.py
anselm/config.json
+5
-1
5 additions, 1 deletion
anselm/config.json
anselm/system.py
+27
-2
27 additions, 2 deletions
anselm/system.py
anselm/worker.py
+7
-7
7 additions, 7 deletions
anselm/worker.py
with
43 additions
and
20 deletions
README.rst
+
2
−
1
View file @
875a208e
...
@@ -6,6 +6,7 @@ anselm
...
@@ -6,6 +6,7 @@ anselm
requirements
requirements
============
============
* couchdb (long-term memory, ltm)
* couchdb
* redis
* PyQt5
* PyQt5
This diff is collapsed.
Click to expand it.
anselm.py
+
2
−
9
View file @
875a208e
...
@@ -176,15 +176,8 @@ class Anselm(System):
...
@@ -176,15 +176,8 @@ class Anselm(System):
self
.
log
.
error
(
"
no task selected at line {}
"
.
format
(
line
))
self
.
log
.
error
(
"
no task selected at line {}
"
.
format
(
line
))
if
task
:
if
task
:
self
.
log
.
debug
(
"
task is: {}
"
.
format
(
task
))
self
.
log
.
debug
(
"
task is: {}
"
.
format
(
task
))
Thread
(
target
=
self
.
worker
.
run
,
args
=
(
task
,
line
,
self
.
result_callback
)).
start
()
Thread
(
target
=
self
.
worker
.
run
,
args
=
(
task
,
line
,)).
start
()
def
result_callback
(
self
,
line
,
results
):
self
.
log
.
info
(
'
result: {} at line {}
'
.
format
(
results
,
line
))
text
=
""
for
_
,
result
in
enumerate
(
results
):
text
=
"
{} {} {}
"
.
format
(
text
,
result
.
get
(
'
Value
'
),
result
.
get
(
'
Unit
'
))
print
(
text
)
def
std_selected
(
self
,
combo
):
def
std_selected
(
self
,
combo
):
self
.
state
[
'
standard
'
]
=
combo
.
currentText
()
self
.
state
[
'
standard
'
]
=
combo
.
currentText
()
self
.
log
.
info
(
"
select standard {}
"
.
format
(
self
.
state
.
get
(
'
standard
'
)))
self
.
log
.
info
(
"
select standard {}
"
.
format
(
self
.
state
.
get
(
'
standard
'
)))
...
...
This diff is collapsed.
Click to expand it.
anselm/config.json
+
5
−
1
View file @
875a208e
...
@@ -6,7 +6,11 @@
...
@@ -6,7 +6,11 @@
"view"
:
{
"view"
:
{
"auxobj"
:
"share/AuxObject"
"auxobj"
:
"share/AuxObject"
}
}
},
},
"redis"
:{
"host"
:
"localhost"
,
"port"
:
6379
,
"db"
:
0
},
"relay"
:{
"relay"
:{
"host"
:
"localhost"
,
"host"
:
"localhost"
,
"port"
:
55555
"port"
:
55555
...
...
This diff is collapsed.
Click to expand it.
anselm/system.py
+
27
−
2
View file @
875a208e
...
@@ -3,6 +3,7 @@ import coloredlogs
...
@@ -3,6 +3,7 @@ import coloredlogs
import
logging
import
logging
import
datetime
import
datetime
import
time
import
time
import
redis
...
@@ -21,7 +22,8 @@ class System:
...
@@ -21,7 +22,8 @@ class System:
# open and parse config file
# open and parse config file
with
open
(
'
anselm/config.json
'
)
as
json_config_file
:
with
open
(
'
anselm/config.json
'
)
as
json_config_file
:
self
.
config
=
json
.
load
(
json_config_file
)
self
.
config
=
json
.
load
(
json_config_file
)
self
.
init_log
()
self
.
init_log
()
self
.
init_kv
()
def
init_log
(
self
):
def
init_log
(
self
):
log_level
=
self
.
config
.
get
(
'
loglevel
'
)
log_level
=
self
.
config
.
get
(
'
loglevel
'
)
...
@@ -31,6 +33,29 @@ class System:
...
@@ -31,6 +33,29 @@ class System:
log_level
=
self
.
log_level
log_level
=
self
.
log_level
coloredlogs
.
install
(
fmt
=
self
.
log_fmt
,
level
=
log_level
,
logger
=
self
.
log
)
coloredlogs
.
install
(
fmt
=
self
.
log_fmt
,
level
=
log_level
,
logger
=
self
.
log
)
def
init_kv
(
self
):
db_dict
=
self
.
config
.
get
(
'
redis
'
)
port
=
db_dict
.
get
(
'
port
'
)
host
=
db_dict
.
get
(
'
host
'
)
db
=
db_dict
.
get
(
'
db
'
)
self
.
r
=
redis
.
StrictRedis
(
host
=
host
,
port
=
port
,
db
=
db
)
self
.
log
.
info
(
"
key value store ok
"
)
def
aset
(
self
,
key_prefix
,
line
,
value
):
k
=
'
{}@{}
'
.
format
(
key_prefix
,
line
)
if
isinstance
(
value
,
dict
)
or
isinstance
(
value
,
list
):
v
=
json
.
dumps
(
value
)
self
.
r
.
set
(
k
,
v
)
def
aget
(
self
,
key_prefix
,
line
):
k
=
'
{}@{}
'
.
format
(
key_prefix
,
line
)
v
=
self
.
r
.
get
(
k
)
return
json
.
loads
(
v
)
def
now
(
self
):
def
now
(
self
):
return
datetime
.
datetime
.
now
().
isoformat
().
replace
(
'
T
'
,
'
'
)
return
datetime
.
datetime
.
now
().
isoformat
().
replace
(
'
T
'
,
'
'
)
This diff is collapsed.
Click to expand it.
anselm/worker.py
+
7
−
7
View file @
875a208e
...
@@ -14,23 +14,23 @@ class Worker(System):
...
@@ -14,23 +14,23 @@ class Worker(System):
self
.
headers
=
{
'
content-type
'
:
'
application/json
'
}
self
.
headers
=
{
'
content-type
'
:
'
application/json
'
}
def
run
(
self
,
task
,
line
,
callback
=
None
):
def
run
(
self
,
task
,
line
):
acc
=
task
[
'
Action
'
]
acc
=
task
[
'
Action
'
]
if
acc
==
"
TCP
"
:
if
acc
==
"
TCP
"
:
self
.
relay_worker
(
task
,
line
,
callback
)
self
.
relay_worker
(
task
,
line
)
if
acc
==
"
VXI11
"
:
if
acc
==
"
VXI11
"
:
self
.
relay_worker
(
task
,
line
,
callback
)
self
.
relay_worker
(
task
,
line
)
def
relay_worker
(
self
,
task
,
line
,
callback
):
def
relay_worker
(
self
,
task
,
line
):
req
=
requests
.
post
(
self
.
relay_url
,
data
=
json
.
dumps
(
task
),
headers
=
self
.
headers
)
req
=
requests
.
post
(
self
.
relay_url
,
data
=
json
.
dumps
(
task
),
headers
=
self
.
headers
)
res
=
req
.
json
()
res
=
req
.
json
()
if
'
Result
'
in
res
:
if
'
Result
'
in
res
:
if
callable
(
callback
):
self
.
aset
(
'
result
'
,
line
,
res
[
'
Result
'
])
callback
(
line
,
res
[
'
Result
'
])
print
(
res
[
'
Result
'
])
print
(
res
[
'
Result
'
])
if
'
ToExchange
'
in
res
:
if
'
ToExchange
'
in
res
:
self
.
aset
(
'
exchange
'
,
line
,
res
[
'
ToExchange
'
])
print
(
res
[
'
ToExchange
'
])
print
(
res
[
'
ToExchange
'
])
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment