forked from IdentityPython/pyFF
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstats.py
45 lines (34 loc) · 955 Bytes
/
stats.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
"""
pyFF statistics module
"""
import logging
import time
__author__ = 'leifj'
# Initialize the repository
if not hasattr(logging, 'statistics'):
logging.statistics = {}
# Initialize my namespace
stats = logging.statistics.setdefault('pyFF Statistics', {})
# Initialize my namespaces scalars and collections
stats.update({
'Enabled': True,
'Start Time': time.time(),
'MD Requests': 0,
'Repository Update Time': None,
'Repository Size': 0,
'Requests/Second': lambda s: (
(s['MD Requests'] / (time.time() - s['Start Time']))),
})
# we keep this separate because the standard stats formatting isn't optimal
metadata = dict()
def set_metadata_info(name, info):
info.setdefault('Size', "(empty)")
info['URL'] = name
metadata[name] = info
def get_metadata_info(uri=None):
if uri is None:
return metadata
elif uri in metadata:
return metadata[uri]
else:
return dict()