Exemplo n.º 1
0
def importdata(infile, outfile, runName, description, shouldParse, shouldCsv):
    """
    Standard function used to import data into the file
    """
    print '\n-------------------------------\nImporting information' + \
        '\n-------------------------------\n'
    if(infile == None):
        print "Specify the in file (--infile filename)"
        exit()
    if(outfile == None):
        print "Specify the out file (--outfile filename)"
        exit()
    if(runName == None):
        print "Specify the rest run name (--runName 01CornerTestRun) "
        exit()

    extension = os.path.splitext(infile)
    infileName = extension[0]
    extension = extension[1]

    csvOut = infileName + '-sofie.csv'
    csvOutParsed = infileName + '-sofie-parsed.csv'

    if extension == '.gce':
        runNameExtended = getGESubDirectory(runName)
        theOriginalFile = GE.open(infile)
        parser = ant_sample
        parser_interpret = ant_sample_interpret
        theWriter = AntRawDataAccess(outfile,
                                     runName=runNameExtended,
                                     description=description)
    elif extension == '.ant':
        runNameExtended = getSparkSubDirectory(runName)
        theOriginalFile = SF.open(infile)
        parser = ant_sample
        parser_interpret = ant_sample_interpret
        theWriter = AntRawDataAccess(outfile,
                                     runName=runNameExtended,
                                     description=description)
    elif extension == '.c3d' or extension == '.C3D':
        runNameExtended = getC3DSubDirectory(runName)
        theOriginalFile = C3.open(infile)
        parser = c3d_sample
        parser_interpret = c3d_sample_interpret
        theWriter = C3DDataAccess(outfile,
                                  runName=runNameExtended,
                                  description=description,
                                  allowDuplicates=True,
                                  videoSamplingRate=theOriginalFile.getVideoSamplingRate(),
                                  videoFrames=theOriginalFile.getVideoFrames(),
                                  scale=theOriginalFile.getScale())
    elif extension == '.csv':
        runNameExtended = getCSVImportSubDirectory(runName)
        theOriginalFile = scf.open(infile)
        parser = csv_sample
        parser_interpret = csv_sample_interpret
        theWriter = SofieCsvPyTableAccess(outfile,
                                          runName=runNameExtended,
                                          description=description,
                                          fieldNames=theOriginalFile.getTableStructure())
    elif extension == '.tab':
        runNameExtended = getAdamsSubDirectory(runName)
        theOriginalFile = adams.open(infile)
        parser = csv_sample
        parser_interpret = csv_sample_interpret
        theWriter = SofieCsvPyTableAccess(outfile,
                                          runName=runNameExtended,
                                          description=description,
                                          fieldNames=theOriginalFile.getTableStructure())
    elif extension == '.bag':
        runNameExtended = getBagSubDirectory(runName)
        theWriter = SofieCsvPyTableAccess(outfile,
                                          runName=runNameExtended,
                                          description=description,
                                          fieldNames=['A HACK'])
        theWriter.writeFile(infile)
        print '\n-------------------------------\n{0} Saved  to file'.format(outfile)
        theWriter.close()
        return
    else:
        raise FileNotSupportedException('File not Supported: ' + str(extension))
    print '\n-------------------------------\nSaving to file',
    print outfile
    if shouldParse:
        print 'File is going to be parsed'
        print 'CSV Parsed File: ' + csvOutParsed
    if shouldCsv:
        print 'CSV File: ' + csvOut + '\n-----------------------------------\n'
        awritercsv = SofieCsvAccess(csvOut)

    for theLine in theOriginalFile:
        logging.debug(theLine)
        try:
            parsedLine = parser(theLine)

        except Exception, e:
            print 'Parsing Failed: ' + str(e)
            continue
        try:
            logging.debug(parsedLine)
            theWriter.write(parsedLine)
            print '.',
            if shouldCsv:
                awritercsv.write(parsedLine)
                print 'c',
        except AntRawParserLengthNotCorrect, e:
            print 'x'
Exemplo n.º 2
0
 def setUp(self):
     logging.info('GeFileTest Test')
     self.file = GF.open('test-data/decrease-velocity.gce')