Calculate A Score

Link to Calculate A Score copied to clipboard

axe DevTools Mobile provides data in the result object that can help track your accessibility progress over time. Below we'll highlight how to calculate an accessibility score from a scan in iOS and Android. This score will provide a metric of how accessibility is going in your application. Or, use these data points to develop a health metric that works for your team!

The Algorithm

At the core, we recommend using the same algorithm you may have seen in some of our other products, but with a mobile spin (we don't use the term pages). We encourage your team to modify the following algorithm to work for you!

(0.4 * s2 + 0.8 * s1 + s0) / TS

s2 = number of Serious scans

s1 = number of Moderate scans

s0 = number of scans with Minor or no issues

TS = Total scans

As you can see, scan results are filtered by impact: Critical, Serious, Moderate, or Minor. We define these terms in the following way:

  1. Minor scans = at least one Minor issue and no Moderate, Serious, or Critical issues
  2. Moderate scans = at least one Moderate issue and no Serious or Critical issues
  3. Serious scans = at least one Serious issue and no Critical issues
  4. Critical scans = at least one Critical issue

Note: if working with legacy data, you may also see the deprecated 'Blocker' impact.

Scoring a single scan

To illustrate how this algorithm works, a single scan would receive one of the following scores:

0% - At least one critical issue

40% - At least one serious issue, and no critical issues

80% - At least one moderate issue, and no serious or critical issues

100% - Only minor or no issues

Scoring a group of scans

For a group of scans, the group accessibility score is the average of the scores for each scan in that group. As an example, let's look at a group of nine screens with the following breakdown:

  • Two scans with critical issues (2)
  • One scan with a serious issue (1)
  • Two scans with moderate issues (2)
  • One scan with a minor issue (1)
  • Three scans with no issues (3)

Plug in the number of scans with their respective scores into our algorithm:

0.4 * 1 + 0.8 * 2 + 4 / 9

This results in a total group accessibility score of 67%.

iOS

From the result object, here's some sample code for pulling out the counts of each impact level:

let critical = result.failures.filter { $0.impact == .CRITICAL }.count
let serious = result.failures.filter { $0.impact == .SERIOUS }.count
let moderate = result.failures.filter { $0.impact == .MODERATE }.count
let minor = result.failures.filter { $0.impact == .MINOR }.count

Android

From the result object, here's some sample code for pulling out the counts of each impact level:

val minorImpactCount = AtomicInteger(0)
val blockerCount = AtomicInteger(0)
val criticalCount = AtomicInteger(0)
val moderateCount = AtomicInteger(0)
val serious = AtomicInteger(0)

result?.axeResult?.axeRuleResults?.forEach {
    when (it.impact) {
        AxeImpact.MINOR.value -> minorImpactCount.incrementAndGet()
        AxeImpact.BLOCKER.value -> blockerCount.incrementAndGet()
        AxeImpact.CRITICAL.value -> criticalCount.incrementAndGet()
        AxeImpact.MODERATE.value -> moderateCount.incrementAndGet()
        AxeImpact.SERIOUS.value -> serious.incrementAndGet()
        else -> {}
    }
}