Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
juga
sbws
Commits
40a76cc7
Commit
40a76cc7
authored
Aug 29, 2018
by
juga
Browse files
Reorder methods in BWV3Header
1. magic methods 2. classmethods 3. staticmethods 4. properties 5. methods
parent
aea806bf
Changes
1
Hide whitespace changes
Inline
Side-by-side
sbws/lib/v3bwfile.py
View file @
40a76cc7
...
@@ -109,52 +109,25 @@ class V3BWHeader(object):
...
@@ -109,52 +109,25 @@ class V3BWHeader(object):
[
setattr
(
self
,
k
,
v
)
for
k
,
v
in
kwargs
.
items
()
[
setattr
(
self
,
k
,
v
)
for
k
,
v
in
kwargs
.
items
()
if
k
in
EXTRA_ARG_KEYVALUES
]
if
k
in
EXTRA_ARG_KEYVALUES
]
@
property
def
keyvalue_unordered_tuple_ls
(
self
):
"""Return list of KeyValue tuples that do not have specific order."""
# sort the list to generate determinist headers
keyvalue_tuple_ls
=
sorted
([(
k
,
v
)
for
k
,
v
in
self
.
__dict__
.
items
()
if
k
in
UNORDERED_KEYVALUES
])
return
keyvalue_tuple_ls
@
property
def
keyvalue_tuple_ls
(
self
):
"""Return list of all KeyValue tuples"""
return
[(
'version'
,
self
.
version
)]
+
self
.
keyvalue_unordered_tuple_ls
@
property
def
keyvalue_v110str_ls
(
self
):
"""Return KeyValue list of strings following spec v1.1.0."""
keyvalues
=
[
self
.
timestamp
]
+
[
KEYVALUE_SEP_V110
.
join
([
k
,
v
])
for
k
,
v
in
self
.
keyvalue_tuple_ls
]
return
keyvalues
@
property
def
strv110
(
self
):
"""Return header string following spec v1.1.0."""
header_str
=
LINE_SEP
.
join
(
self
.
keyvalue_v110str_ls
)
+
LINE_SEP
+
\
LINE_TERMINATOR
return
header_str
@
property
def
keyvalue_v200_ls
(
self
):
"""Return KeyValue list of strings following spec v2.0.0."""
keyvalue
=
[
self
.
timestamp
]
+
[
KEYVALUE_SEP_V200
.
join
([
k
,
v
])
for
k
,
v
in
self
.
keyvalue_tuple_ls
]
return
keyvalue
@
property
def
strv200
(
self
):
"""Return header string following spec v2.0.0."""
header_str
=
LINE_SEP
.
join
(
self
.
keyvalue_v200_ls
)
+
LINE_SEP
+
\
LINE_TERMINATOR
return
header_str
def
__str__
(
self
):
def
__str__
(
self
):
if
self
.
version
==
'1.1.0'
:
if
self
.
version
==
'1.1.0'
:
return
self
.
strv110
return
self
.
strv110
return
self
.
strv200
return
self
.
strv200
@
classmethod
def
from_results
(
cls
,
conf
,
results
):
kwargs
=
dict
()
latest_bandwidth
=
cls
.
latest_bandwidth_from_results
(
results
)
earliest_bandwidth
=
cls
.
earliest_bandwidth_from_results
(
results
)
generator_started
=
cls
.
generator_started_from_file
(
conf
)
timestamp
=
str
(
latest_bandwidth
)
kwargs
[
'latest_bandwidth'
]
=
unixts_to_isodt_str
(
latest_bandwidth
)
kwargs
[
'earliest_bandwidth'
]
=
unixts_to_isodt_str
(
earliest_bandwidth
)
if
generator_started
is
not
None
:
kwargs
[
'generator_started'
]
=
generator_started
h
=
cls
(
timestamp
,
**
kwargs
)
return
h
@
classmethod
@
classmethod
def
from_lines_v110
(
cls
,
lines
):
def
from_lines_v110
(
cls
,
lines
):
"""
"""
...
@@ -184,10 +157,6 @@ class V3BWHeader(object):
...
@@ -184,10 +157,6 @@ class V3BWHeader(object):
assert
isinstance
(
text
,
str
)
assert
isinstance
(
text
,
str
)
return
self
.
from_lines_v110
(
text
.
split
(
LINE_SEP
))
return
self
.
from_lines_v110
(
text
.
split
(
LINE_SEP
))
@
property
def
num_lines
(
self
):
return
len
(
self
.
__str__
().
split
(
LINE_SEP
))
@
staticmethod
@
staticmethod
def
generator_started_from_file
(
conf
):
def
generator_started_from_file
(
conf
):
'''
'''
...
@@ -208,19 +177,50 @@ class V3BWHeader(object):
...
@@ -208,19 +177,50 @@ class V3BWHeader(object):
def
earliest_bandwidth_from_results
(
results
):
def
earliest_bandwidth_from_results
(
results
):
return
round
(
min
([
r
.
time
for
fp
in
results
for
r
in
results
[
fp
]]))
return
round
(
min
([
r
.
time
for
fp
in
results
for
r
in
results
[
fp
]]))
@
classmethod
@
property
def
from_results
(
cls
,
conf
,
results
):
def
keyvalue_unordered_tuple_ls
(
self
):
kwargs
=
dict
()
"""Return list of KeyValue tuples that do not have specific order."""
latest_bandwidth
=
cls
.
latest_bandwidth_from_results
(
results
)
# sort the list to generate determinist headers
earliest_bandwidth
=
cls
.
earliest_bandwidth_from_results
(
results
)
keyvalue_tuple_ls
=
sorted
([(
k
,
v
)
for
k
,
v
in
self
.
__dict__
.
items
()
generator_started
=
cls
.
generator_started_from_file
(
conf
)
if
k
in
UNORDERED_KEYVALUES
])
timestamp
=
str
(
latest_bandwidth
)
return
keyvalue_tuple_ls
kwargs
[
'latest_bandwidth'
]
=
unixts_to_isodt_str
(
latest_bandwidth
)
kwargs
[
'earliest_bandwidth'
]
=
unixts_to_isodt_str
(
earliest_bandwidth
)
@
property
if
generator_started
is
not
None
:
def
keyvalue_tuple_ls
(
self
):
kwargs
[
'generator_started'
]
=
generator_started
"""Return list of all KeyValue tuples"""
h
=
cls
(
timestamp
,
**
kwargs
)
return
[(
'version'
,
self
.
version
)]
+
self
.
keyvalue_unordered_tuple_ls
return
h
@
property
def
keyvalue_v110str_ls
(
self
):
"""Return KeyValue list of strings following spec v1.1.0."""
keyvalues
=
[
self
.
timestamp
]
+
[
KEYVALUE_SEP_V110
.
join
([
k
,
v
])
for
k
,
v
in
self
.
keyvalue_tuple_ls
]
return
keyvalues
@
property
def
strv110
(
self
):
"""Return header string following spec v1.1.0."""
header_str
=
LINE_SEP
.
join
(
self
.
keyvalue_v110str_ls
)
+
LINE_SEP
+
\
LINE_TERMINATOR
return
header_str
@
property
def
keyvalue_v200_ls
(
self
):
"""Return KeyValue list of strings following spec v2.0.0."""
keyvalue
=
[
self
.
timestamp
]
+
[
KEYVALUE_SEP_V200
.
join
([
k
,
v
])
for
k
,
v
in
self
.
keyvalue_tuple_ls
]
return
keyvalue
@
property
def
strv200
(
self
):
"""Return header string following spec v2.0.0."""
header_str
=
LINE_SEP
.
join
(
self
.
keyvalue_v200_ls
)
+
LINE_SEP
+
\
LINE_TERMINATOR
return
header_str
@
property
def
num_lines
(
self
):
return
len
(
self
.
__str__
().
split
(
LINE_SEP
))
class
V3BWLine
(
object
):
class
V3BWLine
(
object
):
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a 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