Exemplo n.º 1
0
def GenerateFinalTrainingFile(model_output):
    ncols = 0
    nrows = 0
    final_file = ""
    ngroups = len(config.LABEL_GROUPS)
    ###export csv
    #"""
    first = glob.glob(config.TEMPDATA_OUTPUT + '/*/training_data.csv')[0]
    final_csv = CSVFile()
    temp = CSVFile()
    temp.from_file(first)
    final_csv.setHeader(temp.getHeader())
    #"""
    ###export csv---
    current_file = CSVFile()
    for filename in glob.glob(config.TEMPDATA_OUTPUT + '/*/training_data.csv'):
        current_file.from_file(filename)
        nrows += current_file.get_row_count()
        ncols = len(current_file.getHeader())
        for row in current_file.getRows():
            #ecsv
            final_csv.addRow(row)
            #ecsv--
            #last ngroups rows are labels, which are ints
            for v in row[:-ngroups]:
                floatval = "0 "
                try:
                    floatval = "{0:.10f}".format(float(v)) + " "
                except:
                    print("Warning: can't transform to float: ", v)

                final_file += floatval

            for group_label in row[-ngroups:]:
                final_file += group_label + ' '

            final_file += '\n'

    mkdir(config.DATA_OUTPUT + '/training')
    final_csv.saveAs(config.DATA_OUTPUT + "/training/final_training_data")
    with open(config.DATA_OUTPUT + "/training/final_training_data.txt",
              "w") as output:
        output.write("0\n 0 \n {} {} {}\n".format(ncols, nrows, ngroups))
        for name in utils.get_group_names(config.LABEL_GROUPS):
            output.write(name + " ")
        output.write(model_output + "\n")
        output.write(final_file)
Exemplo n.º 2
0
def GenerateFinalRegressionTrainingFile():
    ncols = 0
    nrows = 0
    final_file = ""
    ###export csv
    first = glob.glob(config.TEMPDATA_OUTPUT +
                      '/*/regression_training_data.csv')[0]
    final_csv = CSVFile()
    temp = CSVFile()
    temp.from_file(first)
    final_csv.setHeader(temp.getHeader())
    ###export csv---
    current_file = CSVFile()
    for filename in glob.glob(config.TEMPDATA_OUTPUT +
                              '/*/regression_training_data.csv'):
        current_file.from_file(filename)
        nrows += current_file.get_row_count()
        ncols = len(current_file.getHeader())
        for row in current_file.getRows():
            #ecsv
            final_csv.addRow(row)
            #ecsv--
            for v in row:
                final_file += "{0:.10f}".format(float(v)) + " "

            final_file += "\n"

    final_csv.saveAs(config.DATA_OUTPUT +
                     "/training/final_regression_training_data")
    with open(
            config.DATA_OUTPUT +
            "/training/final_regression_training_data.txt", "w") as output:
        outputDimensions = len(config.WINDOW_VALUES)
        inputDimensions = ncols - outputDimensions
        output.write("0 \n 1 \n {} {} {}\n".format(inputDimensions,
                                                   outputDimensions, nrows))
        output.write(final_file)