{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/coderpad/json-schema/coderpad-campaign-insights-result-schema.json",
  "title": "CampaignInsightsResult",
  "description": "the statistics of a test campaign (the same data as the Insights tab)",
  "x-generated": "2026-11-04",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/coderpad-campaigns-api-openapi.yml#/components/schemas/CampaignInsightsResult",
  "type": "object",
  "properties": {
    "id": {
      "type": "integer",
      "description": "the test id",
      "format": "int32"
    },
    "candidates": {
      "$ref": "#/$defs/CampaignCandidatesInsights"
    },
    "scores": {
      "$ref": "#/$defs/CampaignScoresInsights"
    },
    "invitations": {
      "$ref": "#/$defs/CampaignInvitationsInsights"
    },
    "time_spent_seconds": {
      "$ref": "#/$defs/CampaignTimeSpentInsights"
    },
    "candidate_feedback_ratings": {
      "$ref": "#/$defs/CampaignCandidateFeedbackRatingsInsights"
    }
  },
  "$defs": {
    "CampaignCandidateFeedbackRatingsInsights": {
      "type": "object",
      "properties": {
        "distribution": {
          "type": "array",
          "description": "the candidate count of each rating",
          "items": {
            "$ref": "#/$defs/CampaignRatingCountInsights"
          }
        },
        "sample_size": {
          "type": "integer",
          "description": "how many candidates rated the test",
          "format": "int32"
        }
      },
      "description": "the ratings the candidates gave the test once they finished it"
    },
    "CampaignCandidatesInsights": {
      "type": "object",
      "properties": {
        "total": {
          "type": "integer",
          "description": "how many candidates the test holds, whether or not their invitation reached them",
          "format": "int32"
        },
        "by_test_status": {
          "type": "array",
          "description": "the candidate count of each test status, among waiting, in progress, completed, need review, aborted, expired and canceled",
          "items": {
            "$ref": "#/$defs/CampaignStatusCountInsights"
          }
        },
        "by_approval_status": {
          "type": "array",
          "description": "the candidate count of each approval status, among TO_REVIEW, PASSED and REJECTED. Only the candidates a recruiter can review are counted",
          "items": {
            "$ref": "#/$defs/CampaignStatusCountInsights"
          }
        },
        "by_tag": {
          "type": "array",
          "description": "the candidate count of each tag. A candidate carrying several tags is counted under each of them",
          "items": {
            "$ref": "#/$defs/CampaignTagCountInsights"
          }
        }
      },
      "description": "how the candidates of the test break down"
    },
    "CampaignInvitationsInsights": {
      "type": "object",
      "properties": {
        "window": {
          "$ref": "#/$defs/CampaignInvitationsWindowInsights"
        },
        "total": {
          "type": "integer",
          "description": "how many candidates were invited over the window",
          "format": "int32"
        },
        "by_month": {
          "type": "array",
          "description": "the candidate count of each month of the window, most recent last",
          "items": {
            "$ref": "#/$defs/CampaignMonthlyInvitationsInsights"
          }
        }
      },
      "description": "the invitations sent over the current calendar month and the eleven before it"
    },
    "CampaignInvitationsWindowInsights": {
      "type": "object",
      "properties": {
        "timezone": {
          "type": "string",
          "description": "the timezone the months are cut in"
        },
        "first_month": {
          "type": "string",
          "description": "the first month counted, eleven months before the current one"
        },
        "last_month": {
          "type": "string",
          "description": "the last month counted, the current one, still in progress"
        }
      },
      "description": "the calendar months the invitations are counted over"
    },
    "CampaignMonthlyInvitationsInsights": {
      "type": "object",
      "properties": {
        "month": {
          "type": "string",
          "description": "the month the candidates were invited in"
        },
        "count": {
          "type": "integer",
          "description": "how many candidates were invited that month",
          "format": "int32"
        }
      },
      "description": "how many candidates a month holds"
    },
    "CampaignRatingCountInsights": {
      "type": "object",
      "properties": {
        "rating": {
          "type": "integer",
          "description": "the rating the candidates gave, from 1 to 5",
          "format": "int32"
        },
        "count": {
          "type": "integer",
          "description": "how many candidates gave the rating",
          "format": "int32"
        }
      },
      "description": "how many candidates a rating holds"
    },
    "CampaignScoreRangeInsights": {
      "type": "object",
      "properties": {
        "count": {
          "type": "integer",
          "description": "how many candidates scored in the range",
          "format": "int32"
        },
        "min_inclusive": {
          "type": "integer",
          "description": "the lowest score of the range, in percent",
          "format": "int32"
        },
        "max_exclusive": {
          "type": "integer",
          "description": "the score the next range starts at, in percent. Left out on the last range, which holds a score of 100 too",
          "format": "int32"
        }
      },
      "description": "how many candidates a score range holds"
    },
    "CampaignScoresInsights": {
      "type": "object",
      "properties": {
        "mean": {
          "type": "number",
          "description": "the average score, in percent",
          "format": "double"
        },
        "distribution": {
          "type": "array",
          "description": "the candidate count of each ten-point score range",
          "items": {
            "$ref": "#/$defs/CampaignScoreRangeInsights"
          }
        },
        "sample_size": {
          "type": "integer",
          "description": "how many candidates the scores are computed on",
          "format": "int32"
        }
      },
      "description": "the scores of the candidates who submitted the test"
    },
    "CampaignStatusCountInsights": {
      "type": "object",
      "properties": {
        "status": {
          "type": "string",
          "description": "the status the candidates are counted under"
        },
        "count": {
          "type": "integer",
          "description": "how many candidates hold the status",
          "format": "int32"
        }
      },
      "description": "how many candidates a status holds"
    },
    "CampaignTagCountInsights": {
      "type": "object",
      "properties": {
        "tag": {
          "type": "string",
          "description": "the tag the candidates are counted under"
        },
        "count": {
          "type": "integer",
          "description": "how many candidates carry the tag",
          "format": "int32"
        }
      },
      "description": "how many candidates a tag holds"
    },
    "CampaignTimeSpentInsights": {
      "type": "object",
      "properties": {
        "mean": {
          "type": "number",
          "description": "the average time spent, in seconds",
          "format": "double"
        },
        "p25": {
          "type": "number",
          "description": "the time spent a quarter of the candidates stayed under, in seconds",
          "format": "double"
        },
        "median": {
          "type": "number",
          "description": "the time spent half of the candidates stayed under, in seconds",
          "format": "double"
        },
        "p75": {
          "type": "number",
          "description": "the time spent three quarters of the candidates stayed under, in seconds",
          "format": "double"
        },
        "sample_size": {
          "type": "integer",
          "description": "how many candidates the time spent is computed on",
          "format": "int32"
        }
      },
      "description": "how long the candidates who finished the test took"
    }
  }
}