Skip to content
Snippets Groups Projects
Commit 028dc8bf authored by juga's avatar juga
Browse files

Add args to generate to scale as torflow too

parent e64ecd47
No related branches found
No related tags found
No related merge requests found
from sbws.globals import (fail_hard, SBWS_SCALE_CONSTANT)
from sbws.globals import (fail_hard, SBWS_SCALE_CONSTANT, TORFLOW_SCALING,
SBWS_SCALING)
from sbws.lib.v3bwfile import V3BWFile
from sbws.lib.resultdump import load_recent_results_in_datadir
from argparse import ArgumentDefaultsHelpFormatter
......@@ -31,11 +32,14 @@ def gen_parser(sub):
p.add_argument('--scale-constant', default=SBWS_SCALE_CONSTANT, type=int,
help='When scaling bw weights, scale them using this const '
'multiplied by the number of measured relays')
p.add_argument('--scale', action='store_true',
p.add_argument('--scale_sbws', action='store_true',
help='If specified, do not use bandwidth values as they '
'are, but scale them such that we have a budget of '
'scale_constant * num_measured_relays = bandwidth to give '
'out, and we do so proportionally')
p.add_argument('-t', '--scale_torflow', action='store_true',
help='If specified, do not use bandwidth values as they '
'are, but scale them in the way Torflow does.')
def main(args, conf):
......@@ -46,6 +50,12 @@ def main(args, conf):
fail_hard('%s does not exist', datadir)
if args.scale_constant < 1:
fail_hard('--scale-constant must be positive')
if args.scale_sbws:
scaling_method = SBWS_SCALING
elif args.scale_torflow:
scaling_method = TORFLOW_SCALING
else:
scaling_method = None
fresh_days = conf.getint('general', 'data_period')
reset_bw_ipv4_changes = conf.getboolean('general', 'reset_bw_ipv4_changes')
......@@ -59,7 +69,8 @@ def main(args, conf):
'ran sbws scanner recently?)')
return
state_fpath = conf.getpath('paths', 'state_fname')
bw_file = V3BWFile.from_results(results, state_fpath, args.scale_constant)
bw_file = V3BWFile.from_results(results, state_fpath, args.scale_constant,
scaling_method)
output = args.output or \
conf.getpath('paths', 'v3bw_fname').format(now_fname())
bw_file.write(output)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment