Yes well writing it and then making it work were two different things, condensing what was basically 4 separate calls to the database into one function so that the function gets the right data and then checks the data to see if it should be "included" i.e there is a threat / opportunity there wasn't easy and making sure it was passed all the right information in order to do that was harder.. it's a function and not part of the normal flow of data so variables and lots of them need to be passed to make it work..
if anyone wants to have a look at it, I'll try and port it to the "live" stats rather than the "dev test" pages which means a little clean up here and there