<commit_before>from vtk import *
import sys
import getopt

# Usage function
def Usage():
    print "Usage:"
    print "   -d <input data file> | -h <haruspex> | [-s <output model file> ] | [-a <output data file> ] | [-v]"
    sys.exit(1)
# End Usage function

# ReadInData function
# Read input CSV data as input port
def ReadInData( inDataName, verbosity ):
    if verbosity > 0:
        print "#  Reading input data:"

    inData = vtkDelimitedTextReader()
    inData.SetFieldDelimiterCharacters(",")
    inData.SetHaveHeaders(True)
    inData.SetDetectNumericColumns(True)
    inData.SetFileName(inDataName)
    inData.Update()

    if verbosity > 0:
        print "# Table loaded from CSV file:"
        T = inData.GetOutput()
        print "  Number of columns:", T.GetNumberOfColumns()
        print "  Number of rows:", T.GetNumberOfRows()
        print
    
    return inData
# End ReadInData function

# WriteOutData function
# Write haruspex output data
def WriteOutData( haruspex, outDataName, verbosity ):
    if verbosity > 0:
        print "#  Saving output (annotated) data:"

    outData = vtkDelimitedTextWriter()
    outData.SetFieldDelimiter(",")
    outData.SetFileName( outDataName )
    outData.SetInputConnection( haruspex.GetOutputPort(0) )
    outData.Update()

    if verbosity > 0:
        print "   Wrote", outDataName
        print
# End WriteOutData function

# WriteOutModel function
# Write haruspex output model
def WriteOutModel( haruspex, outModelName, verbosity ):
    if verbosity > 0:
        print "#  Saving output model (statistics):"
        
    outModel = vtkDelimitedTextWriter()
    outModel.SetFieldDelimiter(",")
    outModel.SetFileName(outModelName)

    if outModelType == "vtkTable":
        outModel.SetInputConnection(haruspex.GetOutputPort(1))
    elif outModelType == "vtkMultiBlockDataSet":
        print "ERROR: Unsupported case for now"
        sys.exit(1)

    outModel.Update()

    if verbosity > 0:
        print "   Wrote", outModelName
        print
# End WriteOutModel function

# Parse command line
verbosity = 1
print "# Parsing command line:"
opts,args = getopt.getopt(sys.argv[1:], 'vd:h:a:s:v:?')
inDataName = None
haruspexName = None
outDataName = "outputData.csv"
outModelName = "outputModel.csv"

for o,a in opts:
    if o == "-d":
        inDataName = a
    elif o == "-h":
        haruspexName = a
    elif o == "-a":
        outDataName = a
    elif o == "-s":
        outModelName = a
    elif o == "-v":<commit_msg>ENH: better helper.<commit_after>from vtk import *
import sys
import getopt


############################################################
# Global variables
outModelName = "outputModel.csv"
outDataName = "outputData.csv"
############################################################

############################################################
# Usage function
def Usage():
    print "Usage:"
    print "\t -h               Help: print this message and exit"
    print "\t -d <filename>    CSV input data file"
    print "\t -e <haruspex>    Type of statistics engine"
    print "\t [-s <filename> ] CSV output model (statistics) file. Default:",outModelName
    print "\t [-a <filename> ] CSV output data (annotated) file. Default:",outDataName
    print "\t [-v]             Increase verbosity"
    sys.exit(1)
############################################################

############################################################
# Read input CSV data as input port
def ReadInData( inDataName, verbosity ):
    if verbosity > 0:
        print "#  Reading input data:"

    inData = vtkDelimitedTextReader()
    inData.SetFieldDelimiterCharacters(",")
    inData.SetHaveHeaders(True)
    inData.SetDetectNumericColumns(True)
    inData.SetFileName(inDataName)
    inData.Update()

    if verbosity > 0:
        print "# Table loaded from CSV file:"
        T = inData.GetOutput()
        print "  Number of columns:", T.GetNumberOfColumns()
        print "  Number of rows:", T.GetNumberOfRows()
        print
    
    return inData
############################################################

############################################################
# Write haruspex output data
def WriteOutData( haruspex, outDataName, verbosity ):
    if verbosity > 0:
        print "#  Saving output (annotated) data:"

    outData = vtkDelimitedTextWriter()
    outData.SetFieldDelimiter(",")
    outData.SetFileName( outDataName )
    outData.SetInputConnection( haruspex.GetOutputPort(0) )
    outData.Update()

    if verbosity > 0:
        print "   Wrote", outDataName
        print
############################################################

############################################################
# Write haruspex output model
def WriteOutModel( haruspex, outModelName, verbosity ):
    if verbosity > 0:
        print "#  Saving output model (statistics):"
        
    outModel = vtkDelimitedTextWriter()
    outModel.SetFieldDelimiter(",")
    outModel.SetFileName(outModelName)

    if outModelType == "vtkTable":
        outModel.SetInputConnection(haruspex.GetOutputPort(1))
    elif outModelType == "vtkMultiBlockDataSet":
        print "ERROR: Unsupported case for now"
        sys.exit(1)

    outModel.Update()

    if verbosity > 0:
        print "   Wrote", outModelName
        print
############################################################

# Parse command line
verbosity = 1
opts,args = getopt.getopt(sys.argv[1:], 'vd:e:a:s:v:h')
inDataName = None
haruspexName = None

for o,a in opts:
    if o == "-d":
        inDataName = a
    elif o == "-e":
        haruspexName = a
    elif o == "-a":
        outDataName = a
    elif o == "-s":
        outModelName = a
    elif o == "-v":
{'fraction_non_alphanumeric': 0.2016468114926419, 'fraction_numerical': 0.004204625087596356, 'mean_word_length': 3.263629574309186, 'pattern_counts': {'":': 14, '<': 11, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2629392', 'n_tokens_mistral': 1720, 'n_tokens_neox': 1662, 'n_words': 453}