def create_tex_best_count(countBest):
    parse_functions.create_output_dir("output/tex-count/")

    r = config_executor.restrictions['global']

    for strategy in countBest:
        texCountFile = "output/tex-count/" + strategy + ".tex"
        parse_functions.removing_existing_file(texCountFile)

        print("Creating text file: " + texCountFile)
        f = open(texCountFile, 'w')

        caption = ""
        f.write(tex_code.packages)
        f.write(tex_code.commands)
        f.write(tex_code.header_count_best(strategy))

        seg = r.segInf  #1
        while seg <= r.segSup:
            length = r.lenInf
            f.write(" & " + str(int(math.log(seg, 2))))

            while length <= r.lenSup:

                if (seg in countBest[strategy]):
                    if (length in countBest[strategy][seg]):
                        if (countBest[strategy][seg][length] == 0):
                            f.write(" & --")
                        else:
                            value = countBest[strategy][seg][length]

                            if (value >= 80):
                                boldValue = 0.6
                            else:
                                if (value >= 60):
                                    boldValue = 0.5
                                else:
                                    if (value >= 40):
                                        boldValue = 0.4
                                    else:
                                        if (value >= 20):
                                            boldValue = 0.3
                                        else:
                                            boldValue = 0.2

                            #f.write(" & \\bold"+ strategy + "{" + str(boldValue) + "}{\\ApplyGradient{" + str(value) + "}}")
                            f.write(" & \\bold{" + str(boldValue) +
                                    "}{\\ApplyGradient{" + str(value) + "}}")
                            #f.write(" & \\ApplyGradient{" + str(value) + "}")

                length *= 2

            seg *= 2
            f.write("\\\\ \n")

        f.write(tex_code.tail)
        f.close()
def create_tex_all_bests(countBest):
	parse_functions.create_output_dir("output/")
	
	texAllBestsFile = "output/all-bests.tex"
	parse_functions.removing_existing_file(texAllBestsFile)

	print("Creating text file: " + texAllBestsFile)
	f = open(texAllBestsFile, 'w')

	r = config_executor.restrictions['global']

	f.write(tex_code.packages)
	f.write(tex_code.commands)
	f.write(tex_code.header_all_bests())
	
	seg=r.segInf #1
	while seg <= r.segSup:
		
		length = r.lenInf
		f.write(" & " + str(int(math.log(seg,2))))

		while length <= r.lenSup:
			f.write(" &")
			if(length/seg <= 1):
				f.write(" \\noTest")
			else:
				f.write(" \makecell{")
				count = 0
				for strategy in countBest:
					if(seg in countBest[strategy]):
						if(length in countBest[strategy][seg]):
							if(countBest[strategy][seg][length] >= 1):
								f.write(" \\" + strategy + "\\")
								count += 1
								if(count == 2):
									#f.write(" \\\\ ")
									count = 0
				f.write(" }")
			length *= 2
			
		seg *= 2
		f.write("\\\\ \\hhline{|*{2}{~}||*{13}{-}|} \n")

	f.write(tex_code.tailAllBests)
	f.close()
def create_tex_the_best(selectedBests, outputfile, caption):
	parse_functions.create_output_dir("output/")
	
	texTheBestFile = outputfile
	parse_functions.removing_existing_file(texTheBestFile)

	print("Creating text file: " + texTheBestFile)
	f = open(texTheBestFile, 'w')

	r = config_executor.restrictions['global']

	f.write(tex_code.packages)
	f.write(tex_code.commands)
	f.write(tex_code.header_the_best(caption))
	
	seg=r.segInf #1
	while seg <= r.segSup:
		
		length = r.lenInf
		f.write(" & " + str(int(math.log(seg,2))))

		while length <= r.lenSup:
			
			if(length/seg <= 1):
				f.write(' & \\noTest')
			
			else:
				f.write(' & \\' + selectedBests[seg][length])
				
			length *= 2
			
		seg *= 2
		f.write("\\\\ \n")

	f.write(tex_code.tailTheBest)
	f.close()
def generate_multiple_scurves(scurves, outputdir):
	parse_functions.create_output_dir(outputdir)
	for strategy in scurves:
		create_scurve(scurves[strategy], outputdir + strategy + ".eps")