diff options
author | Peng Wu <alexepico@gmail.com> | 2011-07-23 21:17:28 +0800 |
---|---|---|
committer | Peng Wu <alexepico@gmail.com> | 2011-07-23 21:17:28 +0800 |
commit | f06159167fc105e9433e52a0d1eec410ccbaf71d (patch) | |
tree | abfebe99477eb9079e9ced0ff10894c57e33f3f0 /estimate.py | |
parent | f2cce92f790dbceef5bbbbefb6d6989f17701628 (diff) | |
download | trainer-f06159167fc105e9433e52a0d1eec410ccbaf71d.tar.gz trainer-f06159167fc105e9433e52a0d1eec410ccbaf71d.tar.xz trainer-f06159167fc105e9433e52a0d1eec410ccbaf71d.zip |
write estimate.py in progress
Diffstat (limited to 'estimate.py')
-rw-r--r-- | estimate.py | 42 |
1 files changed, 40 insertions, 2 deletions
diff --git a/estimate.py b/estimate.py index e621dcb..6ba0471 100644 --- a/estimate.py +++ b/estimate.py @@ -4,6 +4,7 @@ import os.path import sys from subprocess import Popen, PIPE from argparse import ArgumentParser +from operator import itemgetter import utils from myconfig import MyConfig @@ -67,6 +68,12 @@ def walkThroughModels(path): print('Unexpected file:' + filepath) def gatherModels(path, indexname): + indexfilestatuspath = indexname + config.getStatusPostfix() + indexfilestatus = utils.load_status(indexfilestatuspath) + if utils.check_epoch(indexfilestatuspath, 'Estimate'): + return + + #begin processing indexfile = open(indexname, "w") for root, dirs, files in os.walk(path, topdown=True, onerror=handleError): for onefile in files: @@ -91,9 +98,40 @@ def gatherModels(path, indexname): else: print('Unexpected file:' + filepath) indexfile.close() + #end processing -def sortModels(indexfilename, sortedindexfilename): - pass + utils.sign_epoch(indexfilestatus, 'Estimate') + utils.store_status(indexfilestatuspath, indexfilestatus) + +def sortModels(indexname, sortedindexname): + sortedindexfilestatuspath = sortedindexname + config.getStatusPostfix() + sortedindexfilestatus = utils.load_status(sortedindexfilestatuspath) + if utils.check_epoch(sortedindexfilestatus, 'Estimate'): + return + + #begin processing + records = [] + indexfile = open(indexname, 'r') + for line in indexfile.readlines(): + #remove the trailing '\n' + line = line.rstrip(os.linesep) + (subdir, modelname, score) = line.split('#', 2) + score = float(score) + records.append((subdir, modelname, score)) + indexfile.close() + + records.sort(key=itemgetter(2), reverse=True) + + sortedindexfile = open(sortedindexname, 'w') + for record in records: + (subdir, modelname, score) = record + line = subdir + '#' + modelname + '#' + score + sortedindexfile.writelines([line]) + sortedindexfile.close() + #end processing + + utils.sign_epoch(sortedindexfilestatus, 'Estimate') + utils.store_status(sortedindexfilestatuspath, sortedindexfilestatus) if __name__ == '__main__': pass |