dvc find command

This commit is contained in:
Dmitry
2017-11-16 01:11:07 -08:00
parent 76a6757fa1
commit 86a933ea71
5 changed files with 142 additions and 22 deletions
+26
View File
@@ -2,6 +2,7 @@
Helpers for other modules.
"""
import os
import re
import stat
import shutil
@@ -13,6 +14,7 @@ from dvc.logger import Logger
LOCAL_CHUNK_SIZE = 1024*1024*1024
def cached_property(func):
'''A decorator for caching properties in classes.'''
def get(self):
@@ -82,3 +84,27 @@ def map_progress(func, targets, n_threads):
progress.finish()
return zip(targets, ret)
def parse_target_metric_file(file_name):
with open(file_name, 'r') as fd:
try:
lines = fd.readlines(2)
except Exception:
return None
return parse_target_metric(lines)
FLOATS_FROM_STRING = re.compile(r'[-+]?(?:(?:\d*\.\d+)|(?:\d+\.?))(?:[Ee][+-]?\d+)?')
def parse_target_metric(lines):
if len(lines) != 1:
return None
# Extract float from string. I.e. from 'AUC: 0.596182'
nums = FLOATS_FROM_STRING.findall(lines[0])
if len(nums) < 1:
return None
return float(nums[0])