<commit_before>#!/usr/bin/python
# Creator: <NAME>
# Version 1.0.

import csv as csvreader
import time as time
import sys as sys
import logging as logging
""" This is the SERPENT Incremental Pitch code. It requires a configuration
file titled, exactly, "pitches.txt". This file must consist of one column
of numbers. These numbers are the pitches, in cm, to be used. Additionally
"""

def Read_Setup():
    """ This function reads in a file named "init_setup.txt". It stores this 
    file as a list object from which the file's contents can be retrieved."""
    input_file = open( "init_setup.txt" , "r" )
    setup_file = input_file.readlines()
    setup_file = [ x.rstrip( "\n" ) for x in setup_file ]
    dictionary = {}
    for i in range( len( setup_file ) -1 ):
        dictionary[ setup_file[ i ] ] = setup_file[ i + 1 ]
    if 'log_level' in dictionary.keys():
        dictionary[ 'log_level' ] = int( dictionary[ 'log_level' ] )
    input_file.close()
    return( dictionary )

def Get_Base_Name( file_name ):
    """ This function gets a base name from the host file name """
    end_index = file_name.rfind( "." )
    base_name = file_name[ 0 : end_index ]
    return( base_name )

def Start_Log( base_name , level ): 
    log_file_name = base_name + "_" + time.strftime( "%d_%m_%Y" ) \
        + ".log"

    LogLevel = level 

    logging.basicConfig( filename = log_file_name , format = \
        "[%(levelname)8s] %(message)s" , filemode = 'w' , level = LogLevel )
    logging.debug( "This is the debug level reporting in" )
    logging.info( "This is the info level reporting in " )
    logging.warning( "This is the warning level reporting in" )
    logging.error( "This is the error level reporting in" )
    logging.critical( "This is the critical level reporting in" )

def Cep():
	''' A wrapper to place file seperators in a log file for the
	debug level '''
	logging.debug( "*****************************************************" )
	return()

#Function, refer to docstring for purpose
def Sep():
    '''A wrapper to visually seperate functions in log files'''
    logging.debug( '//////////////////////////////////////////////////////' )
    return()

def Read_Host( file_name , Sep ):
    """ This function reads in a file whose name is given in file_name to the
    function. It's contents are saved in a list. """
    Sep()
    logging.debug( "Reading in file: " + file_name )
    input_file = open( file_name , "r" )
    file_contents = input_file.readlines()
    logging.debug( "Closing file: " + file_name )
    input_file.close()
    return( file_contents )

def Read_Input( file_name , form , Sep ):
    """ This function reads in a file whose name is given in file_name to the
    function. It's contents are saved in a list and stripped of new lines. 
    They are also converted to floats. """
    Sep()
    logging.debug( "Reading in file: " + file_name )
    input_file = open( file_name , "r" )
    file_contents = input_file.readlines()
    if form == 'string':
        file_contents = [ x.rstrip( "\n" ) for x in file_contents ]
    elif form == 'float':
        file_contents = [ float( x ) for x in file_contents ]
    elif form == 'raw':
        pass
    else:
        print( "ERROR!!!: Choice of conversion for input from file " + \
            file_name + " either not given or not 'string' or not 'float'" )
        logging.debug( "ERROR!!!: Choice of conversion for input from file " + \
            file_name + " either not given or not 'string' or not 'float'" )
        exit()
    logging.debug( "Closing file: " + file_name )
    input_file.close()
    return( file_contents )

def Gen_Pitch_or_Diameter( pd , given , given_type , options , Sep , Cep ):
    """ This function generates a list of either diameters or pitches from 
    a list of pitch to diameter ratios depending on which one is additionally
    given"""
    Sep()
    geo_instance=[]
    if given_type == "pitch":
        for i in range( len( given ) ):
            for j in range( len( pd ) ):
                Cep()
                geo_instance.append( [ given [ i ] ] )
                geo_instance[ i * len( given ) + j ].append( \
                     given[ i ] / pd[ j ] )
            logging.debug( "For pitch " + str( given[ i ] ) + \
                " and p/d ratio " + str( pd[ j ] ) + " the diameter is: " )
            logging.debug( str( geo_instance[ i * len( given ) + j ][ 1 ] ) )
        logging.debug( "There are " + str( len( given ) ) + " pitches \n" + \
            " and there are " + str( len( geo_instance) ) + " geo arrays" )
    elif given_type == "diameter":
        for i in range( len( given ) ):
            for j in range( len( pd ) ):
                Cep()
                geo_instance.append( [ given[ i ] * pd[ j ] , \
                     given[ i ] ] )
            logging.debug( "For diameter " + str( given[ i ] ) + \
                " and p/d raio " + str( pd[ j ] ) + " the pitch is: " )
            logging.debug( str( geo_instance[ i * len( given ) + j ][ 0 ] ) )
        logging.debug( "There are " + str( len( given ) ) + " diameters \n" + \
            " and there are " + str( len( geo_instance ) ) + " geo arrays" )
    else:
        print( "ERROR: Choice of pitch or diameter ( given as 'pitch' or \n \
            'diameter' ) was not properly given. Goodbye. " )
        logging.debug( "< given_type > in function < Gen_Pitch_or_Diameter >\n\
            was neither 'diameter' nor 'pitch'" )
        exit()  
    if 'log_level' in options: 
        if options[ 'log_level' ] < 10:
            Cep()
            logging.debug( "The geo_instance array is: " ) 
            for i in range( len( geo_instance ) ):
                logging.debug( str( geo_instance[ i ] ) )
    return( geo_instance )

def Gen_Width_List( cladding, Sep ):
    """ This function creates a list of floats for clad widths """
    Sep()
    logging.debug( "The initial cladding array is: ")
    logging.debug( cladding )
    widths = [ float( x ) for x in cladding[ 1 : : 2 ] ]
    logging.debug( "The widths array is: " )
    logging.debug( widths )
    return( widths )
<commit_msg>In previous nested index for geo_instance i was multiplied by the wrong len, it should be len( pd ) and is now fixed<commit_after>#!/usr/bin/python
# Creator: <NAME>
# Version 1.0.

import csv as csvreader
import time as time
import sys as sys
import logging as logging
""" This is the SERPENT Incremental Pitch code. It requires a configuration
file titled, exactly, "pitches.txt". This file must consist of one column
of numbers. These numbers are the pitches, in cm, to be used. Additionally
"""

def Read_Setup():
    """ This function reads in a file named "init_setup.txt". It stores this 
    file as a list object from which the file's contents can be retrieved."""
    input_file = open( "init_setup.txt" , "r" )
    setup_file = input_file.readlines()
    setup_file = [ x.rstrip( "\n" ) for x in setup_file ]
    dictionary = {}
    for i in range( len( setup_file ) -1 ):
        dictionary[ setup_file[ i ] ] = setup_file[ i + 1 ]
    if 'log_level' in dictionary.keys():
        dictionary[ 'log_level' ] = int( dictionary[ 'log_level' ] )
    input_file.close()
    return( dictionary )

def Get_Base_Name( file_name ):
    """ This function gets a base name from the host file name """
    end_index = file_name.rfind( "." )
    base_name = file_name[ 0 : end_index ]
    return( base_name )

def Start_Log( base_name , level ): 
    log_file_name = base_name + "_" + time.strftime( "%d_%m_%Y" ) \
        + ".log"

    LogLevel = level 

    logging.basicConfig( filename = log_file_name , format = \
        "[%(levelname)8s] %(message)s" , filemode = 'w' , level = LogLevel )
    logging.debug( "This is the debug level reporting in" )
    logging.info( "This is the info level reporting in " )
    logging.warning( "This is the warning level reporting in" )
    logging.error( "This is the error level reporting in" )
    logging.critical( "This is the critical level reporting in" )

def Cep():
	''' A wrapper to place file seperators in a log file for the
	debug level '''
	logging.debug( "*****************************************************" )
	return()

#Function, refer to docstring for purpose
def Sep():
    '''A wrapper to visually seperate functions in log files'''
    logging.debug( '//////////////////////////////////////////////////////' )
    return()

def Read_Host( file_name , Sep ):
    """ This function reads in a file whose name is given in file_name to the
    function. It's contents are saved in a list. """
    Sep()
    logging.debug( "Reading in file: " + file_name )
    input_file = open( file_name , "r" )
    file_contents = input_file.readlines()
    logging.debug( "Closing file: " + file_name )
    input_file.close()
    return( file_contents )

def Read_Input( file_name , form , Sep ):
    """ This function reads in a file whose name is given in file_name to the
    function. It's contents are saved in a list and stripped of new lines. 
    They are also converted to floats. """
    Sep()
    logging.debug( "Reading in file: " + file_name )
    input_file = open( file_name , "r" )
    file_contents = input_file.readlines()
    if form == 'string':
        file_contents = [ x.rstrip( "\n" ) for x in file_contents ]
    elif form == 'float':
        file_contents = [ float( x ) for x in file_contents ]
    elif form == 'raw':
        pass
    else:
        print( "ERROR!!!: Choice of conversion for input from file " + \
            file_name + " either not given or not 'string' or not 'float'" )
        logging.debug( "ERROR!!!: Choice of conversion for input from file " + \
            file_name + " either not given or not 'string' or not 'float'" )
        exit()
    logging.debug( "Closing file: " + file_name )
    input_file.close()
    return( file_contents )

def Gen_Pitch_or_Diameter( pd , given , given_type , options , Sep , Cep ):
    """ This function generates a list of either diameters or pitches from 
    a list of pitch to diameter ratios depending on which one is additionally
    given"""
    Sep()
    geo_instance=[]
    if given_type == "pitch":
        for i in range( len( given ) ):
            for j in range( len( pd ) ):
                Cep()
                geo_instance.append( [ given [ i ] ] )
                geo_instance[ i * len( pd ) + j ].append( \
                     given[ i ] / pd[ j ] )
            logging.debug( "For pitch " + str( given[ i ] ) + \
                " and p/d ratio " + str( pd[ j ] ) + " the diameter is: " )
            logging.debug( str( geo_instance[ i * len( pd ) + j ][ 1 ] ) )
        logging.debug( "There are " + str( len( given ) ) + " pitches \n" + \
            " and there are " + str( len( geo_instance) ) + " geo arrays" )
    elif given_type == "diameter":
        for i in range( len( given ) ):
            for j in range( len( pd ) ):
                Cep()
                geo_instance.append( [ given[ i ] * pd[ j ] , \
                     given[ i ] ] )
            logging.debug( "For diameter " + str( given[ i ] ) + \
                " and p/d raio " + str( pd[ j ] ) + " the pitch is: " )
            logging.debug( str( geo_instance[ i * len( pd ) + j ][ 0 ] ) )
        logging.debug( "There are " + str( len( given ) ) + " diameters \n" + \
            " and there are " + str( len( geo_instance ) ) + " geo arrays" )
    else:
        print( "ERROR: Choice of pitch or diameter ( given as 'pitch' or \n \
            'diameter' ) was not properly given. Goodbye. " )
        logging.debug( "< given_type > in function < Gen_Pitch_or_Diameter >\n\
            was neither 'diameter' nor 'pitch'" )
        exit()  
    if 'log_level' in options: 
        if options[ 'log_level' ] < 10:
            Cep()
            logging.debug( "The geo_instance array is: " ) 
            for i in range( len( geo_instance ) ):
                logging.debug( str( geo_instance[ i ] ) )
    return( geo_instance )

def Gen_Width_List( cladding, Sep ):
    """ This function creates a list of floats for clad widths """
    Sep()
    logging.debug( "The initial cladding array is: ")
    logging.debug( cladding )
    widths = [ float( x ) for x in cladding[ 1 : : 2 ] ]
    logging.debug( "The widths array is: " )
    logging.debug( widths )
    return( widths )

{'fraction_non_alphanumeric': 0.1329606222654351, 'fraction_numerical': 0.0019445794846864365, 'mean_word_length': 2.2923446252333957, 'pattern_counts': {'":': 4, '<': 11, '<?xml version=': 0, '>': 9, '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': '186589', 'n_tokens_mistral': 3809, 'n_tokens_neox': 3644, 'n_words': 1361}