ruff: function instead of lambda
This commit is contained in:
parent
db58e4e11c
commit
3808018981
2 changed files with 21 additions and 13 deletions
|
|
@ -650,6 +650,8 @@ class BlocksInfo:
|
|||
values[v.name] = v.code(values)
|
||||
|
||||
def gen():
|
||||
def make_conv(x):
|
||||
return self.fmt_funcs[x] if x else '{}'
|
||||
for n, fname in enumerate(fnames):
|
||||
spec_conv = d.spec_convs.get(fname)
|
||||
yield (
|
||||
|
|
@ -658,8 +660,7 @@ class BlocksInfo:
|
|||
wid = col1_w + (spec_conv.width_adj if spec_conv else 0),
|
||||
suf = d.spec_sufs.get(fname) or ''),
|
||||
fname,
|
||||
spec_conv.conv if spec_conv else (
|
||||
(lambda x: self.fmt_funcs[x] if x else '{}')(self.fields[fname].fmt_func)),
|
||||
spec_conv.conv if spec_conv else make_conv(self.fields[fname].fmt_func),
|
||||
values[fname])
|
||||
|
||||
return (sname, (d.hdr,) + tuple(gen()))
|
||||
|
|
|
|||
|
|
@ -859,8 +859,13 @@ def make_cfg(gcfg_arg):
|
|||
if portfolio and asset_range:
|
||||
die(1, '--portfolio not supported in market cap view')
|
||||
|
||||
pchg_unit = (lambda s: parse_asset_id(s, require_label=False) if s else None)(
|
||||
get_cfg_var('pchg_unit'))
|
||||
def parse_id(s):
|
||||
return parse_asset_id(s, require_label=False) if s else None
|
||||
|
||||
def make_adj(x):
|
||||
return (100 + x) / 100 if x else 1
|
||||
|
||||
pchg_unit = parse_id(get_cfg_var('pchg_unit'))
|
||||
|
||||
cfg = cfg_tuple(
|
||||
rows = create_rows(),
|
||||
|
|
@ -868,7 +873,7 @@ def make_cfg(gcfg_arg):
|
|||
usr_columns = usr_columns,
|
||||
query = query,
|
||||
asset_range = asset_range,
|
||||
adjust = (lambda x: (100 + x) / 100 if x else 1)(Decimal(gcfg.adjust or 0)),
|
||||
adjust = make_adj(Decimal(gcfg.adjust or 0)),
|
||||
clsname = 'trading' if query else 'overview',
|
||||
btc_only = get_cfg_var('btc'),
|
||||
add_prec = parse_add_precision(get_cfg_var('add_precision')),
|
||||
|
|
@ -893,14 +898,16 @@ def make_cfg(gcfg_arg):
|
|||
|
||||
def get_cfg_in():
|
||||
ret = namedtuple('cfg_in_data', ['cfg', 'portfolio', 'cfg_file', 'portfolio_file'])
|
||||
cfg_file, portfolio_file = (
|
||||
[os.path.join(gcfg.data_dir_root, 'node_tools', fn)
|
||||
for fn in (cfg_fn, portfolio_fn)])
|
||||
cfg_data, portfolio_data = (
|
||||
[yaml.safe_load(open(fn).read()) if os.path.exists(fn) else None
|
||||
for fn in (cfg_file, portfolio_file)])
|
||||
def load_yaml(fn):
|
||||
if os.path.exists(fn):
|
||||
with open(fn) as fh:
|
||||
return yaml.safe_load(fh.read())
|
||||
def make_path(fn):
|
||||
return os.path.join(gcfg.data_dir_root, 'node_tools', fn)
|
||||
cfg_file = make_path(cfg_fn)
|
||||
portfolio_file = make_path(portfolio_fn)
|
||||
return ret(
|
||||
cfg = cfg_data or {
|
||||
cfg = load_yaml(cfg_file) or {
|
||||
'assets': {
|
||||
'coin': [ 'btc-bitcoin', 'eth-ethereum', 'xmr-monero' ],
|
||||
# gold futures, silver futures, Brent futures
|
||||
|
|
@ -910,7 +917,7 @@ def get_cfg_in():
|
|||
# Dow Jones Industrials, Nasdaq 100, S&P 500
|
||||
'index': [ '^dji', '^ixic', '^gspc' ]},
|
||||
'proxy': 'http://vpn-gw:8118'},
|
||||
portfolio = portfolio_data,
|
||||
portfolio = load_yaml(portfolio_file),
|
||||
cfg_file = cfg_file,
|
||||
portfolio_file = portfolio_file)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue