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
d43e76f1
Commit
d43e76f1
authored
May 21, 2018
by
juga
Browse files
Move bw line class to v3bwfile.py
so that it close to the header and we can reuse methods/functions
parent
388bf748
Changes
2
Hide whitespace changes
Inline
Side-by-side
sbws/core/generate.py
View file @
d43e76f1
from
sbws.globals
import
(
fail_hard
,
is_initted
)
from
sbws.lib.v3bwfile
import
V3BwHeader
from
sbws.lib.v3bwfile
import
V3BwHeader
,
V3BWLine
from
sbws.lib.resultdump
import
ResultSuccess
from
sbws.lib.resultdump
import
load_recent_results_in_datadir
from
sbws.util.timestamp
import
unixts_to_isodt_str
...
...
@@ -11,26 +11,6 @@ import logging
log
=
logging
.
getLogger
(
__name__
)
# FIXME: move this to v3bwfile?
class
V3BWLine
:
# TODO: docstrings
def
__init__
(
self
,
fp
,
bw
,
nick
,
rtts
,
last_time
):
# TODO: asserts checking arg types
self
.
fp
=
fp
self
.
nick
=
nick
# convert to KiB and make sure the answer is at least 1
self
.
bw
=
max
(
round
(
bw
/
1024
),
1
)
# convert to ms
rtts
=
[
round
(
r
*
1000
)
for
r
in
rtts
]
self
.
rtt
=
round
(
median
(
rtts
))
self
.
time
=
unixts_to_isodt_str
(
last_time
)
def
__str__
(
self
):
frmt
=
'node_id=${fp} bw={sp} nick={n} rtt={rtt} time={t}'
return
frmt
.
format
(
fp
=
self
.
fp
,
sp
=
self
.
bw
,
n
=
self
.
nick
,
rtt
=
self
.
rtt
,
t
=
self
.
time
)
def
result_data_to_v3bw_line
(
data
,
fingerprint
):
assert
fingerprint
in
data
results
=
data
[
fingerprint
]
...
...
sbws/lib/v3bwfile.py
View file @
d43e76f1
...
...
@@ -3,6 +3,7 @@
(v3bw) used by bandwidth authorities."""
import
logging
from
statistics
import
median
from
sbws
import
__version__
from
sbws.globals
import
SPEC_VERSION
...
...
@@ -186,3 +187,20 @@ class V3BwHeader(object):
kwargs
[
'generator_started'
]
=
generator_started
h
=
cls
(
timestamp
,
**
kwargs
)
return
h
class
V3BWLine
:
def
__init__
(
self
,
fp
,
bw
,
nick
,
rtts
,
last_time
):
self
.
fp
=
fp
self
.
nick
=
nick
# convert to KiB and make sure the answer is at least 1
self
.
bw
=
max
(
round
(
bw
/
1024
),
1
)
# convert to ms
rtts
=
[
round
(
r
*
1000
)
for
r
in
rtts
]
self
.
rtt
=
round
(
median
(
rtts
))
self
.
time
=
last_time
def
__str__
(
self
):
frmt
=
'node_id=${fp} bw={sp} nick={n} rtt={rtt} time={t}'
return
frmt
.
format
(
fp
=
self
.
fp
,
sp
=
self
.
bw
,
n
=
self
.
nick
,
rtt
=
self
.
rtt
,
t
=
self
.
time
)
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