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
The Tor Project
Network Health
sbws
Commits
bfcf80ce
Commit
bfcf80ce
authored
Mar 19, 2018
by
Matt Traudt
Browse files
Scale output lines
parent
d6914d9e
Changes
1
Hide whitespace changes
Inline
Side-by-side
generate-v3bw.py
View file @
bfcf80ce
...
...
@@ -38,6 +38,14 @@ def result_data_to_v3bw_line(data, fingerprint):
return
V3BWLine
(
fingerprint
,
speed
,
nick
)
def
scale_lines
(
v3bw_lines
,
scale_max
):
total
=
sum
([
l
.
bw
for
l
in
v3bw_lines
])
ratio
=
scale_max
/
total
for
line
in
v3bw_lines
:
line
.
bw
=
round
(
line
.
bw
*
ratio
)
return
v3bw_lines
def
main
(
args
):
assert
os
.
path
.
isdir
(
args
.
result_directory
)
data_fnames
=
sorted
(
os
.
listdir
(
args
.
result_directory
),
reverse
=
True
)
...
...
@@ -48,6 +56,7 @@ def main(args):
data
=
read_result_file
(
fname
,
data
)
data_lines
=
[
result_data_to_v3bw_line
(
data
,
fp
)
for
fp
in
data
]
data_lines
=
sorted
(
data_lines
,
key
=
lambda
d
:
d
.
bw
,
reverse
=
True
)
data_lines
=
scale_lines
(
data_lines
,
args
.
scale_max
)
with
open
(
args
.
output
,
'wt'
)
as
fd
:
fd
.
write
(
'{}
\n
'
.
format
(
int
(
time
.
time
())))
for
line
in
data_lines
:
...
...
@@ -61,5 +70,8 @@ if __name__ == '__main__':
help
=
'Where result data from scanner.py is stored'
)
parser
.
add_argument
(
'--output'
,
default
=
'/dev/stdout'
,
type
=
str
,
help
=
'Where to write v3bw file'
)
parser
.
add_argument
(
'--scale-max'
,
default
=
50000000
,
type
=
int
,
help
=
'When scaling bw weights, scale them up/down '
'as if this is the sum of all measurements'
)
args
=
parser
.
parse_args
()
main
(
args
)
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