Example #1
0
def genUpdateSQL(tableName, updateCols, paramNum, whereSQL):
    params = []
    for i in range(paramNum):
        params.append("%s")

    if (whereSQL is None) or (whereSQL == ""):
        insertFormat = "update %s set(%s) VALUES (%s)"
        return insertFormat % (tableName, updateCols, util.listToString(params, ","))
    else:
        insertFormat = "update %s set(%s) VALUES (%s) where %s"
        return insertFormat % (tableName, updateCols, util.listToString(params, ","), whereSQL)
Example #2
0
def getInputData(prefixes, table, sqlFilter):
    fieldList = genMagByPrefix(prefixes)
    fieldList.append("`type`")
    fieldList.append("mainclass")
    sql_select = sqlHelper.genSelectSQLWithFieldList(fieldList, table, sqlFilter)

    outFile = "data_input.txt"
    outFile_tag = "data_input_tag.txt"
    output = open(outFile, "w")
    output_tag = open(outFile_tag, "w")
    count = 0

    res = []
    tags = []
    data = sqlHelper.getFetchAll(sql_select)
    for item in data:
        record = []
        colCount = len(item)
        for i in range(colCount - 1):
            record.append(item[i])

        res.append(record)
        tags.append(item[colCount - 1])

        output.write(util.listToString(record))
        output.write("\n")
        output_tag.write(item[colCount - 1])
        output_tag.write("\n")
        count += 1

    print "input data count : %s" % count
    output.close()
    output_tag.close()
    return np.mat(res), np.mat(tags).T
Example #3
0
def genSelectSQLWithFieldList(fieldList, fromSQL, whereSQL):
    fields = util.listToString(fieldList, ",")
    return genSelectSQL(fields, fromSQL, whereSQL)
Example #4
0
def genInsertSQL(tableName, paramNum):
    params = []
    insertFormat = "INSERT INTO %s VALUES (%s)"
    for i in range(paramNum):
        params.append("%s")
    return insertFormat % (tableName, util.listToString(params, ","))
Example #5
0
for dir in dirs:
    files = os.listdir(os.path.join(inputPath, dir))
    for fileName in files:
        filePath = os.path.join(inputPath, dir, fileName)
        try:
            keywords, flux = astroUtil.getFitsHeaderAndFlux(filePath)

            record = []
            for fea in features:
                record.append(keywords[fea])
            for wl in waveLens:
                record.append(astroUtil.checkLine(flux, wl))

            subClass = keywords[subClassKey][0:1]
            subClassTag = classMap[subClass]
            classCount[subClass] += 1

            record.append(subClassTag)
            output.write(util.listToString(record))
            output.write("\n")
            count += 1
            print "%d - %s" % (count, filePath)
        except Exception, ex:
            print "ERROR : %s - %s" % (count, filePath)

output.close()

util.printDic(classCount)
# O:0, B:0, A:12, F:1404, G:3847, K:1239, M:0, N:0
# 1:0, 2:0, 3:12, 4:1404, 5:3847, 6:1239, 7:0, 8:0