Exemplo n.º 1
0
def ExtractDSStoExcel(configParams, verbose):

    print "\nExtractDSStoExcel(): dssFile %s\n" % configParams.dssFile

    try:
        try:
            dss = HecDss.open( configParams.dataDir + '/' +\
                               configParams.dssFile )

            datasets = Vector()

            pathNameList = dss.getPathnameList()

            # Subset the available dss file paths into those that
            # contain the dssPathIDs and dssDataType
            dssPaths = []
            for dssPathID in configParams.dssPathIDs:
                foundID = False
                for dssPath in pathNameList:
                    if foundID:
                        break
                    if dssPathID in dssPath and \
                       configParams.dssDataType in dssPath:
                        dssPaths.append(dssPath)
                        foundID = True
                        break

            # Extract data and add to Vector datasets
            for dssPath in dssPaths:
                data = dss.get(dssPath, True)

                if data.numberValues == 0:
                    print "%s %s %s\n" % ("ExtractDSStoExcel():", dssPath,
                                          'No Data')
                else:
                    print 'ExtractDSStoExcel(): %s numberValues = %d' % \
                        dssPath, data.numberValues

                    datasets.add(data)

            # Export the .xls file
            list = []
            list.append(datasets)
            table = HecDataTableToExcel.newTable()
            table.createExcelFile(list, outFile)

        except Exception, err:
            print "%s %s\n" % ("ExtractDSStoExcel(): Python Error", err)

        except JavaException, err:
            print "%s %s\n" % ("ExtractDStoExcelS(): Error", err.getMessage())
Exemplo n.º 2
0
    parts[4] = ''
    ABC = "/".join(parts)  # really ABCEF
    if ABC in ABCs: continue
    ABCs[ABC] = 1
    print "Path: %s" % ABC

    data = hecfile.get(path, True)  # True to read full time series

    if dest == "excel":
        # Add Data
        datasets = java.util.Vector()
        datasets.add(data)
        # For this code, jython sees a List before a Vector
        list = []
        list.append(datasets)
        table = HecDataTableToExcel.newTable()
        target = os.path.join(dest, "export-path%07d.xlsx" % count)
        print "Writing %d values to %s" % (data.numberValues, target)
        table.createExcelFile(list, target)
    elif dest == "csv":
        target = os.path.join(dest, "export-path%07d.csv" % count)

        with open(target, 'w') as fp:
            fp.write("# path=%s units=%s type=%s\n" %
                     (ABC, data.units, data.type))
            fp.write("time,value\n")
            times = data.getTimes()
            for i, Q in enumerate(data.values):
                t = times.element(i)
                #file.write(str(t.year())+"-"+str(t.month())+"-"+str(t.day())+ " "+str(t.hour())+":"+str(t.minute())+"\n")
                fp.write(t.date(-13) + ",%.2f\n" % Q)