Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Mattia Rizzolo
nm.debian.org
Commits
f2875a9a
Commit
f2875a9a
authored
Aug 21, 2015
by
Enrico Zini
Browse files
Removed dependency on numpy
parent
499a2912
Changes
2
Hide whitespace changes
Inline
Side-by-side
README.md
View file @
f2875a9a
...
...
@@ -6,7 +6,7 @@ Debian NM Front Desk web application
apt-get install python-django python-ldap python-psycopg2 python-xapian
\
python-debian python-django-south python-markdown
\
python-debiancontributors
python-numpy
python-debiancontributors
# https://github.com/spanezz/django-housekeeping
git clone https://github.com/spanezz/django-housekeeping
...
...
backend/management/commands/process_mbox_stats.py
View file @
f2875a9a
...
...
@@ -29,11 +29,27 @@ import datetime
import
time
import
json
import
os
import
numpy
log
=
logging
.
getLogger
(
__name__
)
def
median
(
l
):
"""
Compute the median of a sequence of numbers
"""
if
not
l
:
return
None
l
=
sorted
(
l
)
if
len
(
l
)
==
1
:
return
l
[
0
]
idx
,
is_odd
=
divmod
(
len
(
l
)
-
1
,
2
)
if
is_odd
:
return
l
[
idx
]
else
:
return
(
l
[
idx
]
+
l
[
idx
+
1
])
/
2.0
class
Interaction
(
object
):
data
=
{
'emails'
:
{},
'process'
:
{}}
unsort_data
=
[]
...
...
@@ -84,41 +100,18 @@ class Interaction(object):
d
[
'From'
]
=
d
[
'From'
]
+
"@debian.org"
self
.
unsort_data
.
append
(
d
)
@
classmethod
def
_average
(
cls
,
process_key
):
if
process_key
is
not
None
:
if
process_key
in
cls
.
data
[
'process'
]:
d
=
cls
.
data
[
'process'
][
process_key
]
log
.
debug
(
"response_time: %s"
%
d
[
'response_time'
])
d
[
'mean'
]
=
numpy
.
mean
(
d
[
'response_time'
])
d
[
'mean_fancy'
]
=
"%s"
%
datetime
.
timedelta
(
seconds
=
numpy
.
int_
(
d
[
'mean'
]))
log
.
debug
(
"%s -> mean: %s[%s]"
%
(
process_key
,
d
[
'mean'
],
d
[
'mean_fancy'
]))
else
:
for
k
,
d
in
cls
.
data
[
'emails'
].
iteritems
():
if
d
[
'num_mails'
]
>
1
:
d
[
'mean'
]
=
numpy
.
mean
(
d
[
'response_time'
])
d
[
'mean_fancy'
]
=
"%s"
%
datetime
.
timedelta
(
seconds
=
numpy
.
int_
(
d
[
'mean'
]))
@
classmethod
def
_median
(
cls
,
process_key
):
if
process_key
is
not
None
:
if
process_key
in
cls
.
data
[
'process'
]:
d
=
cls
.
data
[
'process'
][
process_key
]
log
.
debug
(
"response_time: %s"
%
d
[
'response_time'
])
d
[
'median'
]
=
numpy
.
median
(
d
[
'response_time'
])
d
[
'median_fancy'
]
=
"%s"
%
datetime
.
timedelta
(
seconds
=
numpy
.
int_
(
d
[
'median'
]))
log
.
debug
(
"%s -> median: %s[%s]"
%
(
process_key
,
d
[
'median'
],
d
[
'median_fancy'
]))
d
[
'median'
]
=
median
(
d
[
'response_time'
])
log
.
debug
(
"%s -> median: %s"
%
(
process_key
,
d
[
'median'
]))
else
:
for
k
,
d
in
cls
.
data
[
'emails'
].
iteritems
():
if
d
[
'num_mails'
]
>
1
:
d
[
'median'
]
=
numpy
.
median
(
d
[
'response_time'
])
d
[
'median_fancy'
]
=
"%s"
%
datetime
.
timedelta
(
seconds
=
numpy
.
int_
(
d
[
'median'
]))
d
[
'median'
]
=
median
(
d
[
'response_time'
])
def
generate_stats
(
self
,
process_key
):
self
.
sort_data
=
sorted
(
self
.
unsort_data
,
...
...
@@ -126,11 +119,9 @@ class Interaction(object):
self
.
unsort_data
=
[]
for
d
in
self
.
sort_data
:
self
.
_add
(
d
)
self
.
_average
(
process_key
)
self
.
_median
(
process_key
)
def
generate_email_stats
(
self
):
self
.
_average
(
None
)
self
.
_median
(
None
)
def
export
(
self
,
filename
):
...
...
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment