Commit 00ab6266 authored by Sebastian Heimann's avatar Sebastian Heimann
Browse files

listener: align numbers by dot

parent 040cce1f
from pyrocko import util
import progressbar as pbar import progressbar as pbar
from .base import Listener from .base import Listener
...@@ -19,20 +20,23 @@ class TerminalListener(Listener): ...@@ -19,20 +20,23 @@ class TerminalListener(Listener):
col_width = 15 col_width = 15
row_name = color.BOLD + '{:<{col_param_width}s}' + color.END row_name = color.BOLD + '{:<{col_param_width}s}' + color.END
parameter_fmt = '{:>{col_width}{type}}' parameter_fmt = '{:{col_width}s}'
def __init__(self): def __init__(self):
self.current_state = None self.current_state = None
self.pbars = {} self.pbars = {}
def progress_start(self, name, niter): def progress_start(self, name, niter):
self.pbars[name] = pbar.start(name, niter) pbar = util.progressbar('analysing problem', niter)
self.pbars[name] = pbar
def progress_update(self, name, iiter): def progress_update(self, name, iiter):
self.pbars[name].update(iiter) self.pbars[name].update(iiter)
def progress_finish(self, name): def progress_finish(self, name):
self.pbars[name].finish() self.pbars[name].finish()
del self.pbars[name]
def state(self, state): def state(self, state):
lines = [] lines = []
...@@ -57,13 +61,15 @@ class TerminalListener(Listener): ...@@ -57,13 +61,15 @@ class TerminalListener(Listener):
col_width=self.col_width, col_width=self.col_width,
type='s')) type='s'))
def fmt(s):
return util.gform(s, significant_digits=(self.col_width-1-6)/2)
for ip, parameter_name in enumerate(state.parameter_names): for ip, parameter_name in enumerate(state.parameter_names):
l(out_ln.format( l(out_ln.format(
parameter_name, parameter_name,
*[v[ip] for v in state.parameter_sets.values()], *[fmt(v[ip]) for v in state.parameter_sets.values()],
col_param_width=col_param_width, col_param_width=col_param_width,
col_width=self.col_width, col_width=self.col_width))
l(state.extra_text.format( l(state.extra_text.format(
col_param_width=col_param_width, col_param_width=col_param_width,
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment