Get totalPassed, totalFailed, totalError variables

How can I get the totalPassed, totalFailed and totalError variables that the email template uses?

I am trying to write my own test reports, but if it’s relatively simple to extract those, it would be helpful.