<commit_before>include("util.jl")
using ArgParse, DataFrames, Query

MapSize = Dict("Grid"=>874, "Jelly"=>1293, "L"=>1070, "Total"=>3237)

function log2csv(fname)
	df = DataFrame(epochtype = [], epoch = [], loss_reward = [], single = [], paragraph = [], map = [])
	s = readstring(pipeline(`less $fname`, `grep Epoch`))
	lns = split(s, "\n")

	for line in lns
		if line == ""
			continue
		end
		l = split(line)

		et = split(l[2], ":")[end-1]
		ep = parse(Int, split(l[3], ",")[1])
		ls = parse(Float32, split(l[6], ",")[1])
		sacc = parse(Float32, split(l[9], ",")[1])
		pacc = parse(Float32, split(l[12], ",")[1])

		push!(df, (et, ep, ls, sacc, pacc, l[end]))
	end
	return df
end


function results(fname, sortby)
	d = Dict()
	s = readstring(pipeline(`less $fname`, `grep Epoch`))
	lns = split(s, "\n")
	for line in lns
		if line == ""
			continue;
		end
		l = split(line)

		i = 5
		stop = false
		while !stop
			if startswith(l[i], sortby)
				stop = true
				i += 2
			else
				i += 1
			end
		end

		v = parse(Float64, split(l[i], ",")[1])
		if haskey(d, l[end])
			if v > d[l[end]]
				d[l[end]] = v
			end
		else
			d[l[end]] = v
		end
	end

	avg = 0.0
	for k in keys(d)
		avg += (d[k]*MapSize[k])/MapSize["Total"]
	end
	return avg, d
end

function printlogs(logs)
	for (r,d,f) in logs
		println("File: $f , Results: $r")
		for k in keys(d); println("$k : $(d[k])"); end
		println("")
	end
end

function main()
	args = parse_commandline()

	files = readdir(args["folder"])
	logs = Any[]

	overview = DataFrame(fname=[], singlebest=[], paragraph=[], single=[], paragraphbest=[])

	for f in files
		try
			df = log2csv(string(args["folder"], "/", f))
			writetable(string("experiments/", f, ".csv"), df)
			
			scores = Any[]

			for m in ["Grid", "Jelly", "L"]
				q1 = @from i in df begin
					@where i.map == m
					@orderby descending(i.single)
					@select i
					@collect DataFrame
				end

				q2 = @from i in df begin
					@where i.map == m
					@orderby descending(i.paragraph)
					@select i
					@collect DataFrame
				end

				push!(scores, (q1[1, 4], q1[1, 5], q2[1, 4], q2[1, 5]))
			end

			weighted = map(tup->map(x->x*MapSize[tup[2]]/MapSize["Total"], tup[1]), zip(scores, ["Grid", "Jelly", "L"]))
			push!(overview, (f,
			sum(map(x->x[1], weighted)),
			sum(map(x->x[2], weighted)),
			sum(map(x->x[3], weighted)),
			sum(map(x->x[4], weighted)),
			))
		catch e
			println(e)
			println("Error on $f")
		end<commit_msg>results<commit_after>include("util.jl")
using ArgParse, DataFrames, Query

MapSize = Dict("Grid"=>874, "Jelly"=>1293, "L"=>1070, "Total"=>3237)

function log2csv(fname)
	df = DataFrame(epochtype = [], epoch = [], loss_reward = [], single = [], paragraph = [], map = [])
	s = readstring(pipeline(`less $fname`, `grep Epoch`))
	lns = split(s, "\n")

	for line in lns
		if line == ""
			continue
		end
		l = split(line)

		et = split(l[2], ":")[end-1]
		ep = parse(Int, split(l[3], ",")[1])
		ls = parse(Float32, split(l[6], ",")[1])
		sacc = parse(Float32, split(l[9], ",")[1])
		pacc = parse(Float32, split(l[12], ",")[1])

		push!(df, (et, ep, ls, sacc, pacc, l[end]))
	end
	return df
end


function results(fname, sortby)
	d = Dict()
	s = readstring(pipeline(`less $fname`, `grep Epoch`))
	lns = split(s, "\n")
	for line in lns
		if line == ""
			continue;
		end
		l = split(line)

		i = 5
		stop = false
		while !stop
			if startswith(l[i], sortby)
				stop = true
				i += 2
			else
				i += 1
			end
		end

		v = parse(Float64, split(l[i], ",")[1])
		if haskey(d, l[end])
			if v > d[l[end]]
				d[l[end]] = v
			end
		else
			d[l[end]] = v
		end
	end

	avg = 0.0
	for k in keys(d)
		avg += (d[k]*MapSize[k])/MapSize["Total"]
	end
	return avg, d
end

function printlogs(logs)
	for (r,d,f) in logs
		println("File: $f , Results: $r")
		for k in keys(d); println("$k : $(d[k])"); end
		println("")
	end
end

function main()
	args = parse_commandline()

	files = readdir(args["folder"])
	logs = Any[]

	overview = DataFrame(fname=[], singlebest=[], paragraph=[], single=[], paragraphbest=[], scores=[])

	for f in files
		try
			df = log2csv(string(args["folder"], "/", f))
			writetable(string("experiments/", f, ".csv"), df)
			
			scores = Any[]

			for m in ["Grid", "Jelly", "L"]
				q1 = @from i in df begin
					@where i.map == m
					@orderby descending(i.single)
					@select i
					@collect DataFrame
				end

				q2 = @from i in df begin
					@where i.map == m
					@orderby descending(i.paragraph)
					@select i
					@collect DataFrame
				end

				push!(scores, (q1[1, 4], q1[1, 5], q2[1, 4], q2[1, 5]))
			end

			weighted = map(tup->map(x->x*MapSize[tup[2]]/MapSize["Total"], tup[1]), zip(scores, ["Grid", "Jelly", "L"]))
			push!(overview, (f,
			sum(map(x->x[1], weighted)),
			sum(map(x->x[2], weighted)),
			sum(map(x->x[3], weighted)),
			sum(map(x->x[4], weighted)),
			scores
			))
		catch e
			println(e)
			println("Error on $f")
		end
{'fraction_non_alphanumeric': 0.20868147544324434, 'fraction_numerical': 0.02527002241695537, 'mean_word_length': 3.245674740484429, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 25, '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': '2162060', 'n_tokens_mistral': 2368, 'n_tokens_neox': 2000, 'n_words': 519}