[ external image ]
The concept for colour rendering is thus:
For 0-50% failures within each test, the colour goes from RGB value 00FF00 to FFFF00.
For 50% and above, FFFF00 to FF0000.
The failure rate is of course expressed as failures/tests.
For <50%, we have to scale red between 0 and 255, so effectively we mult the rate by 2, so that the range covers 2 * rate * 255 = 0 to 255, instead of 0 to 127 with rate*255.
For >50%, we have to scale blue from 255 to 0, so we subtract 0.5 from the rate, and then mult by 2, so that we cover 255 - ((rate-0.5)*2*255) = 510 - (2*rate*255). as rate goes from 0.5 to 1, blue hence goes from 255 to 0.
The pseudocode that determines the colour is thus as follows:
Code: Select all
sub doColour{
my ($tests,$failures) = @_;
if ($tests == 0){
return ($failures == 0)? '00FF00' : 'FF0000';
}
return 'FF0000' if ($tests < $failures);
my $offset = $failures * 2 * 255 / $tests;
if ($offset < 255){
return sprintf("%02X",$offset).'FF00';
}else{
return 'FF'.sprintf("%02X",510-$offset).'00';
}
}