Commit 1f163d51 authored by Theophile GENTILHOMME's avatar Theophile GENTILHOMME

[script][figure] Add decimal control in the printing of metrics

parent c22526f0
...@@ -375,6 +375,19 @@ def criterion_option(lcriteria=['eer', 'min-hter', 'far'], **kwargs): ...@@ -375,6 +375,19 @@ def criterion_option(lcriteria=['eer', 'min-hter', 'far'], **kwargs):
return custom_criterion_option return custom_criterion_option
def decimal_option(dflt=2, **kwargs):
'''Get option to get decimal value'''
def custom_decimal_option(func):
def callback(ctx, param, value):
ctx.meta['decimal'] = value
return value
return click.option(
'-d', '--decimal', type=click.INT, default=dflt,
help='Number of decimals to be printed.',
callback=callback, show_default=True, **kwargs)(func)
return custom_decimal_option
def far_option(**kwargs): def far_option(**kwargs):
'''Get option to get far value''' '''Get option to get far value'''
def custom_far_option(func): def custom_far_option(func):
...@@ -589,6 +602,7 @@ def metrics_command(docstring, criteria=('eer', 'min-hter', 'far')): ...@@ -589,6 +602,7 @@ def metrics_command(docstring, criteria=('eer', 'min-hter', 'far')):
@verbosity_option() @verbosity_option()
@click.pass_context @click.pass_context
@functools.wraps(func) @functools.wraps(func)
@decimal_option()
def wrapper(*args, **kwds): def wrapper(*args, **kwds):
return func(*args, **kwds) return func(*args, **kwds)
return wrapper return wrapper
......
...@@ -219,15 +219,17 @@ class Metrics(MeasureBase): ...@@ -219,15 +219,17 @@ class Metrics(MeasureBase):
recall, f1_score) recall, f1_score)
def _strings(self, metrics): def _strings(self, metrics):
fta_str = "%.1f%%" % (100 * metrics[0]) fta_str = "%s%%" % format(100 * metrics[0], '.%df' % self._decimal)
fmr_str = "%.1f%% (%d/%d)" % (100 * metrics[1], metrics[6], metrics[7]) fmr_str = "%s%% (%d/%d)" % (format(100 * metrics[1], '.%df' % self._decimal),
fnmr_str = "%.1f%% (%d/%d)" % (100 * metrics[2], metrics[8], metrics[9]) metrics[6], metrics[7])
far_str = "%.1f%%" % (100 * metrics[4]) fnmr_str = "%s%% (%d/%d)" % (format(100 * metrics[2], '.%df' % self._decimal),
frr_str = "%.1f%%" % (100 * metrics[5]) metrics[8], metrics[9])
hter_str = "%.1f%%" % (100 * metrics[3]) far_str = "%s%%" % format(100 * metrics[4], '.%df' % self._decimal)
prec_str = "%.1f" % (metrics[10]) frr_str = "%s%%" % format(100 * metrics[5], '.%df' % self._decimal)
recall_str = "%.1f" % (metrics[11]) hter_str = "%s%%" % format(100 * metrics[3], '.%df' % self._decimal)
f1_str = "%.1f" % (metrics[12]) prec_str = "%s" % format(metrics[10], '.%df' % self._decimal)
recall_str = "%s" % format(metrics[11], '.%df' % self._decimal)
f1_str = "%s" % format(metrics[12], '.%df' % self._decimal)
return (fta_str, fmr_str, fnmr_str, far_str, frr_str, hter_str, return (fta_str, fmr_str, fnmr_str, far_str, frr_str, hter_str,
prec_str, recall_str, f1_str) prec_str, recall_str, f1_str)
......
Markdown is supported
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