Showing the changes to python (1 of 1 file). Show all
Unified · Split
| @@ -77,11 +77,24 @@ def act_on_results (action,datapath,respath,filter='d'): · 76 unmodified lines | |||
| 77 | s = re.split(datapath, i ,maxsplit=1)[1] | 77 | s = re.split(datapath, i ,maxsplit=1)[1] |
| 78 | action("%s%s%s"%(respath,'/',s)) | 78 | action("%s%s%s"%(respath,'/',s)) |
| 79 | 79 | ||
| 80 | def act_on_files (action,listfiles,listres=None,suffix='.txt',filter='f',sub='\.wav$',**keywords): | ||
| 81 | """ execute action(respath) an all subdirectories in respath """ | ||
| 82 | if listres and len(listfiles) <= len(listres): | ||
| 83 | for i in listfiles: | ||
| 84 | action(i,listres[i],**keywords) | ||
| 85 | else: | ||
| 86 | for i in listfiles: | ||
| 87 | action(i,None,**keywords) | ||
| 88 | |||
| 80 | class bench: | 89 | class bench: |
| 81 | """ class to run benchmarks on directories """ | 90 | """ class to run benchmarks on directories """ |
| 82 | def __init__(self,datadir,resdir=None,checkres=False,checkanno=False): | 91 | def __init__(self,datadir,resdir=None,checkres=False,checkanno=False): |
| 83 | self.datadir = datadir | 92 | self.datadir = datadir |
| 93 | # path to write results path to | ||
| 84 | self.resdir = resdir | 94 | self.resdir = resdir |
| 95 | # list of annotation files | ||
| 96 | self.reslist = [] | ||
| 97 | # list used to gather results | ||
| 85 | self.results = [] | 98 | self.results = [] |
| 86 | print "Checking data directory", self.datadir | 99 | print "Checking data directory", self.datadir |
| 87 | self.checkdata() | 100 | self.checkdata() |
| @@ -89,8 +102,17 @@ class bench: · 1 unmodified line | |||
| 89 | if checkres: self.checkres() | 102 | if checkres: self.checkres() |
| 90 | 103 | ||
| 91 | def checkdata(self): | 104 | def checkdata(self): |
| 105 | if os.path.isfile(self.datadir): | ||
| 106 | self.dirlist = os.path.dirname(self.datadir) | ||
| 107 | print "DBG: found a file" | ||
| 108 | elif os.path.isdir(self.datadir): | ||
| 109 | self.dirlist = list_dirs(self.datadir) | ||
| 110 | print "DBG: found a dir" | ||
| 111 | # allow dir* matching through find commands? | ||
| 112 | else: | ||
| 113 | print "ERR: path not understood" | ||
| 114 | sys.exit(1) | ||
| 92 | print "Listing directories in data directory", | 115 | print "Listing directories in data directory", |
| 93 | self.dirlist = list_dirs(self.datadir) | ||
| 94 | if self.dirlist: | 116 | if self.dirlist: |
| 95 | print " (%d elements)" % len(self.dirlist) | 117 | print " (%d elements)" % len(self.dirlist) |
| 96 | else: | 118 | else: |
| @@ -105,7 +127,6 @@ class bench: · 8 unmodified lines | |||
| 105 | print " (0 elements)" | 127 | print " (0 elements)" |
| 106 | print "ERR: no sound files were found in", self.datadir | 128 | print "ERR: no sound files were found in", self.datadir |
| 107 | sys.exit(1) | 129 | sys.exit(1) |
| 108 | #for each in self.sndlist: print each | ||
| 109 | 130 | ||
| 110 | def checkanno(self): | 131 | def checkanno(self): |
| 111 | print "Listing annotations in data directory", | 132 | print "Listing annotations in data directory", |
| @@ -131,7 +152,7 @@ class bench: · 19 unmodified lines | |||
| 131 | """ run file_exec on every input file """ | 152 | """ run file_exec on every input file """ |
| 132 | self.orig, self.missed, self.merged, self.expc, \ | 153 | self.orig, self.missed, self.merged, self.expc, \ |
| 133 | self.bad, self.doubled = 0, 0, 0, 0, 0, 0 | 154 | self.bad, self.doubled = 0, 0, 0, 0, 0, 0 |
| 134 | act_on_data(self.file_exec,self.datadir,self.resdir, \ | 155 | act_on_files(self.file_exec,self.sndlist,self.reslist, \ |
| 135 | suffix='',filter=sndfile_filter) | 156 | suffix='',filter=sndfile_filter) |
| 136 | 157 | ||
| 137 | def dir_eval(self): | 158 | def dir_eval(self): |