Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
GraceDB Server
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
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
IGWN Computing and Software
GraceDB
GraceDB Server
Commits
8678bf49
Commit
8678bf49
authored
14 years ago
by
Brian Moe
Browse files
Options
Downloads
Patches
Plain Diff
Changed manage/make_histograms to use matplotlib. Still very experimental
parent
cb5fb5e5
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
gracedb/management/commands/make_histograms.py
+90
-28
90 additions, 28 deletions
gracedb/management/commands/make_histograms.py
with
90 additions
and
28 deletions
gracedb/management/commands/make_histograms.py
+
90
−
28
View file @
8678bf49
...
@@ -4,6 +4,10 @@ from django.core.management.base import BaseCommand, NoArgsCommand
...
@@ -4,6 +4,10 @@ from django.core.management.base import BaseCommand, NoArgsCommand
from
django.db
import
connection
from
django.db
import
connection
from
django.utils
import
dateformat
from
django.utils
import
dateformat
import
datetime
import
matplotlib
matplotlib
.
use
(
"
Agg
"
)
import
matplotlib.pyplot
as
plot
from
gracedb.gracedb.models
import
Event
from
gracedb.gracedb.models
import
Event
...
@@ -13,18 +17,7 @@ from subprocess import Popen, PIPE, STDOUT
...
@@ -13,18 +17,7 @@ from subprocess import Popen, PIPE, STDOUT
DEST_DIR
=
"
/tmp/foo
"
DEST_DIR
=
"
/tmp/foo
"
MAX_X
=
1800
def
analysisTypes
():
cursor
=
connection
.
cursor
()
cursor
.
execute
(
"""
SELECT DISTINCT e.analysisType
FROM gracedb_event e, gracedb_group g
WHERE
(e.group_id <> g.id AND g.name =
'
Test
'
) AND
(e.analysisType <>
'
HWINJ
'
)
"""
)
return
[
x
[
0
]
for
x
in
cursor
.
fetchall
()]
class
Command
(
NoArgsCommand
):
class
Command
(
NoArgsCommand
):
...
@@ -38,7 +31,7 @@ class Command(NoArgsCommand):
...
@@ -38,7 +31,7 @@ class Command(NoArgsCommand):
start_week
=
now
-
timedelta
(
7
)
start_week
=
now
-
timedelta
(
7
)
start_month
=
now
-
timedelta
(
30
)
start_month
=
now
-
timedelta
(
30
)
PAST
=
9
1
PAST
=
1
10
now
-=
timedelta
(
PAST
)
now
-=
timedelta
(
PAST
)
start_day
-=
timedelta
(
PAST
)
start_day
-=
timedelta
(
PAST
)
start_week
-=
timedelta
(
PAST
)
start_week
-=
timedelta
(
PAST
)
...
@@ -46,22 +39,92 @@ class Command(NoArgsCommand):
...
@@ -46,22 +39,92 @@ class Command(NoArgsCommand):
time_ranges
=
[(
start_day
,
"
day
"
),
(
start_week
,
"
week
"
),
(
start_month
,
"
month
"
)]
time_ranges
=
[(
start_day
,
"
day
"
),
(
start_week
,
"
week
"
),
(
start_month
,
"
month
"
)]
valid_types
=
analysisTypes
()
annotations
=
{}
# Make the histograms, save as png's.
for
atype
,
atype_name
in
Event
.
ANALYSIS_TYPE_CHOICES
:
for
atype
,
atype_name
in
Event
.
ANALYSIS_TYPE_CHOICES
:
if
atype
not
in
valid_types
:
annotations
[
atype
]
=
{}
continue
for
start_time
,
time_range
in
time_ranges
:
for
start_time
,
time_range
in
time_ranges
:
try
:
note
=
{}
label
=
"
Latencies for %s Events
"
%
atype_name
fname
=
os
.
path
.
join
(
DEST_DIR
,
"
%s-%s.png
"
%
(
atype
,
time_range
))
except
KeyError
:
note
[
'
fname
'
]
=
fname
label
=
"
Bad analysis type: %s
"
%
atype
data
=
Event
.
objects
.
filter
(
analysisType
=
atype
,
#labels = [label, "%s previous to %s" % (time_range, str(now))]
created__range
=
[
start_time
,
now
],
labels
=
[
label
,
"
%s previous to %s
"
%
(
time_range
,
dateformat
.
format
(
now
,
settings
.
DATE_FORMAT
))]
gpstime__gt
=
0
)
d
=
histogramData
(
atype
,
start_time
,
now
)
data
=
[
e
.
reportingLatency
()
for
e
in
data
]
h
=
histogramImage
(
d
,
labels
)
note
[
'
count
'
]
=
data
.
count
()
data
=
[
d
for
d
in
data
if
d
<=
MAX_X
]
note
[
'
npoints
'
]
=
len
(
data
)
note
[
'
over
'
]
=
note
[
'
count
'
]
-
note
[
'
npoints
'
]
if
note
[
'
npoints
'
]
<=
0
:
try
:
os
.
unlink
(
fname
)
except
OSError
:
pass
else
:
makePlot
(
data
,
atype
,
maxx
=
MAX_X
).
savefig
(
fname
)
annotations
[
atype
][
time_range
]
=
note
def
makePlot
(
data
,
title
,
maxx
=
1800
,
facecolor
=
'
green
'
):
# over = 0
# for d in data:
# if d > maxx:
# over += 1
# data = [d for d in data if d <= maxx]
nbins
=
maxx
/
30
if
not
data
:
data
=
[
0
]
n
,
bins
,
patches
=
plot
.
hist
(
data
,
nbins
,
facecolor
=
facecolor
)
vmax
=
max
(
n
)
if
vmax
<=
10
:
vmax
=
10
elif
(
vmax
%
10
)
==
0
:
vmax
+=
10
else
:
vmax
+=
10
-
((
vmax
)
%
10
)
# if over:
# plural = ""
# if over > 1:
# plural = "s"
# title += "\nNOTE: %d event%s > %d seconds" % (over, plural, maxx)
plot
.
xlabel
(
'
Seconds
'
,
fontsize
=
20
)
plot
.
ylabel
(
'
Number of Events
'
,
fontsize
=
20
)
plot
.
title
(
title
)
plot
.
axis
([
0
,
maxx
,
0
,
vmax
])
plot
.
grid
(
True
)
return
plot
#=================================================================
# GNUPlot stuff. Currently unused.
#=================================================================
# Usage:
# d = gnuplotHistogramData(atype, start_time, now)
# h = gnuplotHistogramImage(d, labels)
#
# open(os.path.join(DEST_DIR,"%s-%s.png" % (atype, time_range)),"w").write(h)
def
analysisTypes
():
cursor
=
connection
.
cursor
()
cursor
.
execute
(
"""
SELECT DISTINCT e.analysisType
FROM gracedb_event e, gracedb_group g
WHERE
(e.group_id <> g.id AND g.name =
'
Test
'
) AND
(e.analysisType <>
'
HWINJ
'
)
"""
)
return
[
x
[
0
]
for
x
in
cursor
.
fetchall
()]
open
(
os
.
path
.
join
(
DEST_DIR
,
"
%s-%s.png
"
%
(
atype
,
time_range
)),
"
w
"
).
write
(
h
)
#label = "Latencies for %s Events" % Event.getTypeLabel(atype)
#label = "Latencies for %s Events" % Event.getTypeLabel(atype)
# data = Event.objects.extra(select={"date":"DATE(created)"}) \
# data = Event.objects.extra(select={"date":"DATE(created)"}) \
...
@@ -103,7 +166,7 @@ class GnuPlot(object):
...
@@ -103,7 +166,7 @@ class GnuPlot(object):
return
self
.
p
.
stdout
.
read
()
# XXX ugh. will it always read the whole thing?
return
self
.
p
.
stdout
.
read
()
# XXX ugh. will it always read the whole thing?
def
h
istogramData
(
atype
,
start
,
end
):
def
gnuplotH
istogramData
(
atype
,
start
,
end
):
hist_data
=
{}
hist_data
=
{}
data
=
Event
.
objects
.
filter
(
analysisType
=
atype
,
data
=
Event
.
objects
.
filter
(
analysisType
=
atype
,
...
@@ -120,7 +183,7 @@ def histogramData(atype, start, end):
...
@@ -120,7 +183,7 @@ def histogramData(atype, start, end):
return
hist_data
return
hist_data
def
h
istogramImage
(
data
,
labels
=
[],
size
=
(
400
,
200
)):
def
gnuplotH
istogramImage
(
data
,
labels
=
[],
size
=
(
400
,
200
)):
if
not
data
:
if
not
data
:
data
=
{
0
:
0
}
data
=
{
0
:
0
}
if
isinstance
(
labels
,
str
):
if
isinstance
(
labels
,
str
):
...
@@ -162,4 +225,3 @@ def histogramImage(data, labels=[], size=(400,200)):
...
@@ -162,4 +225,3 @@ def histogramImage(data, labels=[], size=(400,200)):
g
=
GnuPlot
(
plotCode
)
g
=
GnuPlot
(
plotCode
)
g
.
write_data
(
data
)
g
.
write_data
(
data
)
return
g
.
get_image
()
return
g
.
get_image
()
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