示例#1
0
    def test_sofiecsvfile_promove(self):
        csvFile = scf.open('test-data/test-promove.csv')
        csvWriter = SofieCsvAccess('output.csv')

        for row in csvFile:
            csvWriter.write(row)

        csvFile.close()
        csvWriter.close()

        csvFile = scf.open('test-data/test-promove.csv')
        csvFileNew = scf.open('output.csv')
        logging.debug(csvFileNew.reader)
        for row, newRow in zip(csvFile, csvFileNew):
            for key in row.keys():
                if row[key] == None:
                    self.assertEqual(newRow[key], '')
                else:
                    self.assertEqual(row[key], newRow[key])
示例#2
0
    def test_sofiecsvfile_adams(self):
        logging.debug('Creating CSV FILE');
        csvFile = adam.open('test-data/test-adams.tab')
        logging.debug('CSVFILE CREATED.');
        csvWriter = SofieCsvAccess('output.csv')

        for row in csvFile:
            csvWriter.write(row)

        csvFile.close()
        csvWriter.close()

        csvFile = adam.open('test-data/test-adams.tab')
        csvFileNew = scf.open('output.csv')
        logging.debug(csvFileNew.reader)
        for row, newRow in zip(csvFile, csvFileNew):
            for key in row.keys():
                #logging.debug('"'+key+'"')
                self.assertTrue(key == 'Time      ' or  key == 'Roll angle'\
                    or key == 'Steering angle')
                if row[key] == None:
                    self.assertEqual(newRow[key], '')
                else:
                    self.assertEqual(row[key], newRow[key])
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'