Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ad9f0c5

Browse files
committed
Introducing utils.helpers for miscellaneous helper functions
1 parent 7b3bc31 commit ad9f0c5

10 files changed

Lines changed: 21 additions & 27 deletions

bin/benchmark_nc.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
# To use util.tc
1010
sys.path.append(os.path.abspath(os.path.dirname(os.path.dirname(sys.argv[0]))))
1111
import util.taskcluster as tcu
12-
from util.benchmark import keep_only_digits
12+
from util.helpers import keep_only_digits
1313

1414
import paramiko
1515
import argparse
@@ -171,8 +171,8 @@ def nsort(a, b):
171171
assert len(fa) == len(fb)
172172
assert len(fa) == 1
173173

174-
fa = keep_only_digits(fa[0])
175-
fb = keep_only_digits(fb[0])
174+
fa = int(keep_only_digits(fa[0]))
175+
fb = int(keep_only_digits(fb[0]))
176176

177177
if fa < fb:
178178
return -1

bin/benchmark_plotter.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88

99
# To use util.tc
1010
sys.path.append(os.path.abspath(os.path.dirname(os.path.dirname(sys.argv[0]))))
11-
import util.taskcluster as tcu
12-
from util.benchmark import keep_only_digits
11+
from util.helpers import keep_only_digits
1312

1413
import argparse
1514
import numpy
@@ -35,7 +34,7 @@ def reduce_filename(f):
3534
'''
3635

3736
f = os.path.basename(f).split('.')
38-
return keep_only_digits(f[-3])
37+
return int(keep_only_digits(f[-3]))
3938

4039
def ingest_csv(datasets=None, range=None):
4140
existing_files = filter(lambda x: os.path.isfile(x[1]), datasets)

bin/import_cv2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
from multiprocessing import cpu_count
2828
from util.downloader import SIMPLE_BAR
2929
from util.text import Alphabet, validate_label
30-
from util.feeding import secs_to_hours
30+
from util.helpers import secs_to_hours
3131

3232

3333
FIELDNAMES = ['wav_filename', 'wav_filesize', 'transcript']

bin/import_lingua_libre.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
from util.downloader import maybe_download
3030
from util.text import Alphabet, validate_label
31-
from util.feeding import secs_to_hours
31+
from util.helpers import secs_to_hours
3232

3333
FIELDNAMES = ['wav_filename', 'wav_filesize', 'transcript']
3434
SAMPLE_RATE = 16000

bin/import_m-ailabs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
from util.downloader import maybe_download
2828
from util.text import Alphabet, validate_label
29-
from util.feeding import secs_to_hours
29+
from util.helpers import secs_to_hours
3030

3131
FIELDNAMES = ['wav_filename', 'wav_filesize', 'transcript']
3232
SAMPLE_RATE = 16000

bin/import_slr57.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
from util.downloader import maybe_download
3131
from util.text import Alphabet, validate_label
32-
from util.feeding import secs_to_hours
32+
from util.helpers import secs_to_hours
3333

3434
FIELDNAMES = ['wav_filename', 'wav_filesize', 'transcript']
3535
SAMPLE_RATE = 16000

bin/import_ts.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
from util.downloader import maybe_download
2929
from util.text import validate_label
30-
from util.feeding import secs_to_hours
30+
from util.helpers import secs_to_hours
3131

3232
FIELDNAMES = ['wav_filename', 'wav_filesize', 'transcript']
3333
SAMPLE_RATE = 16000

stats.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
import argparse
44
import os
55

6-
from util.feeding import read_csvs, secs_to_hours
6+
from util.helpers import secs_to_hours
7+
from util.feeding import read_csvs
78

89
def main():
910
parser = argparse.ArgumentParser()

util/benchmark.py

Lines changed: 0 additions & 15 deletions
This file was deleted.

util/helpers.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
2+
def keep_only_digits(txt):
3+
return ''.join(filter(lambda c: c.isdigit(), txt))
4+
5+
6+
def secs_to_hours(secs):
7+
hours, remainder = divmod(secs, 3600)
8+
minutes, seconds = divmod(remainder, 60)
9+
return '%d:%02d:%02d' % (hours, minutes, seconds)

0 commit comments

Comments
 (0)