{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/emporix/json-schema/emporix-import-stats-schema.json",
  "title": "Import statistics",
  "description": "Aggregated import metrics for the requested window and scope. A section that was not requested via the `sections` parameter is returned as `null`.",
  "x-generated": "2026-11-10",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/emporix-analytics-api-openapi.yml#/components/schemas/ImportStats",
  "type": "object",
  "properties": {
    "summary": {
      "$ref": "#/$defs/ImportStatsSummary"
    },
    "series": {
      "type": "array",
      "description": "Activity per time bucket, ordered oldest first and gap-free.",
      "items": {
        "$ref": "#/$defs/ImportStatsPoint"
      }
    },
    "streamHealth": {
      "type": "array",
      "description": "The health of each stream in scope.",
      "items": {
        "$ref": "#/$defs/ImportStreamHealth"
      }
    },
    "topFailingStreams": {
      "type": "array",
      "description": "The streams with the most errors during the time window, ordered by error count in descending order.",
      "items": {
        "$ref": "#/$defs/ImportStatsNamedCount"
      }
    },
    "errorBreakdown": {
      "type": "array",
      "description": "The most common errors in the window, grouped by stage and code.",
      "items": {
        "$ref": "#/$defs/ImportStatsErrorBucket"
      }
    },
    "streamChanges": {
      "$ref": "#/$defs/ImportStreamChanges"
    },
    "sourceIssues": {
      "type": "array",
      "description": "The source data does not match what the import process expects during the specified time window. These issues are not failures: the runs succeed, so they do not appear in pass/fail counters.",
      "items": {
        "$ref": "#/$defs/ImportSourceIssue"
      }
    }
  },
  "$defs": {
    "ImportEffectiveThresholds": {
      "title": "Effective thresholds",
      "type": "object",
      "description": "The threshold values the verdict was actually computed with, after resolving every level.",
      "properties": {
        "failureRatioAmber": {
          "type": "number",
          "format": "double"
        },
        "failureRatioRed": {
          "type": "number",
          "format": "double"
        },
        "staleAmberHours": {
          "type": "integer"
        },
        "staleRedHours": {
          "type": "integer"
        },
        "failedRunIsRed": {
          "type": "boolean"
        },
        "customised": {
          "type": "boolean",
          "description": "Whether any level overrides the built-in defaults."
        }
      }
    },
    "ImportSourceIssue": {
      "type": "object",
      "properties": {
        "streamId": {
          "type": "string",
          "format": "uuid",
          "description": "The stream the problem was observed on."
        },
        "configId": {
          "type": "string",
          "format": "uuid",
          "description": "The configuration that owns the stream."
        },
        "name": {
          "type": "string",
          "description": "The stream name."
        },
        "duplicateKeys": {
          "type": "integer",
          "description": "Source rows that repeat a key already imported in the same run. The import keeps the last row of each repeated key and discards earlier rows."
        },
        "unresolvedParents": {
          "type": "integer",
          "description": "Child records that were not imported because their parent could not be found."
        }
      }
    },
    "ImportStatsErrorBucket": {
      "title": "Error bucket",
      "type": "object",
      "description": "A count of errors sharing the same stage and code.",
      "properties": {
        "stage": {
          "type": "string",
          "description": "The pipeline stage the error occurred in."
        },
        "errorCode": {
          "type": "string"
        },
        "count": {
          "type": "integer"
        }
      }
    },
    "ImportStatsNamedCount": {
      "title": "Named count",
      "type": "object",
      "properties": {
        "streamId": {
          "type": "string",
          "format": "uuid"
        },
        "name": {
          "type": "string"
        },
        "count": {
          "type": "integer"
        }
      }
    },
    "ImportStatsPoint": {
      "title": "Statistics time bucket",
      "type": "object",
      "description": "One bucket of the time series, in UTC.",
      "properties": {
        "bucket": {
          "type": "string",
          "format": "date-time",
          "description": "The start of the bucket."
        },
        "runs": {
          "type": "integer"
        },
        "succeeded": {
          "type": "integer"
        },
        "failed": {
          "type": "integer"
        },
        "recordsRead": {
          "type": "integer"
        },
        "created": {
          "type": "integer"
        },
        "updated": {
          "type": "integer"
        },
        "deleted": {
          "type": "integer"
        },
        "skipped": {
          "type": "integer"
        },
        "failedRecords": {
          "type": "integer"
        }
      }
    },
    "ImportStatsSummary": {
      "title": "Statistics summary",
      "type": "object",
      "description": "Headline totals for the window. Rates are fractions between 0 and 1.",
      "properties": {
        "totalRuns": {
          "type": "integer",
          "description": "The number of runs started in the window."
        },
        "succeeded": {
          "type": "integer",
          "description": "The number of runs that finished successfully."
        },
        "partial": {
          "type": "integer",
          "description": "The number of runs that finished with some records failing."
        },
        "failed": {
          "type": "integer",
          "description": "The number of runs that failed."
        },
        "cancelled": {
          "type": "integer",
          "description": "The number of runs that were cancelled."
        },
        "recordsRead": {
          "type": "integer",
          "description": "The number of source records read."
        },
        "created": {
          "type": "integer",
          "description": "The number of target objects created."
        },
        "updated": {
          "type": "integer",
          "description": "The number of target objects updated."
        },
        "skipped": {
          "type": "integer",
          "description": "The number of records skipped because nothing had changed."
        },
        "deleted": {
          "type": "integer",
          "description": "The number of target objects deleted."
        },
        "failedRecords": {
          "type": "integer",
          "description": "The number of records that could not be imported."
        },
        "successRate": {
          "type": "number",
          "format": "double",
          "description": "The share of runs that finished successfully."
        },
        "failureRate": {
          "type": "number",
          "format": "double",
          "description": "The share of records that failed."
        },
        "deletionRate": {
          "type": "number",
          "format": "double",
          "description": "The share of processed records that resulted in a deletion."
        },
        "skipRate": {
          "type": "number",
          "format": "double",
          "description": "The share of records skipped as unchanged."
        },
        "avgRunDurationSec": {
          "type": "number",
          "format": "double",
          "description": "The mean duration of a finished run, in seconds, measured from when the run began executing (`executionStartedAt`). Time spent in the queue is not counted."
        },
        "avgCreatedPerRun": {
          "type": "number",
          "format": "double",
          "description": "The mean number of objects created per run."
        },
        "avgUpdatedPerRun": {
          "type": "number",
          "format": "double",
          "description": "The mean number of objects updated per run."
        },
        "distinctEntities": {
          "type": "integer",
          "description": "The number of distinct target objects currently held by the imports in scope."
        },
        "activeRuns": {
          "type": "integer",
          "description": "The number of runs currently in the `QUEUED`, `RUNNING`, or `RESUMABLE` status. When you filter by `streamId`, queued runs are not counted, because they have not started any stream yet."
        }
      }
    },
    "ImportStreamChanges": {
      "title": "Stream changes",
      "type": "object",
      "description": "The counts of streams added and removed during the time window.",
      "properties": {
        "added": {
          "type": "integer"
        },
        "removed": {
          "type": "integer"
        },
        "trackingSince": {
          "type": "string",
          "format": "date-time",
          "description": "When stream tracking began for the tenant. Streams created before this point are not counted, so a window reaching further back is not comparable."
        },
        "series": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "bucket": {
                "type": "string",
                "format": "date-time"
              },
              "added": {
                "type": "integer"
              },
              "removed": {
                "type": "integer"
              }
            }
          }
        }
      }
    },
    "ImportStreamHealth": {
      "title": "Stream health",
      "type": "object",
      "description": "The health of one stream over the window, and the thresholds the verdict used.",
      "properties": {
        "streamId": {
          "type": "string",
          "format": "uuid"
        },
        "configId": {
          "type": "string",
          "format": "uuid",
          "description": "The configuration the stream belongs to."
        },
        "name": {
          "type": "string"
        },
        "targetType": {
          "type": "string",
          "description": "The target type the stream writes to."
        },
        "lastRunStatus": {
          "type": "string",
          "description": "The status of the stream's most recent run."
        },
        "lastRunAt": {
          "type": "string",
          "format": "date-time"
        },
        "watermarkAgeSeconds": {
          "type": "integer",
          "description": "The number of seconds since the stream last detected new data."
        },
        "failureRatio": {
          "type": "number",
          "format": "double",
          "description": "The share of the stream's records that failed in the window."
        },
        "health": {
          "type": "string",
          "enum": [
            "GREEN",
            "AMBER",
            "RED"
          ],
          "description": "The stream's health verdict."
        },
        "thresholds": {
          "$ref": "#/$defs/ImportEffectiveThresholds"
        }
      }
    }
  }
}