<commit_before>from src import utils
from src import printer
from src import reporting
from src.dims import *
import numpy


def load_correct_props(folders, name = ""):
    props0 = utils.load_properties_dirs(folders, exts=[".txt.cdgp"])
    all_logs = utils.load_properties_dirs(folders, exts=[".txt.cdgp", ".txt"])

    print("\n****** Loading props: " + name)

    def is_correct(p):
        return "status" in p and (p["status"] == "completed" or p["status"] == "initialized") and\
               "result.best.eval" in p and "benchmark" in p

    def is_obsolete(p):
        return False #p["searchAlgorithm"].endswith("SteadyState") and\
               #"info.steadyStateWithZeroInitialTests" not in p

    # Printing names of files which finished with error status or are incomplete.
    props_errors = [p for p in props0 if not is_correct(p)]
    if len(props_errors) > 0:
        print("Files with error status:")
    for p in props_errors:
        if "thisFileName" in p:
            print(p["thisFileName"])
        else:
            print("'thisFileName' not specified! Printing content instead: " + str(p))

    # Filtering props so only correct ones are left
    props = [p for p in props0 if is_correct(p) and not is_obsolete(p)]
    print("Loaded: {0} correct property files, {1} incorrect; All log files: {2}".format(len(props), len(props_errors), len(all_logs)))
    return props


def produce_status_matrix(grid, props):
    text = "["
    for config in grid:
        numRuns = len(config.filter_props(props))
        benchmark = config.stored_values["benchmark"]
        method = config.stored_values["method"]
        sa = config.stored_values["searchAlgorithm"]
        text += "('{0}', '{1}', '{2}', {3}), ".format(benchmark, method, sa, numRuns)
    return text + "]"



def p_GP(p):
    return p["searchAlgorithm"] == "GP"
def p_GPSteadyState(p):
    return p["searchAlgorithm"] == "GPSteadyState"
def p_Lexicase(p):
    return p["searchAlgorithm"] == "Lexicase"
def p_LexicaseSteadyState(p):
    return p["searchAlgorithm"] == "LexicaseSteadyState"
def p_method0(p):
    return p["method"] == "CDGP"
def p_method1(p):
    return p["method"] == "CDGPcons"
def p_method2(p):
    return p["method"] == "GPR"
def p_Generational(p):
    return p["searchAlgorithm"] == "Lexicase" or  p["searchAlgorithm"] == "GP"
def p_SteadyState(p):
    return p["searchAlgorithm"] == "LexicaseSteadyState" or  p["searchAlgorithm"] == "GPSteadyState"
def p_sel_lexicase(p):
    return p["searchAlgorithm"] == "LexicaseSteadyState" or p["searchAlgorithm"] == "Lexicase"
def p_sel_tourn(p):
    return p["searchAlgorithm"] == "GPSteadyState" or p["searchAlgorithm"] == "GP"


d1 = "benchmarks/LIA/cdgp_gecco17/other/"
d2 = "benchmarks/LIA/cdgp_gecco17/"
benchmarks_simple_names = {d1 + "ArithmeticSeries3.sl": "IsSeries3",
                           d1 + "ArithmeticSeries4.sl": "IsSeries4",
                           d1 + "CountPositive2.sl": "CountPos2",
                           d1 + "CountPositive3.sl": "CountPos3",
                           d1 + "Median3.sl": "Median3",
                           d1 + "Range3.sl": "Range3",
                           d1 + "SortedAscending4.sl": "IsSorted4",
                           d2 + "fg_array_search_2.sl": "Search2",
                           d2 + "fg_array_search_4.sl": "Search4",
                           d2 + "fg_array_sum_2_15.sl": "Sum2",
                           d2 + "fg_array_sum_4_15.sl": "Sum4",
                           d2 + "fg_max2.sl": "Max2",
                           d2 + "fg_max4.sl": "Max4"}


dim_method = Dim([Config("CDGP non-conservative", p_method0, method="CDGP"),
                  Config("CDGP conservative", p_method1, method="CDGPcons"),
                  Config("GPR", p_method2, method="GPR")])
dim_sa = Dim([Config("GP", p_GP, searchAlgorithm="GP"),
              Config("GPSS", p_GPSteadyState, searchAlgorithm="GPSteadyState"),
              Config("Lex", p_Lexicase, searchAlgorithm="Lexicase"),
              Config("LexSS", p_LexicaseSteadyState, searchAlgorithm="LexicaseSteadyState")])
dim_ea_type = Dim([Config("Gener.", p_Generational),
                   Config("SteadySt.", p_SteadyState)])
dim_sel = Dim([Config("$Tour$", p_sel_tourn),
               Config("$Lex$", p_sel_lexicase)])
dim_sa_ss = Dim([
              Config("GPSS", p_GPSteadyState, searchAlgorithm="GPSteadyState"),
              Config("LexSS", p_LexicaseSteadyState, searchAlgorithm="LexicaseSteadyState")])
# dim_sa = Dim([Config("$CDGP$", p_GP),
# 			    Config("$CDGP^{ss}$", p_GPSteadyState),
#               Config("$CDGP_{lex}$", p_Lexicase),
#               Config("$CDGP_{lex}^{ss}$", p_LexicaseSteadyState)])


def is_optimal_solution(p):
    return "result.best.isOptimal" in p and p["result.best.isOptimal"] == "true"

def get_num_optimal(props):
    props2 = [p for p in props if is_optimal_solution(p)]
    return len(props2)

def get_num_computed(filtered):
    return len(filtered)
def fun_successRates_full(filtered):
    if len(filtered) == 0:
        return "-"
    num_opt = get_num_optimal(filtered)
    return "{0}/{1}".format(str(num_opt), str(len(filtered)))
def fun_successRates(filtered):
    if len(filtered) == 0:
        return None
    num_opt = get_num_optimal(filtered)
    sr = float(num_opt) / float(len(filtered))
    return "{0}".format("%0.2f" % sr)
def get_stats_size(props):
    vals = [float(p["result.best.size"]) for p in props]
    if len(vals) == 0:
        return "-"#-1.0, -1.0
    else:
        return "%0.1f" % numpy.mean(vals)#, numpy.std(vals)
def get_stats_maxSolverTime(props):
    if len(props) == 0:
        return "-"
    times = []
    for p in props:
        timesMap = p["cdgp.solverAllTimesCountMap"]<commit_msg>Fix lacking -<commit_after>from src import utils
from src import printer
from src import reporting
from src.dims import *
import numpy


def load_correct_props(folders, name = ""):
    props0 = utils.load_properties_dirs(folders, exts=[".txt.cdgp"])
    all_logs = utils.load_properties_dirs(folders, exts=[".txt.cdgp", ".txt"])

    print("\n****** Loading props: " + name)

    def is_correct(p):
        return "status" in p and (p["status"] == "completed" or p["status"] == "initialized") and\
               "result.best.eval" in p and "benchmark" in p

    def is_obsolete(p):
        return False #p["searchAlgorithm"].endswith("SteadyState") and\
               #"info.steadyStateWithZeroInitialTests" not in p

    # Printing names of files which finished with error status or are incomplete.
    props_errors = [p for p in props0 if not is_correct(p)]
    if len(props_errors) > 0:
        print("Files with error status:")
    for p in props_errors:
        if "thisFileName" in p:
            print(p["thisFileName"])
        else:
            print("'thisFileName' not specified! Printing content instead: " + str(p))

    # Filtering props so only correct ones are left
    props = [p for p in props0 if is_correct(p) and not is_obsolete(p)]
    print("Loaded: {0} correct property files, {1} incorrect; All log files: {2}".format(len(props), len(props_errors), len(all_logs)))
    return props


def produce_status_matrix(grid, props):
    text = "["
    for config in grid:
        numRuns = len(config.filter_props(props))
        benchmark = config.stored_values["benchmark"]
        method = config.stored_values["method"]
        sa = config.stored_values["searchAlgorithm"]
        text += "('{0}', '{1}', '{2}', {3}), ".format(benchmark, method, sa, numRuns)
    return text + "]"



def p_GP(p):
    return p["searchAlgorithm"] == "GP"
def p_GPSteadyState(p):
    return p["searchAlgorithm"] == "GPSteadyState"
def p_Lexicase(p):
    return p["searchAlgorithm"] == "Lexicase"
def p_LexicaseSteadyState(p):
    return p["searchAlgorithm"] == "LexicaseSteadyState"
def p_method0(p):
    return p["method"] == "CDGP"
def p_method1(p):
    return p["method"] == "CDGPcons"
def p_method2(p):
    return p["method"] == "GPR"
def p_Generational(p):
    return p["searchAlgorithm"] == "Lexicase" or  p["searchAlgorithm"] == "GP"
def p_SteadyState(p):
    return p["searchAlgorithm"] == "LexicaseSteadyState" or  p["searchAlgorithm"] == "GPSteadyState"
def p_sel_lexicase(p):
    return p["searchAlgorithm"] == "LexicaseSteadyState" or p["searchAlgorithm"] == "Lexicase"
def p_sel_tourn(p):
    return p["searchAlgorithm"] == "GPSteadyState" or p["searchAlgorithm"] == "GP"


d1 = "benchmarks/LIA/cdgp_gecco17/other/"
d2 = "benchmarks/LIA/cdgp_gecco17/"
benchmarks_simple_names = {d1 + "ArithmeticSeries3.sl": "IsSeries3",
                           d1 + "ArithmeticSeries4.sl": "IsSeries4",
                           d1 + "CountPositive2.sl": "CountPos2",
                           d1 + "CountPositive3.sl": "CountPos3",
                           d1 + "Median3.sl": "Median3",
                           d1 + "Range3.sl": "Range3",
                           d1 + "SortedAscending4.sl": "IsSorted4",
                           d2 + "fg_array_search_2.sl": "Search2",
                           d2 + "fg_array_search_4.sl": "Search4",
                           d2 + "fg_array_sum_2_15.sl": "Sum2",
                           d2 + "fg_array_sum_4_15.sl": "Sum4",
                           d2 + "fg_max2.sl": "Max2",
                           d2 + "fg_max4.sl": "Max4"}


dim_method = Dim([Config("CDGP non-conservative", p_method0, method="CDGP"),
                  Config("CDGP conservative", p_method1, method="CDGPcons"),
                  Config("GPR", p_method2, method="GPR")])
dim_sa = Dim([Config("GP", p_GP, searchAlgorithm="GP"),
              Config("GPSS", p_GPSteadyState, searchAlgorithm="GPSteadyState"),
              Config("Lex", p_Lexicase, searchAlgorithm="Lexicase"),
              Config("LexSS", p_LexicaseSteadyState, searchAlgorithm="LexicaseSteadyState")])
dim_ea_type = Dim([Config("Gener.", p_Generational),
                   Config("SteadySt.", p_SteadyState)])
dim_sel = Dim([Config("$Tour$", p_sel_tourn),
               Config("$Lex$", p_sel_lexicase)])
dim_sa_ss = Dim([
              Config("GPSS", p_GPSteadyState, searchAlgorithm="GPSteadyState"),
              Config("LexSS", p_LexicaseSteadyState, searchAlgorithm="LexicaseSteadyState")])
# dim_sa = Dim([Config("$CDGP$", p_GP),
# 			    Config("$CDGP^{ss}$", p_GPSteadyState),
#               Config("$CDGP_{lex}$", p_Lexicase),
#               Config("$CDGP_{lex}^{ss}$", p_LexicaseSteadyState)])


def is_optimal_solution(p):
    return "result.best.isOptimal" in p and p["result.best.isOptimal"] == "true"

def get_num_optimal(props):
    props2 = [p for p in props if is_optimal_solution(p)]
    return len(props2)

def get_num_computed(filtered):
    return len(filtered)
def fun_successRates_full(filtered):
    if len(filtered) == 0:
        return "-"
    num_opt = get_num_optimal(filtered)
    return "{0}/{1}".format(str(num_opt), str(len(filtered)))
def fun_successRates(filtered):
    if len(filtered) == 0:
        return "-"
    num_opt = get_num_optimal(filtered)
    sr = float(num_opt) / float(len(filtered))
    return "{0}".format("%0.2f" % sr)
def get_stats_size(props):
    vals = [float(p["result.best.size"]) for p in props]
    if len(vals) == 0:
        return "-"#-1.0, -1.0
    else:
        return "%0.1f" % numpy.mean(vals)#, numpy.std(vals)
def get_stats_maxSolverTime(props):
    if len(props) == 0:
        return "-"
    times = []
    for p in props:
        timesMap = p["cdgp.solverAllTimesCountMap"]
{'fraction_non_alphanumeric': 0.14980426272292302, 'fraction_numerical': 0.014441061331013484, 'mean_word_length': 2.9792315680166146, 'pattern_counts': {'":': 26, '<': 3, '<?xml version=': 0, '>': 5, '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': '5366082', 'n_tokens_mistral': 3980, 'n_tokens_neox': 3823, 'n_words': 826}