Skip to content

Health Software Common Practices

HSCP-T-010 · open test

Hosting indicator survey: six sourced indicators, valid health data certification

Serves HSCP-G-197 · Recipe: HSCP-R-023

Code under the licence Apache 2.0 · Python 3.10 or later, standard library only, no network access

What the test checks

The evidence is the annual indicator survey, one JSON object per hosting and per year (JSON Lines), following the recipe's data model:

Field Required Meaning
hebergement yes name of the hosting and site
annee yes year of the survey
role yes production, secours, sauvegarde, hors-production or tiers
donnees_sante yes true if the hosting holds health data
indicateurs yes pue, wue, renouvelable, chaleur_valorisee, gestion_equipements, localisation, each {valeur, source}, valeur: null if not provided
certification_sante for health data perimetre, fin_validite
releve_le yes date of the survey

The test accepts the survey if each line carries the six indicators, each value given with its source, a PUE of at least 1, shares between 0 and 1, and, for health data, a hosting certification whose end of validity has not passed on the date of the survey.

It reports, without refusing, each indicator not provided.

Running the test

python3 verifier.py releve.jsonl

--json returns the answer as JSON. Exit code: 0 evidence accepted, 1 evidence refused, 2 incorrect call. Python 3.10 or later, no dependency.

Examples

  • exemples/valide/: a certified production hosting with its six indicators sourced; a non-production cloud that provides only two indicators. Accepted, with the missing indicators reported.
  • exemples/refuse/: a PUE below 1, a value without a source, a share expressed as a percentage, a missing indicator, an expired certification; a role outside the list and health data without certification. Refused.

What the test does not say

  • It does not say that the host's values are accurate, nor that they cover the site serving the product rather than a group average: the source shows it, the review judges it.
  • It does not say that the list of hostings is complete.
  • It does not compute the footprint of the service.

Code

Download the test (zip archive: program, examples, README, licence) (10 KB) · verifier.py

The code and its messages are not translated (French).

#!/usr/bin/env python3
# SPDX-License-Identifier: Apache-2.0
# Copyright 2026 les contributeurs des Gestes communs du logiciel de santé
"""HSCP-T-010 : relevé des indicateurs environnementaux de chaque hébergement, source de chaque valeur, certification
de données de santé valide.

    python3 verifier.py <releve.jsonl> [--json]

Lit le relevé, un objet JSON par hébergement et par année (JSON Lines) : hebergement, annee, role, donnees_sante,
indicateurs {pue, wue, renouvelable, chaleur_valorisee, gestion_equipements, localisation : {valeur, source}},
certification_sante {perimetre, fin_validite}, releve_le.
Refus : ligne illisible ; champ obligatoire absent ; rôle hors liste ; couple hébergement et année en double ;
indicateur absent ; valeur donnée sans source ; PUE inférieur à 1 ; part (renouvelable, chaleur) hors de 0 à 1 ;
hébergement de données de santé sans certification, ou dont la certification a pris fin avant la date du relevé.
Note seulement : indicateur « non fourni » (valeur null).
Il ne dit pas que les valeurs de l'hébergeur sont exactes.

Codes de retour : 0 pièce acceptée, 1 pièce refusée, 2 appel incorrect.
Bibliothèque standard seulement, aucun accès réseau.
"""
import argparse
import datetime as dt
import json
import sys

ID = "HSCP-T-010"
ROLES = {"production", "secours", "sauvegarde", "hors-production", "tiers"}
INDICATEURS = ("pue", "wue", "renouvelable", "chaleur_valorisee", "gestion_equipements", "localisation")
OBLIGATOIRES = ("hebergement", "annee", "role", "donnees_sante", "indicateurs", "releve_le")


def jour(v):
    try:
        return dt.date.fromisoformat(str(v))
    except ValueError:
        return None


def verifier(chemin):
    refus, notes, vus, n = [], [], set(), 0
    for num, ligne in enumerate(open(chemin, encoding="utf-8"), 1):
        if not ligne.strip():
            continue
        try:
            h = json.loads(ligne)
            assert isinstance(h, dict)
        except (ValueError, AssertionError):
            refus.append(f"ligne {num} : objet JSON illisible")
            continue
        n += 1
        nom = f"{h.get('hebergement') or 'ligne ' + str(num)} ({h.get('annee')})"
        manque = [c for c in OBLIGATOIRES if h.get(c) in (None, "")]
        if manque:
            refus.append(f"{nom} : champ(s) absent(s) : {', '.join(manque)}")
            continue
        if nom in vus:
            refus.append(f"{nom} : relevé en double")
        vus.add(nom)
        if h["role"] not in ROLES:
            refus.append(f"{nom} : rôle hors liste")
        releve = jour(h["releve_le"])
        if releve is None:
            refus.append(f"{nom} : date du relevé illisible")
        ind = h["indicateurs"] if isinstance(h["indicateurs"], dict) else {}
        for k in INDICATEURS:
            x = ind.get(k)
            if not isinstance(x, dict) or "valeur" not in x:
                refus.append(f"{nom} : indicateur {k} absent (valeur ou null si non fourni)")
                continue
            v = x["valeur"]
            if v is None:
                notes.append(f"{nom} : {k} non fourni")
                continue
            if not x.get("source"):
                refus.append(f"{nom} : {k} donné sans source")
            if k == "pue" and (not isinstance(v, (int, float)) or v < 1):
                refus.append(f"{nom} : PUE illisible ou inférieur à 1")
            if k in ("renouvelable", "chaleur_valorisee") and (not isinstance(v, (int, float)) or not 0 <= v <= 1):
                refus.append(f"{nom} : {k} doit être une part entre 0 et 1")
        if h["donnees_sante"] is True:
            c = h.get("certification_sante")
            fin = jour(c.get("fin_validite")) if isinstance(c, dict) else None
            if not isinstance(c, dict) or not c.get("perimetre") or fin is None:
                refus.append(f"{nom} : données de santé sans certification d'hébergeur (périmètre et fin de validité)")
            elif releve and fin < releve:
                refus.append(f"{nom} : certification d'hébergeur de données de santé expirée à la date du relevé")
    if n == 0:
        refus.append("relevé vide")
    return refus, notes, n


def main(argv):
    p = argparse.ArgumentParser(prog="verifier.py", description=__doc__.splitlines()[0])
    p.add_argument("releve")
    p.add_argument("--json", action="store_true")
    try:
        a = p.parse_args(argv)
    except SystemExit:
        return 2
    try:
        refus, notes, n = verifier(a.releve)
    except OSError as e:
        print(f"{ID} : pièce illisible : {e}", file=sys.stderr)
        return 2
    if a.json:
        print(json.dumps({"test": ID, "accepte": not refus, "releves": n, "refus": refus, "notes": notes},
                         ensure_ascii=False, indent=2))
    else:
        print(f"{ID} : {'pièce acceptée' if not refus else 'pièce refusée'} ({n} relevé(s))")
        for r in refus:
            print("  refus :", r)
        for x in notes:
            print("  note :", x)
    return 0 if not refus else 1


if __name__ == "__main__":
    sys.exit(main(sys.argv[1:]))

Files of the test