{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "urn:ledgermath:api:v1:index",
  "title": "LedgerMath data API, version 1: the table of contents",
  "description": "v1/index.json: where the list of Series, each benchmark's list of Series, the price files, the schemas, the evidence and the docs are. Start here. Every address a reader needs is written in the files, so a reader never builds one from an id; there are three exceptions, each given as a template: a blob named by hash inside a Run file, whose address is evidence.blob_url_template; a Series' file, whose address is series.series_file_url_template, for a reader who holds the Series' id and nothing else; and a benchmark's list, whose address is benchmarks.benchmark_file_url_template, for a reader who holds the benchmark's name and nothing else. Version 1 only ever gains fields: a field, once in a v1 file, keeps its name, its type and its meaning, and a reader ignores any field it does not know. That is why no object in this schema, nor in series-list, benchmark, series and series-month, forbids members it does not list. A change that would break a reader is published as v2, beside v1. The price files are the exception: each is the day's price file as LedgerMath keeps it, byte for byte, and follows its own schema, ledgermath.prices/1, whose root and LedgerMath's own objects are closed.",
  "type": "object",
  "required": ["schema", "schema_url", "url", "about", "versioning", "figures", "months", "layout", "docs", "newest_run_started_at", "recent_rounds", "series", "prices", "schemas", "evidence"],
  "properties": {
    "schema": { "description": "What this file is, and which version of its shape.", "const": "ledgermath.api.index/1" },
    "schema_url": { "description": "The address of this schema.", "$ref": "#/$defs/url" },
    "url": { "description": "This file's own address.", "$ref": "#/$defs/url" },
    "about": { "description": "What LedgerMath and this API are, in words.", "type": "string" },
    "versioning": { "description": "The rule the API's own v1 files keep, in words: v1 only ever gains fields; and its exception, the price files, which follow their own schema, closed.", "type": "string" },
    "figures": { "description": "How the numbers are written, in words: exactly as the Derivations hold them, never rounded.", "type": "string" },
    "months": { "description": "How each Series is split by month, in words, and exactly when a month file's bytes change: for a given layout, for four causes only, a past month included, so a reader holding a copy compares the month file's sha256, which the Series' file gives, before trusting it; and what a reader does when a month file it fetched does not match its Series file.", "type": "string" },
    "layout": { "description": "How the files are written, as a number. It increases when LedgerMath changes how the files are written (the order of a file's fields, the white space between them, a field every file of a kind gains), so that any file's bytes may change without one of the four causes months gives; for a given layout, those four are the only causes. Editing a schema's words does not change it, nor do the data, nor a field this file alone gains: this file changes with the data at every update, and no other file's bytes change with it. A reader holding copies of month files made under another layout fetches them again.", "type": "integer", "minimum": 1 },
    "docs": {
      "description": "Where the API is described in words: an absolute https address with a host, and a path, query or fragment if any, written with the characters RFC 3986 allows.",
      "type": "string",
      "pattern": "^https://[A-Za-z0-9](?:[A-Za-z0-9-]*[A-Za-z0-9])?(?:\\.[A-Za-z0-9](?:[A-Za-z0-9-]*[A-Za-z0-9])?)*(?::[0-9]{1,5})?(?:[/?#](?:[A-Za-z0-9._~:/?#\\[\\]@!$&'()*+,;=-]|%[0-9A-Fa-f]{2})*)?$"
    },
    "newest_run_started_at": {
      "description": "When the newest Run of any Series started (UTC, to the nanosecond, as the Run records it): how far the data reach. Null when there is no Series. No file of the API carries the time it was made; the same data give the same bytes.",
      "anyOf": [{ "$ref": "#/$defs/time" }, { "type": "null" }]
    },
    "recent_rounds": {
      "description": "What was measured most recently: the newest rounds of boots, newest first, each with its counts in all and by boot, and the address of each boot's summary; and the boot summaries left out of every round, with why. about says what a round is, how it is worked out from the boot summaries alone, what failed means, and when a round shown changes: any of them may, at a later update, not only the newest.",
      "type": "object",
      "required": ["about", "rounds", "left_out"],
      "properties": {
        "about": { "description": "What a round is, what each of its figures counts and when a round shown changes, in words. Its first two sentences state the rule a round is worked out by and how many rounds are given.", "type": "string" },
        "rounds": { "description": "The newest rounds, newest first: as many as about says, or fewer when there are fewer. Empty when no boot summary is read into a round.", "type": "array", "items": { "$ref": "#/$defs/round" } },
        "left_out": {
          "description": "The boot summaries of the evidence that are in no round: no boot summary stops the files being made, and one the rounds cannot be told from is left out and counted here, whatever it holds. A boot left out is in no round, so a round within the gap of its start may be missing it.",
          "type": "object",
          "required": ["count", "summaries"],
          "properties": {
            "count": { "description": "How many boot summaries are left out, of every day.", "type": "integer", "minimum": 0 },
            "summaries": {
              "description": "The newest of them by path (the day its boot started, then its name), newest first, 8 at most; each one sentence of a fixed few says why.",
              "type": "array",
              "maxItems": 8,
              "items": {
                "type": "object",
                "required": ["path", "boot_summary", "why"],
                "properties": {
                  "path": { "description": "The file's path in the evidence, under boots/: for a summary, boots/<yyyy>/<mm>/<dd>/<name>.json, the day its boot started and its name. Each byte of it that is not printable ASCII, and each %, double quote and backslash, is written as % and two hex digits, so each character is one byte; one longer than 120 characters is cut to its first 101, then ..., then the first 16 hex digits of the SHA-256 of the whole.", "type": "string", "pattern": "^boots/[\\x20-\\x7e]*$", "maxLength": 120 },
                  "boot_summary": { "description": "The summary's address, or null when the API does not serve it.", "anyOf": [{ "$ref": "#/$defs/url" }, { "type": "null" }] },
                  "why": { "description": "Why it is in no round: one of a fixed few sentences.", "type": "string" }
                }
              }
            }
          }
        }
      }
    },
    "series": {
      "description": "The list of Series.",
      "type": "object",
      "required": ["url", "schema_url", "count", "series_file_schema_url", "month_file_schema_url"],
      "properties": {
        "url": { "description": "v1/series.json: one row per Series, each with the address of its own file.", "$ref": "#/$defs/url" },
        "schema_url": { "description": "The schema of v1/series.json.", "$ref": "#/$defs/url" },
        "count": { "description": "How many Series it lists.", "type": "integer", "minimum": 0 },
        "series_file_schema_url": { "description": "The schema of one Series' file, v1/series/<id>.json: its summary, its newest Runs and its months.", "$ref": "#/$defs/url" },
        "month_file_schema_url": { "description": "The schema of one month of a Series, v1/series/<id>/<yyyy-mm>.json: every point of the Runs that started that month. A Series' file gives the address, sha256 and size of each of its months; months, above, says when a month file changes.", "$ref": "#/$defs/url" },
        "series_file_url_template": {
          "description": "A Series' file's address: replace {id} with the Series' id, 12 lower-case hex digits, as a row (id) gives it, in the list of every Series or a benchmark's list, and as a Series' file and a citation of the Series name it. For a reader who holds an id and nothing else; every other address of a Series is written in the files. A Series' file gives the address of each of its month files. Written since layout 2; a table of contents written before it lacks it.",
          "type": "string",
          "pattern": "^https?://.*/v1/series/\\{id\\}\\.json$"
        },
        "about": { "description": "Where the Series are listed, and what a Series' id is and where a reader finds one, in words. Written since layout 2.", "type": "string" }
      }
    },
    "benchmarks": {
      "description": "Each benchmark's list of Series: a file per benchmark, v1/benchmarks/<benchmark>.json, holding that benchmark's rows of the list of every Series, so that a reader finds a Series without fetching the whole list. about says what each file holds, which benchmarks list names, and what is left out of every one. Written since layout 2; a table of contents written before it lacks it.",
      "type": "object",
      "required": ["about", "schema_url", "benchmark_file_url_template", "count", "unlisted", "left_out", "list"],
      "properties": {
        "about": { "description": "What a benchmark's list holds, which benchmarks and Series have none, which benchmarks list names, what each entry of list gives, and what a reader does when the files it fetched are of different updates, in words.", "type": "string" },
        "schema_url": { "description": "The schema of a benchmark's list, v1/benchmarks/<benchmark>.json.", "$ref": "#/$defs/url" },
        "benchmark_file_url_template": {
          "description": "A benchmark's list's address: replace {benchmark} with the benchmark's name, as a row (benchmark) gives it. Every benchmark whose name is 1 to 64 characters, a lower-case letter, then lower-case letters, digits and underscores, has its list, whether list names it or not; so a reader holding the name, which every row and every Series' file gives (benchmark), reaches the list.",
          "type": "string",
          "pattern": "^https?://.*/v1/benchmarks/\\{benchmark\\}\\.json$"
        },
        "count": { "description": "How many benchmarks have a list.", "type": "integer", "minimum": 0 },
        "unlisted": { "description": "How many of them list does not name, being past its budget: each still has its list, at benchmark_file_url_template.", "type": "integer", "minimum": 0 },
        "left_out": { "description": "How many Series are in no benchmark's list, for any reason about gives; each is in the list of every Series, v1/series.json, and has its own file.", "type": "integer", "minimum": 0 },
        "list": { "description": "One entry per benchmark that has a list, by name, as many as fit in the budget about gives.", "type": "array", "items": { "$ref": "#/$defs/benchmark" } }
      }
    },
    "prices": {
      "description": "The daily price files: what AWS publicly charges for what LedgerMath measures, one file a day, each byte for byte as LedgerMath keeps it. A price is cited by the price file's path (path), the SKU and the rate code.",
      "type": "object",
      "required": ["schema_url", "newest", "files"],
      "properties": {
        "schema_url": { "description": "The schema of a price file (ledgermath.prices/1). A price file is a record, closed by its own schema.", "$ref": "#/$defs/url" },
        "newest": { "description": "The newest price file, or null when there is none.", "anyOf": [{ "$ref": "#/$defs/price_file" }, { "type": "null" }] },
        "files": { "description": "Every price file held, oldest first.", "type": "array", "items": { "$ref": "#/$defs/price_file" } }
      }
    },
    "schemas": {
      "description": "The JSON schema of each kind of file in v1, and of one line of a Run's stdout (events), which the Methods' definitions name.",
      "type": "array",
      "items": {
        "type": "object",
        "required": ["name", "describes", "url"],
        "properties": {
          "name": { "description": "The schema's name: its address ends v1/schemas/<name>.schema.json.", "type": "string" },
          "describes": { "description": "The files it describes, by path from the host's root; for a schema of what is not a file of v1, what it describes, in words.", "type": "string" },
          "url": { "description": "The schema's address.", "$ref": "#/$defs/url" }
        }
      }
    },
    "evidence": {
      "description": "Where the evidence behind the numbers is: Run files, boot summaries and blobs, served under the same address as the API, never copied into its files.",
      "type": "object",
      "required": ["about", "blob_url_template"],
      "properties": {
        "about": { "description": "Where the evidence is served and how a reader reaches each part of it, in words: a point's Run file and boot summary, and the blobs a Run file names by hash.", "type": "string" },
        "blob_url_template": {
          "description": "A blob's address: replace {hex} with the 64 hex digits of a sha256:<hex> a Run file names (its binary, source, runner, stdout, stderr, dump indexes and their sections).",
          "type": "string",
          "pattern": "^https?://.*/blobs/sha256/\\{hex\\}$"
        }
      }
    }
  },
  "$defs": {
    "url": { "description": "An address: an absolute URL starting http:// or https://.", "type": "string", "pattern": "^https?://" },
    "time": { "description": "UTC, to the nanosecond, as the Run or the boot summary it is read from records it.", "type": "string", "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}(\\.[0-9]+)?Z$" },
    "price_file": {
      "description": "One price file held: the date it is filed under, its own path, and its address in the API.",
      "type": "object",
      "required": ["date", "path", "url"],
      "properties": {
        "date": { "description": "The UTC date the prices were fetched.", "type": "string", "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}$" },
        "path": { "description": "The price file's own path, prices/<yyyy>/<mm>/<dd>/aws.json: the name a price citation gives it.", "type": "string", "pattern": "^prices/[0-9]{4}/[0-9]{2}/[0-9]{2}/aws\\.json$" },
        "url": { "description": "Its address: v1/prices/<yyyy-mm-dd>.json.", "$ref": "#/$defs/url" }
      }
    },
    "round": {
      "description": "One round of boots, with its figures in all, over every boot of the round, and by boot, for the first 12 (each figure in all is the sum of by_boot's when the round has at most 12 boots).",
      "type": "object",
      "required": ["started_at", "boots", "runs", "failed_runs", "runs_in_no_series", "build_failures", "not_run", "instance_types", "by_boot"],
      "properties": {
        "started_at": { "description": "When its first boot started (UTC, to the nanosecond), as that boot's summary records it.", "$ref": "#/$defs/time" },
        "boots": { "description": "How many boots it holds.", "type": "integer", "minimum": 1 },
        "runs": { "$ref": "#/$defs/runs" },
        "failed_runs": { "$ref": "#/$defs/failed_runs" },
        "runs_in_no_series": { "$ref": "#/$defs/runs_in_no_series" },
        "build_failures": { "$ref": "#/$defs/build_failures" },
        "not_run": { "$ref": "#/$defs/not_run" },
        "instance_types": { "description": "The instance type of each boot by_boot lists, in the order the boots started, as its summary names it (1 to 64 letters, digits, dots, hyphens or underscores); null for a boot whose summary names none.", "type": "array", "maxItems": 12, "items": { "anyOf": [{ "$ref": "#/$defs/instance_type" }, { "type": "null" }] } },
        "by_boot": { "description": "The boots of the round in the order they started, the first 12 at most: the round's figures count every boot, boots how many.", "type": "array", "maxItems": 12, "items": { "$ref": "#/$defs/round_boot" } }
      }
    },
    "round_boot": {
      "description": "One boot of a round: its summary's address, and its figures.",
      "type": "object",
      "required": ["boot_summary", "instance_type", "started_at", "runs", "failed_runs", "runs_in_no_series", "build_failures", "not_run"],
      "properties": {
        "boot_summary": { "description": "The boot's summary: every Run it left with how its binary exited, every build that failed and every execution that was not run, with why.", "$ref": "#/$defs/url" },
        "instance_type": { "description": "The instance type the boot ran on, as its summary names it: 1 to 64 letters, digits, dots, hyphens or underscores, a summary giving anything else being in no round; null when it names none.", "anyOf": [{ "$ref": "#/$defs/instance_type" }, { "type": "null" }] },
        "started_at": { "description": "When the boot started (UTC, to the nanosecond), as its summary records it.", "$ref": "#/$defs/time" },
        "runs": { "$ref": "#/$defs/runs" },
        "failed_runs": { "$ref": "#/$defs/failed_runs" },
        "runs_in_no_series": { "$ref": "#/$defs/runs_in_no_series" },
        "build_failures": { "$ref": "#/$defs/build_failures" },
        "not_run": { "$ref": "#/$defs/not_run" }
      }
    },
    "benchmark": {
      "description": "One benchmark's list of Series: where it is, and what it lists.",
      "type": "object",
      "required": ["name", "url", "series", "runs", "newest_run_started_at"],
      "properties": {
        "name": { "description": "The benchmark's name, as its Runs give it: 1 to 64 characters, a lower-case letter, then lower-case letters, digits and underscores.", "type": "string", "pattern": "^[a-z][a-z0-9_]{0,63}$" },
        "url": { "description": "The address of its list, v1/benchmarks/<benchmark>.json.", "$ref": "#/$defs/url" },
        "series": { "description": "How many Series its list holds.", "type": "integer", "minimum": 0 },
        "runs": { "description": "How many Runs those Series hold, counted or not.", "type": "integer", "minimum": 0 },
        "newest_run_started_at": { "description": "When the newest Run of those Series started; null when its list holds none.", "anyOf": [{ "$ref": "#/$defs/time" }, { "type": "null" }] }
      }
    },
    "instance_type": { "description": "An instance type as a summary in a round names it: 1 to 64 letters, digits, dots, hyphens or underscores, so it is written as many bytes as characters.", "type": "string", "pattern": "^[A-Za-z0-9._-]{1,64}$" },
    "runs": { "description": "How many Runs the boots left: the Runs their summaries list.", "type": "integer", "minimum": 0 },
    "failed_runs": {
      "description": "How many of those Runs are failed: not counted by Method requests v1, for a Run of a Series that Method derives (a Series of requests), and by Method series v1, for a Run of any other Series. So a Run of a Series of requests that exited 4, a request having failed, is failed only when requests v1 does not count it, as the Series' own figures say. Each failed Run is a point with counted false and its failure in its Series' month file, under that Method.",
      "type": "integer",
      "minimum": 0
    },
    "runs_in_no_series": { "description": "How many of those Runs are in no Series: their Run file is not in the evidence, or no Method could read it (the list of Series names each such file under each Method's unreadable). Neither counted nor failed.", "type": "integer", "minimum": 0 },
    "build_failures": { "description": "How many builds failed, or binaries could not be started, as the boots' summaries list them: an execution that never started has no Run.", "type": "integer", "minimum": 0 },
    "not_run": { "description": "How many executions the boots were to run and did not, as their summaries list them: each one benchmark, build and parameter set, with why.", "type": "integer", "minimum": 0 }
  }
}
