{
  "$id": "/insights/game",
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "additionalProperties": false,
  "description": "Various insights about the game for displaying in the web app.",
  "properties": {
    "coach_advice": {
      "description": "Lists of advice for each player.",
      "items": {
        "anyOf": [
          {
            "type": "null"
          },
          {
            "additionalProperties": false,
            "description": "Advice based on rank of certain features in the distribution of games (how well the player performed in some areas relative to other games).",
            "properties": {
              "advice": {
                "description": "A list of advice for the player to improve their game (ranked by relevance score, starting from the best).",
                "items": {
                  "additionalProperties": false,
                  "description": "Particular advice",
                  "properties": {
                    "ci": {
                      "description": "The confidence interval ([low, high]) of the value.",
                      "items": {
                        "type": "number"
                      },
                      "maxItems": 2,
                      "minItems": 2,
                      "type": "array"
                    },
                    "kind": {
                      "description": "The statistic in question.",
                      "enum": [
                        "serve_quality",
                        "legal_serve_percentage",
                        "return_quality",
                        "third_shot_quality",
                        "legal_third_shot_percentage",
                        "drop_shot_consistency",
                        "dink_consistency",
                        "rallies_won_with_resets",
                        "rallies_won_with_speedups",
                        "kitchen_arrival_percentage_on_serve"
                      ],
                      "type": "string"
                    },
                    "method": {
                      "description": "The method used to compute the CI for the statistic's rank.",
                      "enum": [
                        "wilson",
                        "avg_rank",
                        "avg",
                        "scalar"
                      ],
                      "type": "string"
                    },
                    "relevance": {
                      "description": "Relevance score indicating how \"interesting\" this advice is (how much of a bad outlier is this particular stat). Higher is better. Calculated from the upper bound of CI, and then slightly weighted (with various weights for different stats) to make the typical advice more interesting.",
                      "type": "number"
                    },
                    "value": {
                      "description": "The raw value of the statistic in question.",
                      "type": "number"
                    }
                  },
                  "required": [
                    "relevance",
                    "kind",
                    "value",
                    "ci",
                    "method"
                  ],
                  "title": "Advice",
                  "type": "object"
                },
                "type": "array"
              }
            },
            "required": [
              "advice"
            ],
            "title": "Coach Advice",
            "type": "object"
          }
        ]
      },
      "maxItems": 4,
      "minItems": 4,
      "type": "array"
    },
    "component_stats": {
      "additionalProperties": false,
      "description": "Per-player values of the component-rating sub-stats shown in the web app, one locked key per stat. Rates are fractions in [0, 1]. Computed for every doubles game whether or not ratings are; omitted for games the stats collector rejects (singles or malformed).",
      "properties": {
        "0_speeds": {
          "description": "Mean speed in mph of the player's serves that stayed in play: serves into the net, short or landing out are left out, and a serve heading out that the receiver played anyway counts. This is the game page's Average Serve. Unit: mph. Component: ball_control. Values for each player (indexed by player ID); null where the stat has no value for that player.  pbql 0.17.1 shots:  SELECT rally.num, shot.num, shot.hitter.id, shot.speed FROM \"<vid>:<session>\" WHERE shot.num = 1 AND NOT shot.errors.faults.net AND NOT shot.errors.faults.short AND NOT (exists(shot.errors.faults.out.outcome) AND shot.errors.faults.out.outcome = \"landed\")  Aggregation:  SELECT shot.hitter.id, avg(shot.speed), count() FROM \"<vid>:<session>\" WHERE shot.num = 1 AND NOT shot.errors.faults.net AND NOT shot.errors.faults.short AND NOT (exists(shot.errors.faults.out.outcome) AND shot.errors.faults.out.outcome = \"landed\") GROUP BY shot.hitter.id",
          "items": {
            "anyOf": [
              {
                "type": "null"
              },
              {
                "minimum": 0,
                "type": "number"
              }
            ]
          },
          "maxItems": 4,
          "minItems": 4,
          "type": "array"
        },
        "1_speeds": {
          "description": "Mean speed in mph of the player's returns of serve. Counts returns that have an execution-quality score and no fault. Unit: mph. Component: ball_control. Values for each player (indexed by player ID); null where the stat has no value for that player.  pbql 0.17.1 shots:  SELECT rally.num, shot.num, shot.hitter.id, shot.speed FROM \"<vid>:<session>\" WHERE shot.num = 2 AND exists(shot.quality.execution) AND NOT shot.hasFault  Aggregation:  SELECT shot.hitter.id, avg(shot.speed), count() FROM \"<vid>:<session>\" WHERE shot.num = 2 AND exists(shot.quality.execution) AND NOT shot.hasFault GROUP BY shot.hitter.id",
          "items": {
            "anyOf": [
              {
                "type": "null"
              },
              {
                "minimum": 0,
                "type": "number"
              }
            ]
          },
          "maxItems": 4,
          "minItems": 4,
          "type": "array"
        },
        "def_to_off_transitions_per_game": {
          "description": "Number of times in the game the team went from a positional disadvantage to an advantage: the team's average advantage turns from negative to positive between consecutive team shots in a rally, whatever the rally's result. Unit: a count. Team stat: both partners carry the same value. Component: defense. Values for each player (indexed by player ID); null where the stat has no value for that player. Not expressible in pbql 0.17.1.",
          "items": {
            "anyOf": [
              {
                "type": "null"
              },
              {
                "minimum": 0,
                "type": "number"
              }
            ]
          },
          "maxItems": 4,
          "minItems": 4,
          "type": "array"
        },
        "defense_flip_index": {
          "description": "Of the rallies the team started on defense (its first two shots at a clear positional disadvantage) and whose winner is known, the fraction where the team later reached a clear advantage and won the rally. Unit: a fraction in [0, 1]. Team stat: both partners carry the same value. Component: defense. Values for each player (indexed by player ID); null where the stat has no value for that player. Not expressible in pbql 0.17.1.",
          "items": {
            "anyOf": [
              {
                "type": "null"
              },
              {
                "maximum": 1,
                "minimum": 0,
                "type": "number"
              }
            ]
          },
          "maxItems": 4,
          "minItems": 4,
          "type": "array"
        },
        "dink_attempts_per_game": {
          "description": "Number of dinks the player hit in the game (shots typed as a dink), faulted dinks included. Unit: a count. Component: kitchen_game. Values for each player (indexed by player ID); null where the stat has no value for that player.  pbql 0.17.1 shots:  SELECT rally.num, shot.num, shot.hitter.id, 1 FROM \"<vid>:<session>\" WHERE shot.type = \"dink\"  Aggregation:  SELECT shot.hitter.id, sum(1), count() FROM \"<vid>:<session>\" WHERE shot.type = \"dink\" GROUP BY shot.hitter.id",
          "items": {
            "anyOf": [
              {
                "type": "null"
              },
              {
                "minimum": 0,
                "type": "number"
              }
            ]
          },
          "maxItems": 4,
          "minItems": 4,
          "type": "array"
        },
        "drive_heights": {
          "description": "Mean peak height in feet of the player's drives. Counts drives that have an execution-quality score and did not fault into the net or land short. Unit: feet. Component: ball_control. Values for each player (indexed by player ID); null where the stat has no value for that player.  pbql 0.17.1 shots:  SELECT rally.num, shot.num, shot.hitter.id, shot.peak.z FROM \"<vid>:<session>\" WHERE shot.type = \"drive\" AND exists(shot.quality.execution) AND NOT shot.errors.faults.net AND NOT shot.errors.faults.short  Aggregation:  SELECT shot.hitter.id, avg(shot.peak.z), count() FROM \"<vid>:<session>\" WHERE shot.type = \"drive\" AND exists(shot.quality.execution) AND NOT shot.errors.faults.net AND NOT shot.errors.faults.short GROUP BY shot.hitter.id",
          "items": {
            "anyOf": [
              {
                "type": "null"
              },
              {
                "minimum": 0,
                "type": "number"
              }
            ]
          },
          "maxItems": 4,
          "minItems": 4,
          "type": "array"
        },
        "errors_after_opponent_shot_rate": {
          "description": "Fraction of the player's shots (serves included) that were rally-ending errors committed after an opponent's shot. Every such fault counts, whether or not it is classified as unforced; faulted serves do not count. In the queries, `winnerType = \"forced_fault\"` marks the opponent's shot before any such fault. Rallies flagged likely bad are excluded. Unit: a fraction in [0, 1]. Component: defense. Values for each player (indexed by player ID); null where the stat has no value for that player.  pbql 0.17.1 shots:  SELECT rally.num, shot.num, shot.hitter.id, exists(shot[-1].winnerType) AND shot[-1].winnerType = \"forced_fault\" AND shot[-1].hitter.team != shot.hitter.team FROM \"<vid>:<session>\"  Aggregation:  SELECT shot.hitter.id, avg(exists(shot[-1].winnerType) AND shot[-1].winnerType = \"forced_fault\" AND shot[-1].hitter.team != shot.hitter.team), count() FROM \"<vid>:<session>\" GROUP BY shot.hitter.id  pbql caveat: pbql cannot leave out rallies flagged likely bad, so its value can differ slightly.",
          "items": {
            "anyOf": [
              {
                "type": "null"
              },
              {
                "maximum": 1,
                "minimum": 0,
                "type": "number"
              }
            ]
          },
          "maxItems": 4,
          "minItems": 4,
          "type": "array"
        },
        "net_domination_share": {
          "description": "Share of rally time when at least one of the team's players is at the kitchen and no opponent is, averaged over the game's rallies (each rally counts equally). Rallies flagged likely bad are excluded. Unit: a fraction in [0, 1]. Team stat: both partners carry the same value. Component: offense. Values for each player (indexed by player ID); null where the stat has no value for that player. Not expressible in pbql 0.17.1.",
          "items": {
            "anyOf": [
              {
                "type": "null"
              },
              {
                "maximum": 1,
                "minimum": 0,
                "type": "number"
              }
            ]
          },
          "maxItems": 4,
          "minItems": 4,
          "type": "array"
        },
        "offensive_shot_pct": {
          "description": "Fraction of the player's non-serve shots with a known positional advantage that were played with the advantage on the player's side. In doubles both partners share one advantage value, so this is the team's advantage. Unit: a fraction in [0, 1]. Component: offense. Values for each player (indexed by player ID); null where the stat has no value for that player. Not expressible in pbql 0.17.1.",
          "items": {
            "anyOf": [
              {
                "type": "null"
              },
              {
                "maximum": 1,
                "minimum": 0,
                "type": "number"
              }
            ]
          },
          "maxItems": 4,
          "minItems": 4,
          "type": "array"
        },
        "partner_distance": {
          "description": "Mean distance in feet between the player and their partner, measured at each of the player's shots. Unit: feet. Component: kitchen_game. Values for each player (indexed by player ID); null where the stat has no value for that player. Not expressible in pbql 0.17.1.",
          "items": {
            "anyOf": [
              {
                "type": "null"
              },
              {
                "minimum": 0,
                "type": "number"
              }
            ]
          },
          "maxItems": 4,
          "minItems": 4,
          "type": "array"
        },
        "partner_nvz_arrival_together_pct": {
          "description": "Fraction of the team's rallies in which both partners reached the kitchen and their first kitchen arrivals were within 1 second of each other. Counts rallies, not flagged likely bad, in which both partners reached the kitchen. Unit: a fraction in [0, 1]. Team stat: both partners carry the same value. Component: kitchen_game. Values for each player (indexed by player ID); null where the stat has no value for that player. Not expressible in pbql 0.17.1.",
          "items": {
            "anyOf": [
              {
                "type": "null"
              },
              {
                "maximum": 1,
                "minimum": 0,
                "type": "number"
              }
            ]
          },
          "maxItems": 4,
          "minItems": 4,
          "type": "array"
        },
        "return_unforced_error_rate": {
          "description": "Fraction of the player's returns of serve that were unforced errors. Unit: a fraction in [0, 1]. Component: targeting. Values for each player (indexed by player ID); null where the stat has no value for that player.  pbql 0.17.1 shots:  SELECT rally.num, shot.num, shot.hitter.id, exists(shot.errors.unforced) AND shot.errors.unforced FROM \"<vid>:<session>\" WHERE shot.num = 2  Aggregation:  SELECT shot.hitter.id, avg(exists(shot.errors.unforced) AND shot.errors.unforced), count() FROM \"<vid>:<session>\" WHERE shot.num = 2 GROUP BY shot.hitter.id",
          "items": {
            "anyOf": [
              {
                "type": "null"
              },
              {
                "maximum": 1,
                "minimum": 0,
                "type": "number"
              }
            ]
          },
          "maxItems": 4,
          "minItems": 4,
          "type": "array"
        },
        "return_win_rate_when_drive": {
          "description": "Fraction of rallies the player's team won after the player's faster returns of serve: returns above the player's own median return speed in this game. Rallies flagged likely bad or with an unknown winner are excluded. Unit: a fraction in [0, 1]. Component: targeting. Values for each player (indexed by player ID); null where the stat has no value for that player. Not expressible in pbql 0.17.1.",
          "items": {
            "anyOf": [
              {
                "type": "null"
              },
              {
                "maximum": 1,
                "minimum": 0,
                "type": "number"
              }
            ]
          },
          "maxItems": 4,
          "minItems": 4,
          "type": "array"
        },
        "return_win_rate_when_float": {
          "description": "Fraction of rallies the player's team won after the player's slower returns of serve: returns at or below the player's own median return speed in this game. Rallies flagged likely bad or with an unknown winner are excluded. Unit: a fraction in [0, 1]. Component: targeting. Values for each player (indexed by player ID); null where the stat has no value for that player. Not expressible in pbql 0.17.1.",
          "items": {
            "anyOf": [
              {
                "type": "null"
              },
              {
                "maximum": 1,
                "minimum": 0,
                "type": "number"
              }
            ]
          },
          "maxItems": 4,
          "minItems": 4,
          "type": "array"
        },
        "speedup_count_rallies_all_shots_count_rallies": {
          "description": "Of the rallies in which the player hit at least one shot with an execution-quality score, the fraction in which at least one of those shots was a speedup. Unit: a fraction in [0, 1]. Component: offense. Values for each player (indexed by player ID); null where the stat has no value for that player.  pbql 0.17.1 rallies:  SELECT rally.num, shot.num, me.id, rally.count(shot.hitter = me AND shot.isSpeedup AND exists(shot.quality.execution)) > 0 FROM \"<vid>:<session>\" WHERE shot.num = 1 AND rally.count(shot.hitter = me AND exists(shot.quality.execution)) > 0  Aggregation: Run once per player, as `me`.  SELECT avg(rally.count(shot.hitter = me AND shot.isSpeedup AND exists(shot.quality.execution)) > 0), count() FROM \"<vid>:<session>\" WHERE shot.num = 1 AND rally.count(shot.hitter = me AND exists(shot.quality.execution)) > 0",
          "items": {
            "anyOf": [
              {
                "type": "null"
              },
              {
                "maximum": 1,
                "minimum": 0,
                "type": "number"
              }
            ]
          },
          "maxItems": 4,
          "minItems": 4,
          "type": "array"
        }
      },
      "required": [
        "dink_attempts_per_game",
        "partner_distance",
        "partner_nvz_arrival_together_pct",
        "drive_heights",
        "0_speeds",
        "1_speeds",
        "def_to_off_transitions_per_game",
        "errors_after_opponent_shot_rate",
        "defense_flip_index",
        "net_domination_share",
        "offensive_shot_pct",
        "speedup_count_rallies_all_shots_count_rallies",
        "return_win_rate_when_float",
        "return_win_rate_when_drive",
        "return_unforced_error_rate"
      ],
      "type": "object"
    },
    "game_data": {
      "$ref": "/insights/game_data",
      "description": "Contains data about the game overall.",
      "title": "Game Data"
    },
    "highlights": {
      "description": "A list of the noteworthy exchanges within the game.",
      "items": {
        "$ref": "/insights/highlight",
        "description": "a section of the video that stands out",
        "title": "Highlight"
      },
      "type": "array"
    },
    "md5_full": {
      "const": "1674d8c6482483c3f220ca0af5c34714",
      "description": "MD5 of the all aspects of this schema (including non-functional elements like documentation)"
    },
    "md5_functional": {
      "const": "1ab0ec47a10285c15fae943869cfe47d",
      "description": "MD5 of the functional aspects of this schema"
    },
    "player_data": {
      "description": "Each player's data over the whole game for the web app.  If the player's location is unknown, the value for that player will be null.",
      "items": {
        "anyOf": [
          {
            "type": "null"
          },
          {
            "$ref": "/insights/player_data",
            "description": "Contains player-specific data over the whole game for the web app.",
            "title": "Player Data"
          }
        ]
      },
      "maxItems": 4,
      "minItems": 4,
      "type": "array"
    },
    "rallies": {
      "description": "An ordered list of the rallies within a singles or doubles game. This structure can also represent a distinct session or drill.",
      "items": {
        "additionalProperties": false,
        "properties": {
          "end_ms": {
            "$ref": "/types/video_time",
            "description": "The end time of the rally (milliseconds).",
            "title": "Video Milliseconds"
          },
          "players": {
            "description": "The positional information for players during a rally.  If the player's location is unknown, the value for that player will be null.",
            "items": {
              "anyOf": [
                {
                  "type": "null"
                },
                {
                  "additionalProperties": false,
                  "properties": {
                    "had_arrival_opportunity": {
                      "description": "`true` if this player had a fair opportunity to arrive at the kitchen in this rally",
                      "type": "boolean"
                    },
                    "kitchen_arrivals": {
                      "description": "List of periods when the player was positioned at the kitchen line",
                      "items": {
                        "additionalProperties": false,
                        "description": "A period within the rally when this player was positioned at the kitchen",
                        "properties": {
                          "ft_moved": {
                            "$ref": "/types/vector",
                            "description": "Total denoised displacement movement vector in feet that this player moved during this kitchen line period, tracking x and y directions separately.",
                            "title": "Vector"
                          },
                          "since_ms": {
                            "description": "Millisecond timestamp (from the beginning of the rally) when the player first arrived at the kitchen line",
                            "type": "integer"
                          },
                          "until_ms": {
                            "description": "Millisecond timestamp (from the beginning of the rally) when the player was pushed back from the kitchen line",
                            "type": "integer"
                          }
                        },
                        "required": [
                          "since_ms"
                        ],
                        "title": "Kitchen Line Period",
                        "type": "object"
                      },
                      "type": "array"
                    },
                    "started_on_left_side": {
                      "description": "`true` if this player started on the left side",
                      "type": "boolean"
                    }
                  },
                  "required": [
                    "started_on_left_side",
                    "had_arrival_opportunity"
                  ],
                  "type": "object"
                }
              ]
            },
            "maxItems": 4,
            "minItems": 4,
            "title": "Rally Player Positions",
            "type": "array"
          },
          "scoring_info": {
            "additionalProperties": false,
            "description": "Scoring rally-specific information. Note that the running_score and the server_number reflect the score DURING this rally (so not taking into account this rally's outcome).",
            "properties": {
              "likely_bad": {
                "description": "If true, this rally is likely bad and should be ignored while computing the ongoing score.",
                "type": "boolean"
              },
              "running_score": {
                "description": "The running score of the game during _this_ rally. The first element is the score of team 0, and the second element is the score of team 1.",
                "items": {
                  "type": "integer"
                },
                "maxItems": 2,
                "minItems": 2,
                "title": "Running Score",
                "type": "array"
              },
              "server_number": {
                "description": "Server number for _this_ rally, is only there for the side-out scoring mode.",
                "maximum": 2,
                "minimum": 1,
                "type": "integer"
              }
            },
            "title": "Scoring Info",
            "type": "object"
          },
          "serving_transition": {
            "additionalProperties": false,
            "description": "Present in doubles when the serving team attempted a third shot (third-shot errors included) and the rally's opening is reliably recognized. Omitted otherwise.",
            "properties": {
              "established": {
                "description": "Whether both serving partners got forward together, covering their lanes and out from under immediate pressure, at some point in the rally. Omitted if unknown.",
                "type": "boolean"
              }
            },
            "type": "object"
          },
          "shots": {
            "description": "The sequence of shots during this rally.",
            "items": {
              "$ref": "/insights/shot",
              "title": "Shot"
            },
            "type": "array"
          },
          "start_ms": {
            "$ref": "/types/video_time",
            "description": "The start time of the rally (milliseconds).",
            "title": "Video Milliseconds"
          },
          "team_stats": {
            "description": "Team-level statistics for the rally (omitted for singles).",
            "items": {
              "additionalProperties": false,
              "properties": {
                "average_ft_between_players_along_x": {
                  "description": "Average distance in feet between team players during the rally.",
                  "type": "number"
                },
                "side_switches_ms": {
                  "description": "Moments (ms in the video) where team switched their relative X position (left/right) for at least a second.",
                  "items": {
                    "minimum": 0,
                    "type": "integer"
                  },
                  "type": "array"
                },
                "x_distance_optimality": {
                  "description": "0-1 score of the consistency of the team's maintenance of the optimal x-direction distance between players (we consider 7-10 ft as optimal, and we give lower score for 5-7 or 10-12 ft. Everything below or above that is a 0).",
                  "type": "number"
                }
              },
              "type": "object"
            },
            "maxItems": 2,
            "minItems": 2,
            "type": "array"
          },
          "winning_team": {
            "description": "Which team won the rally (team 0 or 1)",
            "maximum": 1,
            "minimum": 0,
            "type": "integer"
          }
        },
        "required": [
          "start_ms",
          "end_ms",
          "players",
          "shots",
          "scoring_info"
        ],
        "title": "Rally",
        "type": "object"
      },
      "minItems": 1,
      "type": "array"
    },
    "session": {
      "$ref": "/types/session",
      "description": "Defines aspects of the session or game being played.",
      "title": "Session"
    },
    "stats": {
      "additionalProperties": false,
      "description": "All collected stats keyed by stat name. Each entry contains the metric value for every player.",
      "patternProperties": {
        "^[a-zA-Z0-9_]+$": {
          "description": "Values for each player (indexed by player ID).",
          "items": {
            "anyOf": [
              {
                "type": "null"
              },
              {
                "type": "number"
              }
            ]
          },
          "maxItems": 4,
          "minItems": 4,
          "type": "array"
        }
      },
      "type": "object"
    },
    "version": {
      "$ref": "/types/version",
      "description": "a version string matching x.x.x where x represents one or more digits",
      "title": "Version"
    }
  },
  "required": [
    "version",
    "game_data",
    "session",
    "highlights",
    "player_data",
    "rallies",
    "coach_advice",
    "stats"
  ],
  "title": "Insights",
  "type": "object"
}