Log in

View Full Version : [TBA]: Incorrect qual points


Brandon_L
01-04-2015, 20:29
Seems like TBA is incorrectly calculating the district qual points for each event. I'm not sure if its been noticed or if a fix is in the works or what TBA is even coded in, but I was messing around in php and got it running. If you'd like to steal the code and port it over to whatever you guys use, works for me.

function qual_points($n, $r){
$a=1.07;
return ceil((inverf(($n-(2*$r)+2)/($a*$n))*(10/(inverf(1/$a))))+12);
}

function sign($number) {
return ( $number > 0 ) ? 1 : ( ( $number < 0 ) ? -1 : 0 );
}

function inverf($x) {
$a=0.147;
return sign($x)*sqrt(sqrt(pow(((2/(pi()*$a))+((log(1-pow($x, 2)))/2)), 2) - ((log(1-pow($x, 2)))/$a) )-((2/(pi()*$a))+(log(1-pow($x, 2)))/2));
}*credit to my bro paul for some help

called with qual_points(n,r) where n=the number of teams at the event and r=rank

the formula I'm using for inverf(x) comes from an approximation found on wikipedia (http://en.wikipedia.org/wiki/Error_function#Approximation_with_elementary_funct ions)

http://upload.wikimedia.org/math/1/8/0/18032f4d9ac1cae98508d89b266a03ac.png

These incorrect calculations currently up are messing with a project I'm currently working on with the API, so I don't know if there is anything else I can do to help sort it out but please let me know.

plnyyanks
01-04-2015, 20:46
Thanks for the reminder on this. TBA is written in python, and has an open issue for it (https://github.com/the-blue-alliance/the-blue-alliance/issues/1160). We'll get it corrected soon

Eugene Fang
01-04-2015, 20:55
Thanks. Our inverse error function indeed gets points off by 1 sometimes.

Brandon_L
01-04-2015, 22:22
it is off by as much as 3 points in many places.

Brandon_L
02-04-2015, 01:37
Converted over to python by a friend

def sign(x):
if x > 0:
return 1
elif x < 0:
return -1
else:
return 0

def inverf(x):
a = 0.147
formula = math.sqrt((math.sqrt((((2 / (math.pi * a)) + ((math.log(1 - x**2)) / 2))**2) - ((math.log(1 - x**2)) / a))) - ((2 / (math.pi * a)) + (math.log(1 - x**2)) / 2))
return formula*sign(x)

def qual_points(n, r):
a = 1.07
formula = math.ceil((inverf((n-(2*r)+2)/(a*n))*(10/(inverf(1/a))))+12)
return formula