Player12
An open source football management simulator
Loading...
Searching...
No Matches
match_insights.h
Go to the documentation of this file.
1// -----------------------------------------------------------------------------
2// Football Management Project
3// Copyright (c) 2025 - 2026 Flavio Milinanni. All Rights Reserved.
4//
5// This file is part of the Football Management Project.
6// See the LICENSE file in the project root.
7// -----------------------------------------------------------------------------
8
9#pragma once
10
11#include <array>
12#include <cstdint>
13#include <functional>
14#include <optional>
15#include <span>
16#include <string>
17#include <vector>
18
19#include "global/types.h"
22
23class MatchEngine;
24struct MatchReport;
25
28{
30 bool home = true;
31 std::uint16_t touches = 0;
33 float avg_x = 0.5f;
34 float avg_y = 0.5f;
35 std::uint16_t progressive_passes = 0;
36 std::uint16_t pressures = 0;
37 float expected_assists = 0.0f;
39 std::array<std::uint8_t, MatchTracking::CELLS> cells{};
40};
41
44{
45 std::uint8_t from = 0;
46 std::uint8_t to = 0;
47 std::uint16_t count = 0;
48};
49
52{
53 std::uint8_t minute = 0;
54 bool home = true;
57};
58
66{
67 std::vector<DetailPlayer> players;
68 std::vector<PassLink> links;
70 std::array<std::array<std::uint8_t, MatchTracking::BUCKETS>, 2> final_third{};
71 std::vector<DetailSubstitution> substitutions;
72
73 [[nodiscard]] bool empty() const { return players.empty(); }
75 [[nodiscard]] std::optional<std::size_t> indexOf(PlayerID player) const;
76
78 [[nodiscard]] std::vector<std::uint8_t> encode() const;
80 static std::optional<MatchDetail> decode(std::span<const std::uint8_t> data);
81};
82
85
88{
89 enum class Kind : std::uint8_t
90 {
91 Goal,
92 OwnGoal,
93 BigChance,
95 Yellow,
97 Red,
99 };
101 std::uint8_t minute = 0;
102 std::uint8_t added = 0;
104 bool home = true;
107 float xg = 0.0f;
109 int shot = -1;
110};
111
113{
114inline constexpr float BIG_CHANCE_XG = 0.3f;
116inline constexpr float CLEAR_XG_GAP = 0.6f;
118inline constexpr float FINISHING_GAP = 1.0f;
120inline constexpr int MIN_FLANK_TOUCHES = 24;
121inline constexpr float FLANK_SHARE = 0.45f;
122inline constexpr int MIN_SPELL_TOUCHES = 12;
124inline constexpr float LOW_SHOT_QUALITY = 0.075f;
125inline constexpr int MIN_SHOTS_FOR_QUALITY = 10;
126inline constexpr int MAX_SUMMARY_LINES = 5;
127} // namespace MatchInsights
128
131{
132 const MatchReport* report = nullptr;
133 std::span<const ShotRecord> shots;
134 const MatchDetail* detail = nullptr;
135 bool managed_home = true;
137 std::function<std::string(PlayerID)> name_of;
138};
139
141std::vector<KeyMoment> keyMoments(const InsightInput& input);
142
150std::vector<AnalysisLine> summariseMatch(const InsightInput& input);
151
153std::array<int, 3> finalThirdByFlank(const MatchDetail& detail, bool home);
Definition match_engine.h:517
MatchDetail captureDetail(const MatchEngine &engine)
Definition match_insights.cpp:262
std::array< int, 3 > finalThirdByFlank(const MatchDetail &detail, bool home)
Final-third touches of one side split by flank (attacking frame).
Definition match_insights.cpp:320
std::vector< KeyMoment > keyMoments(const InsightInput &input)
Definition match_insights.cpp:337
std::vector< AnalysisLine > summariseMatch(const InsightInput &input)
Definition match_insights.cpp:508
Definition match_insights.h:113
constexpr float CLEAR_XG_GAP
Definition match_insights.h:116
constexpr float FINISHING_GAP
Definition match_insights.h:118
constexpr int MIN_FLANK_TOUCHES
Definition match_insights.h:120
constexpr float BIG_CHANCE_XG
Definition match_insights.h:114
constexpr int MAX_SUMMARY_LINES
Definition match_insights.h:126
constexpr float LOW_SHOT_QUALITY
Definition match_insights.h:124
constexpr int MIN_SHOTS_FOR_QUALITY
Definition match_insights.h:125
constexpr float FLANK_SHARE
Definition match_insights.h:121
constexpr int MIN_SPELL_TOUCHES
Definition match_insights.h:122
Tracked numbers of one player in a match (attacking frame).
Definition match_insights.h:28
bool home
Definition match_insights.h:30
std::uint16_t touches
Definition match_insights.h:31
std::array< std::uint8_t, MatchTracking::CELLS > cells
Definition match_insights.h:39
std::uint16_t pressures
Definition match_insights.h:36
PlayerID player
Definition match_insights.h:29
float expected_assists
Definition match_insights.h:37
float avg_y
Definition match_insights.h:34
std::uint16_t progressive_passes
Definition match_insights.h:35
float avg_x
Definition match_insights.h:33
A substitution of the match.
Definition match_insights.h:52
PlayerID on
Definition match_insights.h:56
bool home
Definition match_insights.h:54
PlayerID off
Definition match_insights.h:55
std::uint8_t minute
Definition match_insights.h:53
What the summary and the key moments are built from.
Definition match_insights.h:131
const MatchDetail * detail
Definition match_insights.h:134
const MatchReport * report
Definition match_insights.h:132
std::function< std::string(PlayerID)> name_of
Definition match_insights.h:137
bool managed_home
Definition match_insights.h:135
std::span< const ShotRecord > shots
Definition match_insights.h:133
One entry of the key-moments list.
Definition match_insights.h:88
std::uint8_t added
Definition match_insights.h:102
bool home
Definition match_insights.h:104
Kind
Definition match_insights.h:90
int shot
Definition match_insights.h:109
PlayerID player
Definition match_insights.h:105
Kind kind
Definition match_insights.h:100
PlayerID other
Definition match_insights.h:106
std::uint8_t minute
Definition match_insights.h:101
float xg
Definition match_insights.h:107
Per-match aggregates behind the match report's analysis: touch maps, the pass network,...
Definition match_insights.h:66
std::vector< std::uint8_t > encode() const
Definition match_insights.cpp:135
std::vector< PassLink > links
Definition match_insights.h:68
bool empty() const
Definition match_insights.h:73
std::array< std::array< std::uint8_t, MatchTracking::BUCKETS >, 2 > final_third
Definition match_insights.h:70
static std::optional< MatchDetail > decode(std::span< const std::uint8_t > data)
Definition match_insights.cpp:190
std::vector< DetailSubstitution > substitutions
Definition match_insights.h:71
std::vector< DetailPlayer > players
Definition match_insights.h:67
std::optional< std::size_t > indexOf(PlayerID player) const
Definition match_insights.cpp:128
Structured summary of a played fixture, persisted per fixture.
Definition match_report.h:93
uint32_t PlayerID
Type alias for Player identifiers.
Definition types.h:21