Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
N
noblogsmv
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor 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
ai
noblogsmv
Commits
91ae5732
Commit
91ae5732
authored
11 years ago
by
ale
Browse files
Options
Downloads
Patches
Plain Diff
add little graph of the task state history
parent
51cf0093
No related branches found
No related tags found
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
noblogsmv/state.py
+32
-1
32 additions, 1 deletion
noblogsmv/state.py
noblogsmv/templates/index.html
+4
-0
4 additions, 0 deletions
noblogsmv/templates/index.html
noblogsmv/webapp.py
+31
-0
31 additions, 0 deletions
noblogsmv/webapp.py
setup.py
+1
-1
1 addition, 1 deletion
setup.py
with
68 additions
and
2 deletions
noblogsmv/state.py
+
32
−
1
View file @
91ae5732
...
@@ -253,6 +253,23 @@ class StateMachineWorker(threading.Thread):
...
@@ -253,6 +253,23 @@ class StateMachineWorker(threading.Thread):
return
info
return
info
class
RingBuffer
(
object
):
def
__init__
(
self
,
size
):
self
.
size
=
size
self
.
values
=
[
None
]
*
size
self
.
ptr
=
0
def
add
(
self
,
value
):
self
.
values
[
self
.
ptr
]
=
value
self
.
ptr
+=
1
if
self
.
ptr
>
self
.
size
:
self
.
ptr
=
0
def
get_values
(
self
):
return
values
[
self
.
ptr
:]
+
values
[:
self
.
ptr
]
class
StatsThread
(
threading
.
Thread
):
class
StatsThread
(
threading
.
Thread
):
def
__init__
(
self
,
sm
):
def
__init__
(
self
,
sm
):
...
@@ -285,6 +302,7 @@ class StateMachine(object):
...
@@ -285,6 +302,7 @@ class StateMachine(object):
self
.
num_workers
=
num_workers
self
.
num_workers
=
num_workers
self
.
threads
=
[]
self
.
threads
=
[]
self
.
state_count
=
{}
self
.
state_count
=
{}
self
.
state_count_ts
=
{}
def
load_data
(
self
,
input_stream
):
def
load_data
(
self
,
input_stream
):
with
transaction
(
self
.
db
)
as
session
:
with
transaction
(
self
.
db
)
as
session
:
...
@@ -321,9 +339,22 @@ class StateMachine(object):
...
@@ -321,9 +339,22 @@ class StateMachine(object):
with
readonly_transaction
(
self
.
db
)
as
session
:
with
readonly_transaction
(
self
.
db
)
as
session
:
return
self
.
db
.
dump
(
session
)
return
self
.
db
.
dump
(
session
)
def
get_current_state_count
(
self
):
return
self
.
state_count
def
get_ts_state_count
(
self
):
return
self
.
state_count_ts
def
compute_stats
(
self
):
def
compute_stats
(
self
):
with
readonly_transaction
(
self
.
db
)
as
session
:
with
readonly_transaction
(
self
.
db
)
as
session
:
self
.
state_count
=
self
.
db
.
count_by_state
(
session
)
state_count
=
self
.
db
.
count_by_state
(
session
)
state_count_ts
=
dict
(
self
.
state_count_ts
)
for
key
,
value
in
state_count
.
iteritems
():
if
key
not
in
state_count_ts
:
state_count_ts
[
key
]
=
RingBuffer
(
512
)
state_count_ts
[
key
].
add
(
value
)
self
.
state_count
=
state_count
self
.
state_count_ts
=
state_count_ts
def
run
(
self
):
def
run
(
self
):
input_queue
=
Queue
.
Queue
()
input_queue
=
Queue
.
Queue
()
...
...
This diff is collapsed.
Click to expand it.
noblogsmv/templates/index.html
+
4
−
0
View file @
91ae5732
...
@@ -69,6 +69,10 @@
...
@@ -69,6 +69,10 @@
{% endfor %}
{% endfor %}
</tbody>
</tbody>
</table>
</table>
<h4>
Task states over time:
</h4>
<img
src=
"{{ state_count_graph }}"
>
</div>
</div>
<div
class=
"tab-pane"
id=
"tasks"
>
<div
class=
"tab-pane"
id=
"tasks"
>
...
...
This diff is collapsed.
Click to expand it.
noblogsmv/webapp.py
+
31
−
0
View file @
91ae5732
...
@@ -7,6 +7,7 @@ import time
...
@@ -7,6 +7,7 @@ import time
import
urllib2
import
urllib2
from
noblogsmv
import
state
from
noblogsmv
import
state
from
flask
import
Flask
,
redirect
,
render_template
,
request
,
g
from
flask
import
Flask
,
redirect
,
render_template
,
request
,
g
from
pygooglechart
import
SimpleLineChart
app
=
Flask
(
__name__
)
app
=
Flask
(
__name__
)
...
@@ -17,6 +18,35 @@ def before_request_handler():
...
@@ -17,6 +18,35 @@ def before_request_handler():
g
.
sm
=
app
.
config
.
sm
g
.
sm
=
app
.
config
.
sm
_palette
=
[
0xffa07a
,
0xffdab9
,
0x5f9ea0
,
0xdda0dd
,
0x6294ed
,
0x8fbc8b
,
0xf0e68c
,
0xff69b4
,
0x4ce2d3
,
]
def
_mk_stats_graph
(
x
=
450
,
y
=
270
):
ts
=
g
.
sm
.
state_count_ts
chart
=
SimpleLineChart
(
x
,
y
)
labels
=
[]
for
key
,
rbuf
in
ts
.
iteritems
():
values
=
rbuf
.
get_values
()
chart
.
add_data
(
values
)
labels
.
append
(
key
)
nkeys
=
len
(
labels
)
chart
.
add_data
([
0
]
*
nkeys
)
chart
.
set_colours
(
_palette
[:
nkeys
])
for
i
in
xrange
(
nkeys
-
1
):
chart
.
add_fill_range
(
_palette
[
i
],
i
,
i
+
1
)
return
chart
.
get_url
()
@app.route
(
'
/
'
)
@app.route
(
'
/
'
)
def
index
():
def
index
():
now
=
time
.
time
()
now
=
time
.
time
()
...
@@ -26,6 +56,7 @@ def index():
...
@@ -26,6 +56,7 @@ def index():
return
render_template
(
'
index.html
'
,
return
render_template
(
'
index.html
'
,
state
=
cur_state
,
state
=
cur_state
,
state_count
=
state_count
,
state_count
=
state_count
,
state_count_graph
=
_mk_stats_graph
(),
worker_info
=
worker_info
,
worker_info
=
worker_info
,
now
=
time
.
time
())
now
=
time
.
time
())
...
...
This diff is collapsed.
Click to expand it.
setup.py
+
1
−
1
View file @
91ae5732
...
@@ -9,7 +9,7 @@ setup(
...
@@ -9,7 +9,7 @@ setup(
author
=
"
ale
"
,
author
=
"
ale
"
,
author_email
=
"
ale@incal.net
"
,
author_email
=
"
ale@incal.net
"
,
url
=
"
https://git.autistici.org/ai/noblogsmv
"
,
url
=
"
https://git.autistici.org/ai/noblogsmv
"
,
install_requires
=
[
'
Flask
'
,
'
SQLAlchemy
'
],
install_requires
=
[
'
Flask
'
,
'
SQLAlchemy
'
,
'
pygooglechart
'
],
setup_requires
=
[],
setup_requires
=
[],
zip_safe
=
True
,
zip_safe
=
True
,
packages
=
find_packages
(),
packages
=
find_packages
(),
...
...
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