{
 "$schema": "https://json-schema.org/draft/2020-12/schema",
 "$id": "https://rankator.com/schema/resultats/1.0.json",
 "title": "Rankator results of a test campaign (single schema)",
 "description": "One file is one campaign for one niche, with every tool tested and every pass. This is the only format accepted for Rankator results (rankator.resultats/1.0). The formulas are in the public protocol, parts 5 to 7: https://rankator.com/methodology/n1/1.0/. A separate example file with two tools, marked FICTITIOUS, is published next to this schema. Field names and enumerated values are in English.",
 "type": "object",
 "additionalProperties": false,
 "required": [
  "schema",
  "fictitious",
  "protocol",
  "campaign",
  "reference_app",
  "tools",
  "ranking",
  "publication"
 ],
 "properties": {
  "schema": {
   "const": "rankator.resultats/1.0"
  },
  "fictitious": {
   "type": "boolean",
   "description": "true means an example or a trial run; a fictitious file can never be published as a result."
  },
  "protocol": {
   "type": "object",
   "properties": {
    "id": {
     "type": "string",
     "pattern": "^RKT-PROTO-[A-Z0-9]+$"
    },
    "version": {
     "type": "string",
     "pattern": "^[0-9]+\\.[0-9]+$"
    },
    "url": {
     "type": "string",
     "format": "uri"
    },
    "sha256": {
     "type": "string",
     "pattern": "^[0-9a-f]{64}$"
    }
   },
   "additionalProperties": false,
   "required": [
    "id",
    "version",
    "url",
    "sha256"
   ]
  },
  "campaign": {
   "type": "object",
   "properties": {
    "id": {
     "type": "string",
     "pattern": "^N[0-9]+-[0-9]{4}-[0-9]{2}(-[a-z0-9]+)?$"
    },
    "niche": {
     "type": "string"
    },
    "start": {
     "type": "string",
     "format": "date-time"
    },
    "end": {
     "type": "string",
     "format": "date-time"
    },
    "region": {
     "type": "string"
    },
    "bench": {
     "type": "object",
     "properties": {
      "version": {
       "type": "string",
       "pattern": "^bench-[0-9]{4}\\.[0-9]{2}\\.[0-9]{2}-[0-9a-f]{7,}$"
      },
      "browser": {
       "type": "object",
       "properties": {
        "name": {
         "enum": [
          "chromium",
          "firefox",
          "webkit"
         ]
        },
        "version": {
         "type": "string"
        }
       },
       "additionalProperties": false,
       "required": [
        "name",
        "version"
       ]
      }
     },
     "additionalProperties": false,
     "required": [
      "version",
      "browser"
     ]
    }
   },
   "additionalProperties": false,
   "required": [
    "id",
    "niche",
    "start",
    "end",
    "region",
    "bench"
   ]
  },
  "reference_app": {
   "type": "object",
   "properties": {
    "id": {
     "type": "string"
    },
    "spec_version": {
     "type": "string"
    },
    "spec_sha256": {
     "type": "string",
     "pattern": "^[0-9a-f]{64}$"
    },
    "seed_sha256": {
     "type": "string",
     "pattern": "^[0-9a-f]{64}$"
    }
   },
   "additionalProperties": false,
   "required": [
    "id",
    "spec_version",
    "spec_sha256",
    "seed_sha256"
   ]
  },
  "tools": {
   "type": "array",
   "minItems": 1,
   "items": {
    "$ref": "#/$defs/tool"
   }
  },
  "ranking": {
   "type": "array",
   "items": {
    "type": "object",
    "properties": {
     "rank": {
      "type": "integer",
      "minimum": 1
     },
     "tool": {
      "type": "string"
     },
     "score": {
      "type": "integer",
      "minimum": 0,
      "maximum": 100
     },
     "tied_with": {
      "type": "array",
      "items": {
       "type": "string"
      }
     }
    },
    "additionalProperties": false,
    "required": [
     "rank",
     "tool",
     "score",
     "tied_with"
    ]
   }
  },
  "publication": {
   "type": "object",
   "properties": {
    "status": {
     "enum": [
      "draft",
      "publishable",
      "published",
      "suspended"
     ]
    },
    "date": {
     "type": [
      "string",
      "null"
     ],
     "format": "date-time"
    },
    "license": {
     "const": "CC-BY-4.0"
    },
    "valid_until": {
     "type": [
      "string",
      "null"
     ],
     "format": "date"
    },
    "bundle_sha256": {
     "type": [
      "string",
      "null"
     ],
     "pattern": "^[0-9a-f]{64}$"
    }
   },
   "additionalProperties": false,
   "required": [
    "status",
    "date",
    "license",
    "valid_until",
    "bundle_sha256"
   ]
  },
  "_warning": {
   "type": "string",
   "description": "Present, and starting with FICTITIOUS, when fictitious is true."
  }
 },
 "allOf": [
  {
   "if": {
    "properties": {
     "fictitious": {
      "const": true
     }
    }
   },
   "then": {
    "required": [
     "_warning"
    ],
    "properties": {
     "_warning": {
      "pattern": "^(FICTIF|FICTITIOUS)"
     },
     "publication": {
      "properties": {
       "status": {
        "const": "draft"
       }
      }
     }
    }
   }
  }
 ],
 "$defs": {
  "tool": {
   "type": "object",
   "properties": {
    "id": {
     "type": "string",
     "pattern": "^[a-z0-9-]+$"
    },
    "name": {
     "type": "string"
    },
    "url": {
     "type": "string",
     "format": "uri"
    },
    "rankable": {
     "type": "boolean",
     "description": "false for any Framework product: it may be measured, and is never ranked."
    },
    "affiliation": {
     "type": "object",
     "properties": {
      "program": {
       "type": "boolean"
      },
      "network": {
       "type": [
        "string",
        "null"
       ]
      },
      "link_present": {
       "type": "boolean"
      }
     },
     "additionalProperties": false,
     "required": [
      "program",
      "network",
      "link_present"
     ]
    },
    "tool_version": {
     "type": "object",
     "properties": {
      "plan": {
       "type": "string"
      },
      "monthly_price_usd": {
       "type": [
        "number",
        "null"
       ],
       "minimum": 0
      },
      "accessed_at": {
       "type": "string",
       "format": "date-time"
      },
      "version_id": {
       "type": [
        "string",
        "null"
       ]
      },
      "changelog_url": {
       "type": [
        "string",
        "null"
       ]
      }
     },
     "additionalProperties": false,
     "required": [
      "plan",
      "monthly_price_usd",
      "accessed_at",
      "version_id",
      "changelog_url"
     ]
    },
    "build": {
     "type": "object",
     "properties": {
      "start": {
       "type": "string",
       "format": "date-time"
      },
      "duration_min": {
       "type": "number",
       "minimum": 0
      },
      "iterations": {
       "type": "integer",
       "minimum": 0
      },
      "budget_exhausted": {
       "type": "boolean"
      },
      "unmet_requirements": {
       "type": "array",
       "items": {
        "type": "string",
        "pattern": "^EX-[0-9]{2}$"
       }
      },
      "build_log_url": {
       "type": "string"
      }
     },
     "additionalProperties": false,
     "required": [
      "start",
      "duration_min",
      "iterations",
      "budget_exhausted",
      "unmet_requirements",
      "build_log_url"
     ]
    },
    "instance": {
     "type": "object",
     "properties": {
      "url": {
       "type": "string",
       "format": "uri"
      },
      "hosting": {
       "type": "string"
      }
     },
     "additionalProperties": false,
     "required": [
      "url",
      "hosting"
     ]
    },
    "passes": {
     "type": "array",
     "minItems": 2,
     "maxItems": 3,
     "items": {
      "$ref": "#/$defs/pass"
     }
    },
    "replayability": {
     "type": "object",
     "properties": {
      "compliant": {
       "type": "boolean"
      },
      "retained_passes": {
       "type": "array",
       "items": {
        "type": "integer",
        "minimum": 1,
        "maximum": 3
       },
       "minItems": 2,
       "maxItems": 2
      },
      "score_gap": {
       "type": "number",
       "minimum": 0
      },
      "out_of_tolerance": {
       "type": "array",
       "items": {
        "type": "string"
       }
      }
     },
     "additionalProperties": false,
     "required": [
      "compliant",
      "retained_passes",
      "score_gap",
      "out_of_tolerance"
     ]
    },
    "result": {
     "oneOf": [
      {
       "type": "null"
      },
      {
       "$ref": "#/$defs/result"
      }
     ],
     "description": "null when the result cannot be replayed or the tool cannot be ranked."
    }
   },
   "additionalProperties": false,
   "required": [
    "id",
    "name",
    "url",
    "rankable",
    "affiliation",
    "tool_version",
    "build",
    "instance",
    "passes",
    "replayability",
    "result"
   ]
  },
  "pass": {
   "type": "object",
   "properties": {
    "n": {
     "type": "integer",
     "minimum": 1,
     "maximum": 3
    },
    "start": {
     "type": "string",
     "format": "date-time"
    },
    "end": {
     "type": "string",
     "format": "date-time"
    },
    "reset": {
     "type": "boolean",
     "const": true
    },
    "journeys": {
     "type": "array",
     "minItems": 9,
     "maxItems": 9,
     "items": {
      "type": "object",
      "properties": {
       "id": {
        "type": "string",
        "pattern": "^P[1-9]$"
       },
       "weight": {
        "type": "integer",
        "minimum": 1
       },
       "outcome": {
        "enum": [
         "passed",
         "unstable",
         "failed",
         "not_feasible"
        ]
       },
       "attempts": {
        "type": "integer",
        "minimum": 0,
        "maximum": 3
       },
       "duration_ms": {
        "type": "number",
        "minimum": 0
       },
       "evidence": {
        "type": "string"
       }
      },
      "additionalProperties": false,
      "required": [
       "id",
       "weight",
       "outcome",
       "attempts",
       "duration_ms",
       "evidence"
      ]
     }
    },
    "performance": {
     "type": "object",
     "properties": {
      "pages": {
       "type": "array",
       "minItems": 1,
       "items": {
        "type": "object",
        "properties": {
         "path": {
          "type": "string"
         },
         "lcp_ms": {
          "type": "array",
          "items": {
           "type": "number",
           "minimum": 0
          },
          "minItems": 1,
          "maxItems": 3
         },
         "cls": {
          "type": "array",
          "items": {
           "type": "number",
           "minimum": 0
          },
          "minItems": 1,
          "maxItems": 3
         },
         "ttfb_ms": {
          "type": "array",
          "items": {
           "type": "number",
           "minimum": 0
          },
          "minItems": 1,
          "maxItems": 3
         },
         "weight_bytes": {
          "type": "integer",
          "minimum": 0
         },
         "requests": {
          "type": "integer",
          "minimum": 0
         }
        },
        "additionalProperties": false,
        "required": [
         "path",
         "lcp_ms",
         "cls",
         "ttfb_ms",
         "weight_bytes",
         "requests"
        ]
       }
      },
      "slow_mobile_lcp_ms": {
       "type": "array",
       "items": {
        "type": "number",
        "minimum": 0
       },
       "minItems": 1,
       "maxItems": 3
      },
      "light_load": {
       "type": "object",
       "properties": {
        "requests": {
         "type": "integer"
        },
        "p95_ms": {
         "type": "number",
         "minimum": 0
        },
        "errors": {
         "type": "integer",
         "minimum": 0
        }
       },
       "additionalProperties": false,
       "required": [
        "requests",
        "p95_ms",
        "errors"
       ]
      }
     },
     "additionalProperties": false,
     "required": [
      "pages",
      "slow_mobile_lcp_ms",
      "light_load"
     ]
    },
    "errors": {
     "type": "object",
     "properties": {
      "signatures": {
       "type": "array",
       "items": {
        "type": "object",
        "properties": {
         "type": {
          "enum": [
           "unhandled_js",
           "internal_http_error",
           "broken_link"
          ]
         },
         "signature": {
          "type": "string"
         },
         "page": {
          "type": "string"
         }
        },
        "additionalProperties": false,
        "required": [
         "type",
         "signature",
         "page"
        ]
       }
      }
     },
     "additionalProperties": false,
     "required": [
      "signatures"
     ]
    },
    "accessibility": {
     "type": "object",
     "properties": {
      "violations": {
       "type": "array",
       "items": {
        "type": "object",
        "properties": {
         "rule": {
          "type": "string"
         },
         "page": {
          "type": "string"
         },
         "impact": {
          "enum": [
           "critical",
           "serious",
           "moderate",
           "minor"
          ]
         }
        },
        "additionalProperties": false,
        "required": [
         "rule",
         "page",
         "impact"
        ]
       }
      }
     },
     "additionalProperties": false,
     "required": [
      "violations"
     ]
    },
    "passive_security": {
     "type": "object",
     "properties": {
      "checks": {
       "type": "array",
       "minItems": 8,
       "maxItems": 8,
       "items": {
        "type": "object",
        "properties": {
         "id": {
          "enum": [
           "https_hsts",
           "csp",
           "x_content_type_options",
           "anti_framing",
           "referrer_policy",
           "cookie_secure",
           "cookie_httponly",
           "no_mixed_content"
          ]
         },
         "ok": {
          "type": "boolean"
         }
        },
        "additionalProperties": false,
        "required": [
         "id",
         "ok"
        ]
       }
      }
     },
     "additionalProperties": false,
     "required": [
      "checks"
     ]
    },
    "resilience": {
     "type": "object",
     "properties": {
      "scenarios": {
       "type": "array",
       "minItems": 3,
       "maxItems": 3,
       "items": {
        "type": "object",
        "properties": {
         "id": {
          "enum": [
           "R1_slow_network",
           "R2_offline_booking",
           "R3_api_500"
          ]
         },
         "ok": {
          "type": "boolean"
         }
        },
        "additionalProperties": false,
        "required": [
         "id",
         "ok"
        ]
       }
      }
     },
     "additionalProperties": false,
     "required": [
      "scenarios"
     ]
    },
    "mobile": {
     "type": "object",
     "properties": {
      "overflow_pages": {
       "type": "array",
       "items": {
        "type": "string"
       }
      }
     },
     "additionalProperties": false,
     "required": [
      "overflow_pages"
     ]
    },
    "notes": {
     "$ref": "#/$defs/notes"
    },
    "pass_score": {
     "type": "number",
     "minimum": 0,
     "maximum": 100
    }
   },
   "additionalProperties": false,
   "required": [
    "n",
    "start",
    "end",
    "reset",
    "journeys",
    "performance",
    "errors",
    "accessibility",
    "passive_security",
    "resilience",
    "mobile",
    "notes",
    "pass_score"
   ]
  },
  "notes": {
   "type": "object",
   "properties": {
    "F": {
     "type": "number",
     "minimum": 0,
     "maximum": 1
    },
    "P": {
     "type": "number",
     "minimum": 0,
     "maximum": 1
    },
    "E": {
     "type": "number",
     "minimum": 0,
     "maximum": 1
    },
    "A": {
     "type": "number",
     "minimum": 0,
     "maximum": 1
    },
    "S": {
     "type": "number",
     "minimum": 0,
     "maximum": 1
    },
    "D": {
     "type": "number",
     "minimum": 0,
     "maximum": 1
    },
    "R": {
     "type": "number",
     "minimum": 0,
     "maximum": 1
    },
    "V": {
     "type": "number",
     "minimum": 0,
     "maximum": 1
    }
   },
   "additionalProperties": false,
   "required": [
    "F",
    "P",
    "E",
    "A",
    "S",
    "D",
    "R",
    "V"
   ]
  },
  "result": {
   "type": "object",
   "properties": {
    "notes": {
     "$ref": "#/$defs/notes"
    },
    "score": {
     "type": "integer",
     "minimum": 0,
     "maximum": 100
    },
    "exact_score": {
     "type": "number",
     "minimum": 0,
     "maximum": 100
    },
    "interval": {
     "type": "object",
     "properties": {
      "low": {
       "type": "number"
      },
      "high": {
       "type": "number"
      },
      "method": {
       "const": "wilson95_F+min_max_passes"
      }
     },
     "additionalProperties": false,
     "required": [
      "low",
      "high",
      "method"
     ]
    },
    "isolation_cap": {
     "type": "boolean"
    },
    "rank": {
     "type": "integer",
     "minimum": 1
    },
    "quadrant": {
     "type": "object",
     "properties": {
      "x_reliability": {
       "type": "number",
       "minimum": 0,
       "maximum": 100
      },
      "y_technical_quality": {
       "type": "number",
       "minimum": 0,
       "maximum": 100
      },
      "zone": {
       "enum": [
        "complete",
        "functional",
        "technical",
        "maturing"
       ]
      }
     },
     "additionalProperties": false,
     "required": [
      "x_reliability",
      "y_technical_quality",
      "zone"
     ]
    }
   },
   "additionalProperties": false,
   "required": [
    "notes",
    "score",
    "exact_score",
    "interval",
    "isolation_cap",
    "rank",
    "quadrant"
   ]
  }
 }
}
