Exemplo n.º 1
0
def validation_code(name,param,output,xmlname,val_param,val_depend,precision,pathD):
	result=1
	for out in output:
		if len(out.getDependencies())==0:
			print "[Validation] error : no dependencies..."
			break
		depend=out.getDependencies()[0]
		func=out.getFuncs()[0]
		data=[]
		for val_dep in val_depend[depend]:
			list_param=[]
			val=[]
			for par in param:
				if (par.getName()!=depend):
					list_param.append(par.getName())
					val.append(val_param[par.getName()][0])
				else:
					list_param.append(par.getName())
					val.append(val_dep)
					par_depend=par
			data.append(xmlParser.parse_xml_result(xmlname,name,list_param,val,out.getName()))

		data=map(float,data)
		val=map(float,val_depend[depend])
		data_temp=[val,data]

		temp=error.validation(data_temp,func,depend,precision)
		result=temp and result

		nb_decimal=len(str(precision))-1

		#Transformation des donnees pour affichage graphique
		data2=error.changedata(data_temp,func)
		func2=error.changefunc(func)
		data3 = error.fit(data2[0],data2[1])

		#On veut un certain nombre de chiffres significatifs pour les estimations
		#bo abscisse a l'origine et b1 pente
		b0=str(decimal.Decimal(str(round(exp(data3[1][0]),nb_decimal))))
		b1=str(decimal.Decimal(str(round(data3[1][1],nb_decimal))))

		#On teste si le parametre variable contient une description latex
		if (par_depend.getAttrNames().count("latex")):
				chaine=par_depend.getAttrValues()[3]
				func=func.replace(par_depend.getName(),par_depend.getAttrValues()[3])
		else:
				chaine=depend

		#On teste le nombre de log appliques a la fonction
	   	#Permet de mettre les bons titres aux axes et de rappliquer un log aux donnees si besoin
		if ((func2.count("log")-func.count("log"))==2):
				debut_log="log(log("
				fin_log="))"
				data_temp=[data_temp[0],log(data_temp[1])]
				interp="exp(chaine+**{"+b1+"})"
		else:
				debut_log="log("
				fin_log=")"
				interp=chaine+"**{"+b1+"}"

		a=float(exp(data3[1][0]))
		b=float(data3[1][1])

		graph = displayGraphics.graphBuilder(name+" (generated on "+datetime.datetime.now().strftime("%d/%m/%Y %H:%M:%S)"),3,0,"log(x)","log(y)")

		graph.addTriangle(func.split("**")[-1],b1)

		graph.addFunction("y(x)="+func.replace(par_depend.getName(),'x'),"theoritical",color.rgb.red)
		graph.addFunction("y(x)="+str(a)+"*x**"+str(b),"practical",color.rgb.blue)

		graph.addPoints(data_temp,"data")

		graph.addInfo("$"+str(out.getAttrValues()[2])+"$"+" : "+"$"
                      +str(chaine)+"$"+"$\longrightarrow$"+"$"+func.replace("**","^")+"$",
                      "Interpolated : "+"$"+str(chaine)+"$"
					  +"$\longrightarrow$"+"$"+interp.replace("**","^")+"$",
                      temp,precision)

		print("[Validation] : writing "+ pathD+out.getName()+".pdf")
		graph.writePDFfile(pathD+out.getName())
	return result
Exemplo n.º 2
0
def validation_code(name, param, output, xmlname, val_param, val_depend,
                    precision, pathD):
    result = 1
    for out in output:
        if len(out.getDependencies()) == 0:
            print "[Validation] error : no dependencies..."
            break
        depend = out.getDependencies()[0]
        func = out.getFuncs()[0]
        data = []
        for val_dep in val_depend[depend]:
            list_param = []
            val = []
            for par in param:
                if (par.getName() != depend):
                    list_param.append(par.getName())
                    val.append(val_param[par.getName()][0])
                else:
                    list_param.append(par.getName())
                    val.append(val_dep)
                    par_depend = par
            data.append(
                xmlParser.parse_xml_result(xmlname, name, list_param, val,
                                           out.getName()))

        data = map(float, data)
        val = map(float, val_depend[depend])
        data_temp = [val, data]

        temp = error.validation(data_temp, func, depend, precision)
        result = temp and result

        nb_decimal = len(str(precision)) - 1

        #Transformation des donnees pour affichage graphique
        data2 = error.changedata(data_temp, func)
        func2 = error.changefunc(func)
        data3 = error.fit(data2[0], data2[1])

        #On veut un certain nombre de chiffres significatifs pour les estimations
        #bo abscisse a l'origine et b1 pente
        b0 = str(decimal.Decimal(str(round(exp(data3[1][0]), nb_decimal))))
        b1 = str(decimal.Decimal(str(round(data3[1][1], nb_decimal))))

        #On teste si le parametre variable contient une description latex
        if (par_depend.getAttrNames().count("latex")):
            chaine = par_depend.getAttrValues()[3]
            func = func.replace(par_depend.getName(),
                                par_depend.getAttrValues()[3])
        else:
            chaine = depend

        #On teste le nombre de log appliques a la fonction
        #Permet de mettre les bons titres aux axes et de rappliquer un log aux donnees si besoin
        if ((func2.count("log") - func.count("log")) == 2):
            debut_log = "log(log("
            fin_log = "))"
            data_temp = [data_temp[0], log(data_temp[1])]
            interp = "exp(chaine+**{" + b1 + "})"
        else:
            debut_log = "log("
            fin_log = ")"
            interp = chaine + "**{" + b1 + "}"

        a = float(exp(data3[1][0]))
        b = float(data3[1][1])

        graph = displayGraphics.graphBuilder(
            name + " (generated on " +
            datetime.datetime.now().strftime("%d/%m/%Y %H:%M:%S)"), 3, 0,
            "log(x)", "log(y)")

        graph.addTriangle(func.split("**")[-1], b1)

        graph.addFunction("y(x)=" + func.replace(par_depend.getName(), 'x'),
                          "theoritical", color.rgb.red)
        graph.addFunction("y(x)=" + str(a) + "*x**" + str(b), "practical",
                          color.rgb.blue)

        graph.addPoints(data_temp, "data")

        graph.addInfo(
            "$" + str(out.getAttrValues()[2]) + "$" + " : " + "$" +
            str(chaine) + "$" + "$\longrightarrow$" + "$" +
            func.replace("**", "^") + "$",
            "Interpolated : " + "$" + str(chaine) + "$" + "$\longrightarrow$" +
            "$" + interp.replace("**", "^") + "$", temp, precision)

        print("[Validation] : writing " + pathD + out.getName() + ".pdf")
        graph.writePDFfile(pathD + out.getName())
    return result
Exemplo n.º 3
0
print(data2)
print(func2)

data3=error.slope_calc(data,func)
print(data3)

#V1 affichage sans utiliser nos fonctions
c=canvas.canvas()
g=c.insert(graph.graphxy(width=8,
                  x=graph.axis.log(min=1, max=10),
                  y=graph.axis.linear(min=1, max=10)))

g.plot([graph.data.list(array([data[0],log(data[1])]).transpose(), x=1,y=2,)],[graph.style.symbol()])

g.plot([graph.data.list(array([data[0],error.peval(data2[0],data3)]).transpose(), x=1, y=2,)],[graph.style.line([color.rgb.red])])

g.plot([graph.data.function('y(x)='+func2)],[graph.style.line([color.rgb.blue])])


g.writePDFfile("plot")

print(error.validation(data,func,0.01))


#V2 affichage en utilisant nos fonctions
h=displayGraphics.create_graph_XlogYlin(8,1,10,1,10)
displayGraphics.plotPointsXlinYlog(h,data)
displayGraphics.plotLinesXlinYlin(h,data[0],error.peval(data2[0],data3),color.rgb.red)
displayGraphics.plotFunction(h,func2,color.rgb.blue)
h.writePDFfile("plot2")
g.plot(
    [graph.data.list(
        array([data[0], log(data[1])]).transpose(),
        x=1,
        y=2,
    )], [graph.style.symbol()])

g.plot([
    graph.data.list(
        array([data[0], error.peval(data2[0], data3)]).transpose(),
        x=1,
        y=2,
    )
], [graph.style.line([color.rgb.red])])

g.plot([graph.data.function('y(x)=' + func2)],
       [graph.style.line([color.rgb.blue])])

g.writePDFfile("plot")

print(error.validation(data, func, 0.01))

#V2 affichage en utilisant nos fonctions
h = displayGraphics.create_graph_XlogYlin(8, 1, 10, 1, 10)
displayGraphics.plotPointsXlinYlog(h, data)
displayGraphics.plotLinesXlinYlin(h, data[0], error.peval(data2[0], data3),
                                  color.rgb.red)
displayGraphics.plotFunction(h, func2, color.rgb.blue)
h.writePDFfile("plot2")