<commit_before>
resultfiles = readdir(joinpath(pwd(), ARGS[1]))

fd = open(joinpath(pwd(), ARGS[2]), "w")

# process into a CSV file with columns:
println(fd,"solver,instance,status,objval,objbound,solvertime,totaltime,filename")

for filename in resultfiles
    if filename == ".DS_Store"
        continue
    end

    solver = " "
    instance = " "
    status = " "
    objval = " "
    objbound = " "
    solvertime = " "
    totaltime = " "
    # gaplimit = false

    for line in eachline(joinpath(pwd(), ARGS[1], filename))
        if startswith(line, "#SOLVERNAME#")
            solver = split(line)[2]
        elseif startswith(line, "#INSTANCE#")
            instance = split(line)[2]
        elseif startswith(line, "#STATUS#")
            status = split(line)[2]
        elseif startswith(line, "#OBJVAL#")
            objval = split(line)[2]
        elseif startswith(line, "#OBJBOUND#")
            objbound = split(line)[2]
        elseif startswith(line, "#TIMESOLVER#")
            solvertime = split(line)[2]
        elseif startswith(line, "#TIMEALL#")
            totaltime = split(line)[2]
        elseif startswith(line, "#SOLUTION#")
            solutionvec = split(line)[2:end]
        # elseif contains(line, "gap limit reached") # SCIP does this when it means optimal
        #     gaplimit=true
        end
    end

    # if gaplimit
    #     @assert contains(solver, "SCIP")
    #     status = "Optimal"
    # end

    println(fd, "$solver,$instance,$status,$objval,$objbound,$solvertime,$totaltime,$(basename(filename))")
end

close(fd)
<commit_msg>preliminary processing of solution in process.jl<commit_after>using ConicBenchmarkUtilities

resultfiles = readdir(joinpath(pwd(), ARGS[1]))

fd = open(joinpath(pwd(), ARGS[2]), "w")

# process into a CSV file with columns:
println(fd,"solver,instance,status,objval,objbound,solvertime,totaltime,filename")

# from instance name to file name
function find_instance(name)
    instances = joinpath(dirname(@__FILE__),"instancedata")
    try
        match = "$name.*"
        f = readstring(`find $instances -name $match`)
        if length(split(f,"\n")) == 2
            return chomp(f)
        end
    end
    return ""
end


function validate_solution(instancename, solution)
    instancefile = find_instance(instancename)
    dat = readcbfdata(instancefile)
    c, A, b, con_cones, var_cones, vartypes, sense, objoffset = cbftompb(dat)
    @assert length(solution) == length(c)
    objval = dot(c,solution)
    return objval
end

for filename in resultfiles
    if filename == ".DS_Store" || contains(filename,"META")
        continue
    end

    solver = " "
    instance = " "
    status = " "
    objval = " "
    objbound = " "
    solvertime = " "
    totaltime = " "
    solution = []
    # gaplimit = false

    for line in eachline(joinpath(pwd(), ARGS[1], filename))
        if startswith(line, "#SOLVERNAME#")
            solver = split(line)[2]
        elseif startswith(line, "#INSTANCE#")
            instance = split(line)[2]
        elseif startswith(line, "#STATUS#")
            status = split(line)[2]
        elseif startswith(line, "#OBJVAL#")
            objval = split(line)[2]
        elseif startswith(line, "#OBJBOUND#")
            objbound = split(line)[2]
        elseif startswith(line, "#TIMESOLVER#")
            solvertime = split(line)[2]
        elseif startswith(line, "#TIMEALL#")
            totaltime = split(line)[2]
        elseif startswith(line, "#SOLUTION#")
            solutionvec = split(line)[2]
            if startswith(solutionvec,'[') && endswith(solutionvec,']')
                solution = [parse(Float64,x) for x in split(solutionvec[2:end-1],',')]
            end
        end
        # elseif contains(line, "gap limit reached") # SCIP does this when it means optimal
        #     gaplimit=true
        #end
    end
    @show instance,length(solution)
    if length(solution) > 0
        objval_sol = validate_solution(instance,solution)
        try
            diff = abs(objval_sol-parse(Float64,objval))/abs(objval_sol)
            if diff > 1e-3
                @show diff
            end
        end
    end

    # if gaplimit
    #     @assert contains(solver, "SCIP")
    #     status = "Optimal"
    # end

    println(fd, "$solver,$instance,$status,$objval,$objbound,$solvertime,$totaltime,$(basename(filename))")
end

close(fd)

{'fraction_non_alphanumeric': 0.1328, 'fraction_numerical': 0.007314285714285714, 'mean_word_length': 2.6255178127589063, 'pattern_counts': {'":': 0, '<': 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': '1003672', 'n_tokens_mistral': 1417, 'n_tokens_neox': 1397, 'n_words': 302}