# Path: util/tools.py
# def readQidQuery(inputfile):
#     data = [ x.strip().split(" ", 1) for x in open(inputfile).readlines()]
#     qid = [x[0] for x in data]
#     query = [x[1] for x in data]
#     return (qid, query)
# 
# Path: basic/common.py
# ROOT_PATH = "/home/b/VisualSearch1"
# 
# def printMessage(message_type, trace, message):
#     print ('%s %s [%s] %s' % (time.strftime('%d/%m/%Y %H:%M:%S'), message_type, trace, message))
# 
# def checkToSkip(filename, overwrite):
#     if os.path.exists(filename):
#         print ("%s exists." % filename),
#         if overwrite:
#             print ("overwrite")
#             return 0
#         else:
#             print ("skip")
#             return 1
#     return 0    
# 
# def makedirsforfile(filename):
#     try:
#         os.makedirs(os.path.split(filename)[0])
#     except:
#         pass


import os,sys
from util.tools import readQidQuery
from basic.common import ROOT_PATH, printMessage, checkToSkip, makedirsforfile
    from optparse import OptionParser
        name2feature = {}
        for fnum in xrange(method_count):
            data_file = os.path.join( num2file[fnum], '%s.txt' % qid)
            data = readAnnotations(data_file)
            data.sort(key=lambda v:v[0], reverse=True)
            names = [x[0] for x in data]
            labels = [x[1] for x in data]
            # print 'fnum %d' % fnum
            if fnum == 0:
                key_names = names
                for i in xrange(len(names)):
                    name2feature[names[i]] = [labels[i]]
            else:
                assert(checkSameList(key_names, names))
                for i in xrange(len(names)):
                    name2feature[names[i]].append(labels[i])
        for img in key_names:
            fout.write('%s ' % qid + img + ' ' + ' '.join(name2feature[img]) + '\n')  
    fout.close()

    print 'Combined result of different written into %s' % result_file


def main(argv=None):
    if argv is None:
        argv = sys.argv[1:]

    parser = OptionParser(usage="""usage: %prog [options] collection""")

    parser.add_option("--overwrite", default=0, type="int", help="overwrite existing file (default: 0)")

# Path: util/tools.py
# def readQidQuery(inputfile):
#     data = [ x.strip().split(" ", 1) for x in open(inputfile).readlines()]
#     qid = [x[0] for x in data]
#     query = [x[1] for x in data]
#     return (qid, query)
# 
# Path: basic/common.py
# ROOT_PATH = "/home/b/VisualSearch1"
# 
# def printMessage(message_type, trace, message):
#     print ('%s %s [%s] %s' % (time.strftime('%d/%m/%Y %H:%M:%S'), message_type, trace, message))
# 
# def checkToSkip(filename, overwrite):
#     if os.path.exists(filename):
#         print ("%s exists." % filename),
#         if overwrite:
#             print ("overwrite")
#             return 0
#         else:
#             print ("skip")
#             return 1
#     return 0    
# 
# def makedirsforfile(filename):
#     try:
#         os.makedirs(os.path.split(filename)[0])
#     except:
#         pass


# Path: combine_result.py
import os,sys
from util.tools import readQidQuery
from basic.common import ROOT_PATH, printMessage, checkToSkip, makedirsforfile
    from optparse import OptionParser

        name2feature = {}
        for fnum in xrange(method_count):
            data_file = os.path.join( num2file[fnum], '%s.txt' % qid)
            data = readAnnotations(data_file)
            data.sort(key=lambda v:v[0], reverse=True)
            names = [x[0] for x in data]
            labels = [x[1] for x in data]
            # print 'fnum %d' % fnum
            if fnum == 0:
                key_names = names
                for i in xrange(len(names)):
                    name2feature[names[i]] = [labels[i]]
            else:
                assert(checkSameList(key_names, names))
                for i in xrange(len(names)):
                    name2feature[names[i]].append(labels[i])
        for img in key_names:
            fout.write('%s ' % qid + img + ' ' + ' '.join(name2feature[img]) + '\n')  
    fout.close()

    print 'Combined result of different written into %s' % result_file


def main(argv=None):
    if argv is None:
        argv = sys.argv[1:]

    parser = OptionParser(usage="""usage: %prog [options] collection""")

    parser.add_option("--overwrite", default=0, type="int", help="overwrite existing file (default: 0)")

    parser.add_option("--rootpath", default=ROOT_PATH, type="string", help="rootpath (default: %s)" % ROOT_PATH)