mirror of
https://github.com/clearml/clearml
synced 2025-06-23 01:55:38 +00:00
Improve utility get_single_result()
This commit is contained in:
parent
9da307730c
commit
3cb42acd12
@ -72,10 +72,10 @@ def get_single_result(entity, query, results, log=None, show_results=10, raise_o
|
|||||||
|
|
||||||
raise ValueError('No {entity}s found when searching for `{query}`'.format(**locals()))
|
raise ValueError('No {entity}s found when searching for `{query}`'.format(**locals()))
|
||||||
|
|
||||||
|
if len(results) > 1:
|
||||||
|
if show_results:
|
||||||
if not log:
|
if not log:
|
||||||
log = get_logger()
|
log = get_logger()
|
||||||
|
|
||||||
if len(results) > 1:
|
|
||||||
log.warning('More than one {entity} found when searching for `{query}`'
|
log.warning('More than one {entity} found when searching for `{query}`'
|
||||||
' (showing first {show_results} {entity}s follow)'.format(**locals()))
|
' (showing first {show_results} {entity}s follow)'.format(**locals()))
|
||||||
if sort_by_date:
|
if sort_by_date:
|
||||||
@ -88,6 +88,7 @@ def get_single_result(entity, query, results, log=None, show_results=10, raise_o
|
|||||||
results = sorted(results, key=lambda x: int((x.created - relative_time).total_seconds()
|
results = sorted(results, key=lambda x: int((x.created - relative_time).total_seconds()
|
||||||
if x.created else 0), reverse=True)
|
if x.created else 0), reverse=True)
|
||||||
|
|
||||||
|
if show_results and log:
|
||||||
for i, obj in enumerate(o if isinstance(o, dict) else o.to_dict() for o in results[:show_results]):
|
for i, obj in enumerate(o if isinstance(o, dict) else o.to_dict() for o in results[:show_results]):
|
||||||
selected = 'Selected' if i == 0 else 'Additionally found'
|
selected = 'Selected' if i == 0 else 'Additionally found'
|
||||||
log.warning('{selected} {entity} `{obj[name]}` (id={obj[id]})'.format(**locals()))
|
log.warning('{selected} {entity} `{obj[name]}` (id={obj[id]})'.format(**locals()))
|
||||||
|
Loading…
Reference in New Issue
Block a user