football-docs 0.4.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +53 -53
- package/bin/serve.js +6 -1
- package/data/docs.db +0 -0
- package/dist/crawl.js +59 -1
- package/dist/impect-truth.d.ts +61 -0
- package/dist/impect-truth.js +250 -0
- package/dist/index.d.ts +11 -6
- package/dist/index.js +104 -304
- package/dist/ingest.js +5 -2
- package/dist/tools.d.ts +63 -0
- package/dist/tools.js +526 -0
- package/docs/_reference/skillcorner-crunch-help/getting-started-api-access-dynamic-events.md +134 -0
- package/docs/_reference/skillcorner-crunch-help/getting-started-api-access-our-tracking-data.md +160 -0
- package/docs/_reference/skillcorner-crunch-help/getting-started-best-practice-analysis-guidance.md +16 -0
- package/docs/_reference/skillcorner-crunch-help/getting-started-dynamic-events-check.md +33 -0
- package/docs/_reference/skillcorner-crunch-help/getting-started-explore-game-intelligence-data-1.md +37 -0
- package/docs/_reference/skillcorner-crunch-help/getting-started-explore-game-intelligence-data.md +29 -0
- package/docs/_reference/skillcorner-crunch-help/getting-started-first-requests.md +99 -0
- package/docs/_reference/skillcorner-crunch-help/getting-started-generate-visual-reports.md +90 -0
- package/docs/_reference/skillcorner-crunch-help/getting-started-make-your-first-queries.md +92 -0
- package/docs/_reference/skillcorner-crunch-help/getting-started-off-ball-run-sportscode-xml.md +32 -0
- package/docs/_reference/skillcorner-crunch-help/getting-started-on-ball-engagement-video-definitio.md +15 -0
- package/docs/_reference/skillcorner-crunch-help/getting-started-python-retrieve-dynamic-events-fil.md +102 -0
- package/docs/_reference/skillcorner-crunch-help/getting-started-python-retrieve-game-intelligence-.md +158 -0
- package/docs/_reference/skillcorner-crunch-help/getting-started-python-sync-your-database-with-ski.md +192 -0
- package/docs/_reference/skillcorner-crunch-help/getting-started-run-detection-and-classification.md +131 -0
- package/docs/_reference/skillcorner-crunch-help/getting-started-skill-corner-tracking-data.md +82 -0
- package/docs/_reference/skillcorner-crunch-help/getting-started-skillcorner-python-client.md +70 -0
- package/docs/_reference/skillcorner-crunch-help/getting-started-using-skillcorner-api.md +146 -0
- package/docs/_reference/skillcorner-crunch-help/getting-started.md +43 -0
- package/docs/_reference/skillcorner-crunch-help/glossaries-coordinates-distance-speeds-and-directi.md +149 -0
- package/docs/_reference/skillcorner-crunch-help/glossaries-dynamic-events-csv-specifications.md +15 -0
- package/docs/_reference/skillcorner-crunch-help/glossaries-forward-momentum.md +13 -0
- package/docs/_reference/skillcorner-crunch-help/glossaries-game-intelligence-v2-metrics.md +17 -0
- package/docs/_reference/skillcorner-crunch-help/glossaries-in-possession-package-content.md +19 -0
- package/docs/_reference/skillcorner-crunch-help/glossaries-line-breaking-passes.md +103 -0
- package/docs/_reference/skillcorner-crunch-help/glossaries-off-ball-run-dynamic-events.md +197 -0
- package/docs/_reference/skillcorner-crunch-help/glossaries-overcoming-pressure.md +105 -0
- package/docs/_reference/skillcorner-crunch-help/glossaries-passing-metrics-1.md +144 -0
- package/docs/_reference/skillcorner-crunch-help/glossaries-passing-moment-frame-selection.md +19 -0
- package/docs/_reference/skillcorner-crunch-help/glossaries-peak-sprint-velocity.md +26 -0
- package/docs/_reference/skillcorner-crunch-help/glossaries-phases-of-play-video-definitions.md +15 -0
- package/docs/_reference/skillcorner-crunch-help/glossaries-physical-data-glossary.md +127 -0
- package/docs/_reference/skillcorner-crunch-help/glossaries-running-off-ball-metrics-1.md +135 -0
- package/docs/_reference/skillcorner-crunch-help/glossaries.md +43 -0
- package/docs/_reference/skillcorner-crunch-help/index.md +33 -0
- package/docs/_reference/skillcorner-crunch-help/models-general-concepts-pass-completion-probabilit.md +15 -0
- package/docs/_reference/skillcorner-crunch-help/models-general-concepts-passing-option.md +30 -0
- package/docs/_reference/skillcorner-crunch-help/models-general-concepts-physical-load-prediction-m.md +63 -0
- package/docs/_reference/skillcorner-crunch-help/models-general-concepts-pressure-detection.md +46 -0
- package/docs/_reference/skillcorner-crunch-help/models-general-concepts-pressure-intensity.md +80 -0
- package/docs/_reference/skillcorner-crunch-help/models-general-concepts-threat.md +40 -0
- package/docs/_reference/skillcorner-crunch-help/models-general-concepts.md +37 -0
- package/docs/_reference/skillcorner-crunch-help/product-updates-1-changelog-2025.md +57 -0
- package/docs/_reference/skillcorner-crunch-help/product-updates-1-game-intelligence-v2-migration.md +64 -0
- package/docs/_reference/skillcorner-crunch-help/product-updates-1-product-updates.md +200 -0
- package/docs/_reference/skillcorner-crunch-help/product-updates-1.md +25 -0
- package/docs/_reference/skillcorner-crunch-help/tool-box-api-data-version.md +255 -0
- package/docs/_reference/skillcorner-crunch-help/tool-box-data-availability.md +55 -0
- package/docs/_reference/skillcorner-crunch-help/tool-box-python-event-tracking-synchronization-1.md +442 -0
- package/docs/_reference/skillcorner-crunch-help/tool-box-python-event-tracking-synchronization.md +276 -0
- package/docs/_reference/skillcorner-crunch-help/tool-box-python-off-ball-runs-radar-plots.md +69 -0
- package/docs/_reference/skillcorner-crunch-help/tool-box-rule-based-event-synchronisation.md +44 -0
- package/docs/_reference/skillcorner-crunch-help/tool-box.md +35 -0
- package/docs/_reference/skillcorner-crunch-help/working-with-the-data-averaging-per-match-per-even.md +179 -0
- package/docs/_reference/skillcorner-crunch-help/working-with-the-data-benchmarking-normalisation.md +27 -0
- package/docs/_reference/skillcorner-crunch-help/working-with-the-data-data-quality-standards.md +45 -0
- package/docs/_reference/skillcorner-crunch-help/working-with-the-data-physical-data-glossary-1-1.md +54 -0
- package/docs/_reference/skillcorner-crunch-help/working-with-the-data-physical-data-glossary-1.md +25 -0
- package/docs/_reference/skillcorner-crunch-help/working-with-the-data-pitch-modelisation.md +27 -0
- package/docs/_reference/skillcorner-crunch-help/working-with-the-data-playing-time-info.md +133 -0
- package/docs/_reference/skillcorner-crunch-help/working-with-the-data.md +43 -0
- package/docs/floodlight/compendium-0-compendium.md +21 -0
- package/docs/floodlight/compendium-1-data.md +54 -0
- package/docs/floodlight/compendium-2-design.md +49 -0
- package/docs/floodlight/compendium-3-time.md +57 -0
- package/docs/floodlight/compendium-4-space.md +137 -0
- package/docs/floodlight/compendium-5-identifier.md +63 -0
- package/docs/floodlight/core-code.md +85 -0
- package/docs/floodlight/core-core.md +39 -0
- package/docs/floodlight/core-definitions.md +128 -0
- package/docs/floodlight/core-events.md +177 -0
- package/docs/floodlight/core-pitch.md +87 -0
- package/docs/floodlight/core-property.md +107 -0
- package/docs/floodlight/core-teamsheet.md +86 -0
- package/docs/floodlight/core-xy.md +192 -0
- package/docs/floodlight/guides-contrib-manual.md +462 -0
- package/docs/floodlight/guides-getting-started.md +194 -0
- package/docs/floodlight/guides-tutorial-analysis.md +245 -0
- package/docs/floodlight/guides-tutorial-matchsheets.md +439 -0
- package/docs/floodlight/index.md +17 -0
- package/docs/floodlight/io-datasets.md +365 -0
- package/docs/floodlight/io-dfl.md +107 -0
- package/docs/floodlight/io-io.md +131 -0
- package/docs/floodlight/io-kinexon.md +119 -0
- package/docs/floodlight/io-opta.md +49 -0
- package/docs/floodlight/io-secondspectrum.md +121 -0
- package/docs/floodlight/io-skillcorner.md +40 -0
- package/docs/floodlight/io-sportradar.md +35 -0
- package/docs/floodlight/io-statsbomb.md +61 -0
- package/docs/floodlight/io-statsperform.md +239 -0
- package/docs/floodlight/io-tracab.md +78 -0
- package/docs/floodlight/io-utils.md +59 -0
- package/docs/floodlight/metrics-entropy.md +36 -0
- package/docs/floodlight/metrics-metrics.md +15 -0
- package/docs/floodlight/metrics-trajectory-clustering.md +51 -0
- package/docs/floodlight/metrics-zone-aggregation.md +116 -0
- package/docs/floodlight/models-geometry.md +411 -0
- package/docs/floodlight/models-kinematics.md +251 -0
- package/docs/floodlight/models-kinetics.md +137 -0
- package/docs/floodlight/models-models.md +89 -0
- package/docs/floodlight/models-space.md +202 -0
- package/docs/floodlight/transforms-filter.md +412 -0
- package/docs/floodlight/transforms-interpolation.md +230 -0
- package/docs/floodlight/transforms-permutation.md +36 -0
- package/docs/floodlight/transforms-spatial.md +54 -0
- package/docs/floodlight/transforms-temporal.md +42 -0
- package/docs/floodlight/transforms-transforms.md +57 -0
- package/docs/floodlight/utils-types.md +13 -0
- package/docs/floodlight/utils-utils.md +17 -0
- package/docs/floodlight/vis-pitches.md +111 -0
- package/docs/floodlight/vis-positions.md +129 -0
- package/docs/floodlight/vis-vis.md +19 -0
- package/docs/fmdb-pro/api-access.md +120 -0
- package/docs/fmdb-pro/api-endpoints.md +123 -0
- package/docs/fmdb-pro/data-model.md +124 -0
- package/docs/fmdb-pro/identity-surfaces.md +108 -0
- package/docs/fotmob/identity-surfaces.md +16 -44
- package/docs/free-sources/contextual-story-joins.md +110 -0
- package/docs/free-sources/overview.md +60 -13
- package/docs/free-sources/understat.md +15 -6
- package/docs/free-sources/xg-timelines.md +123 -0
- package/docs/impect/concepts.md +183 -0
- package/docs/impect/coordinate-system.md +136 -0
- package/docs/impect/data-model.md +276 -0
- package/docs/impect/event-types.md +226 -0
- package/docs/impect/identity-surfaces.md +123 -51
- package/docs/impect/kpi-definitions.md +154 -0
- package/docs/impect/overview.md +152 -0
- package/docs/kloppy/event-derived-metrics.md +337 -0
- package/docs/kloppy/tracking-rendering.md +420 -0
- package/docs/mplsoccer/visualizations.md +363 -6
- package/docs/opta/charting-game-state.md +216 -0
- package/docs/opta/charting-lineups.md +90 -0
- package/docs/opta/charting-passmaps.md +130 -0
- package/docs/opta/charting-set-pieces.md +106 -0
- package/docs/opta/charting-shot-placement.md +233 -0
- package/docs/opta/event-types.md +44 -0
- package/docs/opta/identity-surfaces.md +31 -59
- package/docs/opta/qualifiers.md +16 -7
- package/docs/skillcorner/api-access.md +68 -0
- package/docs/skillcorner/api-endpoints.md +79 -0
- package/docs/skillcorner/concepts.md +58 -0
- package/docs/skillcorner/coordinate-system.md +34 -0
- package/docs/skillcorner/data-model.md +79 -0
- package/docs/skillcorner/identity-surfaces.md +26 -43
- package/docs/skillcorner/physical-data.md +106 -0
- package/docs/socceraction/spadl.md +21 -0
- package/docs/soccerdata/data-sources.md +37 -0
- package/docs/soccerdonna/identity-surfaces.md +16 -45
- package/docs/sportmonks/charting-season-stories.md +125 -0
- package/docs/sportmonks/data-model.md +35 -12
- package/docs/sportmonks/event-types.md +1 -1
- package/docs/sportmonks/identity-surfaces.md +33 -56
- package/docs/sportradar/api-access.md +75 -0
- package/docs/sportradar/api-endpoints.md +92 -0
- package/docs/sportradar/charting-and-stories.md +57 -0
- package/docs/sportradar/data-model.md +84 -0
- package/docs/sportradar/integration-notes.md +58 -0
- package/docs/statsbomb/charting-lineups.md +79 -0
- package/docs/statsbomb/identity-surfaces.md +33 -61
- package/docs/statsbomb/player-mapping.md +9 -10
- package/docs/thesportsdb/api-access.md +68 -0
- package/docs/thesportsdb/api-endpoints.md +55 -0
- package/docs/thesportsdb/identity-surfaces.md +48 -0
- package/docs/thesportsdb/livescore.md +70 -0
- package/docs/transfermarkt/identity-surfaces.md +23 -53
- package/docs/transferroom/api-access.md +91 -0
- package/docs/transferroom/api-endpoints.md +257 -0
- package/docs/transferroom/charting-availability.md +74 -0
- package/docs/transferroom/data-model.md +143 -0
- package/docs/transferroom/identity-surfaces.md +132 -0
- package/docs/wyscout/api-access.md +86 -127
- package/docs/wyscout/api-endpoints.md +136 -0
- package/docs/wyscout/charting-analysis-metrics.md +124 -0
- package/docs/wyscout/coordinate-system.md +35 -107
- package/docs/wyscout/data-model.md +185 -231
- package/docs/wyscout/event-types.md +59 -180
- package/docs/wyscout/glossary-events.md +1956 -0
- package/docs/wyscout/glossary-metrics-concepts.md +812 -0
- package/docs/wyscout/identity-surfaces.md +21 -42
- package/package.json +6 -14
- package/providers.json +167 -62
package/dist/tools.js
ADDED
|
@@ -0,0 +1,526 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
import { dirname, resolve } from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
export const TOOL_NAMES = [
|
|
5
|
+
"search_docs",
|
|
6
|
+
"resolve_provider_id",
|
|
7
|
+
"get_provider_docs",
|
|
8
|
+
"list_providers",
|
|
9
|
+
"compare_providers",
|
|
10
|
+
"request_update",
|
|
11
|
+
"resolve_entity",
|
|
12
|
+
];
|
|
13
|
+
const QUERY_STOP_WORDS = new Set(["and", "or", "not", "near"]);
|
|
14
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
15
|
+
const PROVIDERS_PATH = resolve(__dirname, "..", "providers.json");
|
|
16
|
+
const PROVIDER_REGISTRY = JSON.parse(readFileSync(PROVIDERS_PATH, "utf-8"));
|
|
17
|
+
function slugProvider(provider) {
|
|
18
|
+
return provider
|
|
19
|
+
.trim()
|
|
20
|
+
.toLowerCase()
|
|
21
|
+
.replace(/&/g, " and ")
|
|
22
|
+
.replace(/[^a-z0-9]+/g, "-")
|
|
23
|
+
.replace(/^-|-$/g, "");
|
|
24
|
+
}
|
|
25
|
+
function buildProviderAliases() {
|
|
26
|
+
const aliases = {};
|
|
27
|
+
for (const [provider, metadata] of Object.entries(PROVIDER_REGISTRY.providers)) {
|
|
28
|
+
aliases[slugProvider(provider)] = provider;
|
|
29
|
+
aliases[slugProvider(metadata.display_name)] = provider;
|
|
30
|
+
for (const alias of metadata.aliases) {
|
|
31
|
+
aliases[slugProvider(alias)] = provider;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return aliases;
|
|
35
|
+
}
|
|
36
|
+
const PROVIDER_ALIASES = buildProviderAliases();
|
|
37
|
+
const DISPLAY_PROVIDER_ALIASES = Object.entries(PROVIDER_ALIASES).reduce((aliasesByProvider, [alias, provider]) => {
|
|
38
|
+
if (alias === provider)
|
|
39
|
+
return aliasesByProvider;
|
|
40
|
+
const aliases = aliasesByProvider[provider] ?? [];
|
|
41
|
+
aliases.push(alias);
|
|
42
|
+
aliasesByProvider[provider] = aliases;
|
|
43
|
+
return aliasesByProvider;
|
|
44
|
+
}, {});
|
|
45
|
+
function textResult(text, isError = false) {
|
|
46
|
+
return {
|
|
47
|
+
isError: isError || undefined,
|
|
48
|
+
content: [{ type: "text", text }],
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
function extractFtsTokens(query) {
|
|
52
|
+
const rawTokens = query.match(/[\p{L}\p{N}_]+/gu) ?? [];
|
|
53
|
+
const tokens = rawTokens
|
|
54
|
+
.map((token) => token.trim().toLowerCase())
|
|
55
|
+
.filter((token) => token.length > 0 && !QUERY_STOP_WORDS.has(token));
|
|
56
|
+
return [...new Set(tokens)];
|
|
57
|
+
}
|
|
58
|
+
function quoteFtsToken(token) {
|
|
59
|
+
return `"${token.replace(/"/g, '""')}"`;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Build a safe FTS5 MATCH query from user text.
|
|
63
|
+
*
|
|
64
|
+
* User questions are usually natural language, not exact doc phrases. Joining
|
|
65
|
+
* searchable tokens with AND keeps results precise while still allowing queries
|
|
66
|
+
* like "Opta qualifier 76" to match docs that contain those tokens separately.
|
|
67
|
+
*/
|
|
68
|
+
export function sanitiseFtsQuery(query) {
|
|
69
|
+
const tokens = extractFtsTokens(query);
|
|
70
|
+
if (tokens.length === 0)
|
|
71
|
+
return '""';
|
|
72
|
+
return tokens.map(quoteFtsToken).join(" AND ");
|
|
73
|
+
}
|
|
74
|
+
function relaxedFtsQuery(query) {
|
|
75
|
+
const tokens = extractFtsTokens(query);
|
|
76
|
+
if (tokens.length === 0)
|
|
77
|
+
return '""';
|
|
78
|
+
return tokens.map(quoteFtsToken).join(" OR ");
|
|
79
|
+
}
|
|
80
|
+
function normaliseProvider(provider) {
|
|
81
|
+
const slug = slugProvider(provider);
|
|
82
|
+
return PROVIDER_ALIASES[slug] ?? slug;
|
|
83
|
+
}
|
|
84
|
+
function providerFilterLabel(original, normalised) {
|
|
85
|
+
if (!original || !normalised)
|
|
86
|
+
return "";
|
|
87
|
+
const trimmed = original.trim();
|
|
88
|
+
return trimmed === normalised ? normalised : `${trimmed} (${normalised})`;
|
|
89
|
+
}
|
|
90
|
+
function indexedProviders(db) {
|
|
91
|
+
const rows = db.prepare("SELECT DISTINCT provider FROM docs ORDER BY provider").all();
|
|
92
|
+
return new Set(rows.map((row) => row.provider));
|
|
93
|
+
}
|
|
94
|
+
function editDistance(a, b) {
|
|
95
|
+
const previous = Array.from({ length: b.length + 1 }, (_, index) => index);
|
|
96
|
+
const current = Array.from({ length: b.length + 1 }, () => 0);
|
|
97
|
+
for (let i = 1; i <= a.length; i += 1) {
|
|
98
|
+
current[0] = i;
|
|
99
|
+
for (let j = 1; j <= b.length; j += 1) {
|
|
100
|
+
const cost = a[i - 1] === b[j - 1] ? 0 : 1;
|
|
101
|
+
current[j] = Math.min(current[j - 1] + 1, previous[j] + 1, previous[j - 1] + cost);
|
|
102
|
+
}
|
|
103
|
+
previous.splice(0, previous.length, ...current);
|
|
104
|
+
}
|
|
105
|
+
return previous[b.length];
|
|
106
|
+
}
|
|
107
|
+
function providerSuggestions(provider, providerSet) {
|
|
108
|
+
const candidates = new Map();
|
|
109
|
+
for (const indexedProvider of providerSet) {
|
|
110
|
+
candidates.set(indexedProvider, indexedProvider);
|
|
111
|
+
}
|
|
112
|
+
for (const [alias, indexedProvider] of Object.entries(PROVIDER_ALIASES)) {
|
|
113
|
+
if (providerSet.has(indexedProvider)) {
|
|
114
|
+
candidates.set(alias, indexedProvider);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
const threshold = Math.max(2, Math.ceil(provider.length * 0.3));
|
|
118
|
+
return [...candidates.entries()]
|
|
119
|
+
.map(([candidate, indexedProvider]) => ({
|
|
120
|
+
candidate,
|
|
121
|
+
indexedProvider,
|
|
122
|
+
distance: editDistance(provider, candidate),
|
|
123
|
+
}))
|
|
124
|
+
.filter((suggestion) => suggestion.distance <= threshold)
|
|
125
|
+
.sort((a, b) => a.distance - b.distance || a.candidate.localeCompare(b.candidate))
|
|
126
|
+
.map((suggestion) => suggestion.indexedProvider)
|
|
127
|
+
.filter((providerName, index, suggestions) => suggestions.indexOf(providerName) === index)
|
|
128
|
+
.slice(0, 3);
|
|
129
|
+
}
|
|
130
|
+
function unknownProviderMessage(original, provider, providerSet) {
|
|
131
|
+
const suggestions = providerSuggestions(provider, providerSet);
|
|
132
|
+
const suggestionText = suggestions.length ? ` Did you mean: ${suggestions.join(", ")}?` : "";
|
|
133
|
+
return `Provider "${providerFilterLabel(original, provider)}" is not indexed.${suggestionText} Call list_providers for available provider keys, or use request_update to suggest adding it.`;
|
|
134
|
+
}
|
|
135
|
+
function requestProviderKey(provider) {
|
|
136
|
+
return slugProvider(provider).replace(/-/g, "");
|
|
137
|
+
}
|
|
138
|
+
function requestIssueTemplate(type) {
|
|
139
|
+
return {
|
|
140
|
+
new_provider: "new-provider.md",
|
|
141
|
+
recrawl: "flag-outdated.md",
|
|
142
|
+
flag_outdated: "flag-outdated.md",
|
|
143
|
+
suggest_source: "suggest-source.md",
|
|
144
|
+
}[type];
|
|
145
|
+
}
|
|
146
|
+
function requestIssueUrl(args) {
|
|
147
|
+
const titlePrefix = {
|
|
148
|
+
new_provider: "New provider",
|
|
149
|
+
recrawl: "Recrawl",
|
|
150
|
+
flag_outdated: "Outdated",
|
|
151
|
+
suggest_source: "Better source",
|
|
152
|
+
}[args.type];
|
|
153
|
+
const params = new URLSearchParams({
|
|
154
|
+
template: requestIssueTemplate(args.type),
|
|
155
|
+
title: `${titlePrefix}: ${args.provider}`,
|
|
156
|
+
});
|
|
157
|
+
return `https://github.com/withqwerty/football-docs/issues/new?${params.toString()}`;
|
|
158
|
+
}
|
|
159
|
+
function normaliseLimit(value, defaultValue, maxValue) {
|
|
160
|
+
if (value === undefined || !Number.isFinite(value))
|
|
161
|
+
return defaultValue;
|
|
162
|
+
return Math.min(Math.max(Math.trunc(value), 1), maxValue);
|
|
163
|
+
}
|
|
164
|
+
function searchRows(db, matchQuery, provider, limit) {
|
|
165
|
+
let sql = `
|
|
166
|
+
SELECT d.provider, d.category, d.title, d.content,
|
|
167
|
+
d.source_type, d.source_url, d.upstream_version,
|
|
168
|
+
d.crawled_at,
|
|
169
|
+
rank * -1 as relevance
|
|
170
|
+
FROM docs_fts
|
|
171
|
+
JOIN docs d ON d.id = docs_fts.rowid
|
|
172
|
+
WHERE docs_fts MATCH ?
|
|
173
|
+
`;
|
|
174
|
+
const params = [matchQuery];
|
|
175
|
+
if (provider) {
|
|
176
|
+
sql += " AND d.provider = ?";
|
|
177
|
+
params.push(normaliseProvider(provider));
|
|
178
|
+
}
|
|
179
|
+
sql += " ORDER BY rank LIMIT ?";
|
|
180
|
+
params.push(limit);
|
|
181
|
+
return db.prepare(sql).all(...params);
|
|
182
|
+
}
|
|
183
|
+
function compareRows(db, matchQuery, providers) {
|
|
184
|
+
let sql = `
|
|
185
|
+
SELECT d.provider, d.category, d.title, d.content,
|
|
186
|
+
rank * -1 as relevance
|
|
187
|
+
FROM docs_fts
|
|
188
|
+
JOIN docs d ON d.id = docs_fts.rowid
|
|
189
|
+
WHERE docs_fts MATCH ?
|
|
190
|
+
`;
|
|
191
|
+
const params = [matchQuery];
|
|
192
|
+
if (providers && providers.length > 0) {
|
|
193
|
+
const placeholders = providers.map(() => "?").join(", ");
|
|
194
|
+
sql += ` AND d.provider IN (${placeholders})`;
|
|
195
|
+
params.push(...providers.map(normaliseProvider));
|
|
196
|
+
}
|
|
197
|
+
sql += " ORDER BY d.provider, rank LIMIT 30";
|
|
198
|
+
return db.prepare(sql).all(...params);
|
|
199
|
+
}
|
|
200
|
+
function compareRowsForProvider(db, matchQuery, provider, limit) {
|
|
201
|
+
return db
|
|
202
|
+
.prepare(`SELECT d.provider, d.category, d.title, d.content,
|
|
203
|
+
rank * -1 as relevance
|
|
204
|
+
FROM docs_fts
|
|
205
|
+
JOIN docs d ON d.id = docs_fts.rowid
|
|
206
|
+
WHERE docs_fts MATCH ? AND d.provider = ?
|
|
207
|
+
ORDER BY rank
|
|
208
|
+
LIMIT ?`)
|
|
209
|
+
.all(matchQuery, normaliseProvider(provider), limit);
|
|
210
|
+
}
|
|
211
|
+
function sourceLabel(row) {
|
|
212
|
+
const crawledAt = row.crawled_at ? ` | crawled ${row.crawled_at}` : "";
|
|
213
|
+
if (row.source_type === "curated") {
|
|
214
|
+
return `**Source:** curated by football-docs contributors${crawledAt}`;
|
|
215
|
+
}
|
|
216
|
+
return `**Source:** ${row.source_type}${row.source_url ? ` (${row.source_url})` : ""}${row.upstream_version ? ` | v${row.upstream_version}` : ""}${crawledAt}`;
|
|
217
|
+
}
|
|
218
|
+
function providerMetadata(provider) {
|
|
219
|
+
return PROVIDER_REGISTRY.providers[provider];
|
|
220
|
+
}
|
|
221
|
+
function providerCoverage(db, provider) {
|
|
222
|
+
const rows = db
|
|
223
|
+
.prepare(`SELECT category, COUNT(*) as chunks
|
|
224
|
+
FROM docs
|
|
225
|
+
WHERE provider = ?
|
|
226
|
+
GROUP BY category
|
|
227
|
+
ORDER BY category`)
|
|
228
|
+
.all(provider);
|
|
229
|
+
return {
|
|
230
|
+
indexed: rows.length > 0,
|
|
231
|
+
total: rows.reduce((sum, row) => sum + row.chunks, 0),
|
|
232
|
+
categories: rows.map((row) => `${row.category} (${row.chunks})`),
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
function formatProviderResolution(db, provider, originalQuery) {
|
|
236
|
+
const metadata = providerMetadata(provider);
|
|
237
|
+
const coverage = providerCoverage(db, provider);
|
|
238
|
+
const aliasText = metadata?.aliases.length ? metadata.aliases.join(", ") : "none";
|
|
239
|
+
const sourceText = metadata?.sources
|
|
240
|
+
.map((source) => `${source.type}${source.url ? `: ${source.url}` : ""}`)
|
|
241
|
+
.join("; ") || "none registered";
|
|
242
|
+
return [
|
|
243
|
+
`Resolved "${originalQuery}" to provider ID: **${provider}**`,
|
|
244
|
+
`**Display name:** ${metadata?.display_name ?? provider}`,
|
|
245
|
+
`**Indexed:** ${coverage.indexed ? `yes (${coverage.total} chunks)` : "no"}`,
|
|
246
|
+
`**Categories:** ${coverage.categories.length ? coverage.categories.join(", ") : "none indexed"}`,
|
|
247
|
+
`**Aliases:** ${aliasText}`,
|
|
248
|
+
`**Access level:** ${metadata?.access_level ?? "unknown"}`,
|
|
249
|
+
`**Licence/status:** ${metadata?.licence_status ?? "unknown"}`,
|
|
250
|
+
`**Public-safety notes:** ${metadata?.public_safety_notes ?? "none registered"}`,
|
|
251
|
+
`**Version:** ${metadata?.version ?? "unversioned"}`,
|
|
252
|
+
`**Last crawled:** ${metadata?.last_crawled ?? "not crawled"}`,
|
|
253
|
+
`**Registered sources:** ${sourceText}`,
|
|
254
|
+
].join("\n");
|
|
255
|
+
}
|
|
256
|
+
function providerDocsRows(db, provider, matchQuery, category, limit) {
|
|
257
|
+
const params = [];
|
|
258
|
+
let sql;
|
|
259
|
+
if (matchQuery) {
|
|
260
|
+
sql = `
|
|
261
|
+
SELECT d.provider, d.category, d.title, d.content,
|
|
262
|
+
d.source_type, d.source_url, d.upstream_version,
|
|
263
|
+
d.crawled_at,
|
|
264
|
+
rank * -1 as relevance
|
|
265
|
+
FROM docs_fts
|
|
266
|
+
JOIN docs d ON d.id = docs_fts.rowid
|
|
267
|
+
WHERE docs_fts MATCH ? AND d.provider = ?
|
|
268
|
+
`;
|
|
269
|
+
params.push(matchQuery, provider);
|
|
270
|
+
}
|
|
271
|
+
else {
|
|
272
|
+
sql = `
|
|
273
|
+
SELECT d.provider, d.category, d.title, d.content,
|
|
274
|
+
d.source_type, d.source_url, d.upstream_version,
|
|
275
|
+
d.crawled_at,
|
|
276
|
+
0 as relevance
|
|
277
|
+
FROM docs d
|
|
278
|
+
WHERE d.provider = ?
|
|
279
|
+
`;
|
|
280
|
+
params.push(provider);
|
|
281
|
+
}
|
|
282
|
+
if (category) {
|
|
283
|
+
sql += " AND d.category = ?";
|
|
284
|
+
params.push(category);
|
|
285
|
+
}
|
|
286
|
+
sql += matchQuery ? " ORDER BY rank LIMIT ?" : " ORDER BY d.category, d.id LIMIT ?";
|
|
287
|
+
params.push(limit);
|
|
288
|
+
return db.prepare(sql).all(...params);
|
|
289
|
+
}
|
|
290
|
+
export function resolveProviderId(db, args) {
|
|
291
|
+
const provider = normaliseProvider(args.query);
|
|
292
|
+
const registryProviders = new Set(Object.keys(PROVIDER_REGISTRY.providers));
|
|
293
|
+
const indexedProviderSet = indexedProviders(db);
|
|
294
|
+
if (registryProviders.has(provider)) {
|
|
295
|
+
return textResult(formatProviderResolution(db, provider, args.query));
|
|
296
|
+
}
|
|
297
|
+
const suggestions = providerSuggestions(provider, new Set([...registryProviders, ...indexedProviderSet]));
|
|
298
|
+
const suggestionText = suggestions.length ? ` Did you mean: ${suggestions.join(", ")}?` : "";
|
|
299
|
+
return textResult(`Provider "${args.query}" is not registered.${suggestionText} Use request_update to suggest adding it, or open a GitHub issue with the new-provider template.`, true);
|
|
300
|
+
}
|
|
301
|
+
export function getProviderDocs(db, args) {
|
|
302
|
+
const provider = normaliseProvider(args.provider);
|
|
303
|
+
const providerSet = indexedProviders(db);
|
|
304
|
+
if (!providerSet.has(provider)) {
|
|
305
|
+
const registryProviders = new Set(Object.keys(PROVIDER_REGISTRY.providers));
|
|
306
|
+
if (registryProviders.has(provider)) {
|
|
307
|
+
return textResult(`Provider "${providerFilterLabel(args.provider, provider)}" is registered but has no indexed docs yet. Use request_update to ask maintainers to crawl or curate it.`, true);
|
|
308
|
+
}
|
|
309
|
+
return textResult(unknownProviderMessage(args.provider, provider, providerSet), true);
|
|
310
|
+
}
|
|
311
|
+
const limit = normaliseLimit(args.max_results, 10, 50);
|
|
312
|
+
const category = args.category ? slugProvider(args.category) : undefined;
|
|
313
|
+
const strictQuery = args.topic ? sanitiseFtsQuery(args.topic) : undefined;
|
|
314
|
+
const fallbackQuery = args.topic ? relaxedFtsQuery(args.topic) : undefined;
|
|
315
|
+
let rows = providerDocsRows(db, provider, strictQuery, category, limit);
|
|
316
|
+
if (rows.length === 0 && fallbackQuery && fallbackQuery !== strictQuery) {
|
|
317
|
+
rows = providerDocsRows(db, provider, fallbackQuery, category, limit);
|
|
318
|
+
}
|
|
319
|
+
if (rows.length === 0) {
|
|
320
|
+
return textResult(`No provider docs found for "${providerFilterLabel(args.provider, provider)}"${category ? ` in category "${category}"` : ""}${args.topic ? ` matching "${args.topic}"` : ""}. Call resolve_provider_id or list_providers to inspect available coverage.`);
|
|
321
|
+
}
|
|
322
|
+
const metadata = providerMetadata(provider);
|
|
323
|
+
const docs = rows
|
|
324
|
+
.map((row, index) => {
|
|
325
|
+
return `## [${index + 1}] ${row.title}\n**Provider:** ${row.provider} | **Category:** ${row.category} | ${sourceLabel(row)}\n\n${row.content}`;
|
|
326
|
+
})
|
|
327
|
+
.join("\n\n---\n\n");
|
|
328
|
+
return textResult(`Provider docs for **${provider}** (${metadata?.display_name ?? provider})${args.topic ? ` matching "${args.topic}"` : ""}${category ? ` in category "${category}"` : ""}:\n\n${docs}`);
|
|
329
|
+
}
|
|
330
|
+
export function searchDocs(db, args) {
|
|
331
|
+
const limit = normaliseLimit(args.max_results, 10, 50);
|
|
332
|
+
const strictQuery = sanitiseFtsQuery(args.query);
|
|
333
|
+
const fallbackQuery = relaxedFtsQuery(args.query);
|
|
334
|
+
const provider = args.provider ? normaliseProvider(args.provider) : undefined;
|
|
335
|
+
if (args.provider && provider) {
|
|
336
|
+
const providerSet = indexedProviders(db);
|
|
337
|
+
if (!providerSet.has(provider)) {
|
|
338
|
+
return textResult(unknownProviderMessage(args.provider, provider, providerSet), true);
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
let rows = searchRows(db, strictQuery, provider, limit);
|
|
342
|
+
if (rows.length === 0 && fallbackQuery !== strictQuery) {
|
|
343
|
+
rows = searchRows(db, fallbackQuery, provider, limit);
|
|
344
|
+
}
|
|
345
|
+
if (rows.length === 0) {
|
|
346
|
+
const providerLabel = providerFilterLabel(args.provider, provider);
|
|
347
|
+
return textResult(`No results found for "${args.query}"${providerLabel ? ` in ${providerLabel}` : ""}. Try broader football-data terms, remove the provider filter, or call list_providers to inspect coverage.`);
|
|
348
|
+
}
|
|
349
|
+
const results = rows
|
|
350
|
+
.map((row, index) => {
|
|
351
|
+
return `## [${index + 1}] ${row.title}\n**Provider:** ${row.provider} | **Category:** ${row.category} | ${sourceLabel(row)}\n\n${row.content}`;
|
|
352
|
+
})
|
|
353
|
+
.join("\n\n---\n\n");
|
|
354
|
+
const providerLabel = providerFilterLabel(args.provider, provider);
|
|
355
|
+
return textResult(`Found ${rows.length} result(s) for "${args.query}"${providerLabel ? ` in ${providerLabel}` : ""}:\n\n${results}`);
|
|
356
|
+
}
|
|
357
|
+
export function listProviders(db) {
|
|
358
|
+
const rows = db
|
|
359
|
+
.prepare(`SELECT provider, category, COUNT(*) as chunks
|
|
360
|
+
FROM docs
|
|
361
|
+
GROUP BY provider, category
|
|
362
|
+
ORDER BY provider, category`)
|
|
363
|
+
.all();
|
|
364
|
+
const byProvider = new Map();
|
|
365
|
+
for (const row of rows) {
|
|
366
|
+
const entry = byProvider.get(row.provider) ?? { categories: [], total: 0 };
|
|
367
|
+
entry.categories.push(`${row.category} (${row.chunks})`);
|
|
368
|
+
entry.total += row.chunks;
|
|
369
|
+
byProvider.set(row.provider, entry);
|
|
370
|
+
}
|
|
371
|
+
const lines = [...byProvider.entries()]
|
|
372
|
+
.map(([provider, info]) => {
|
|
373
|
+
const aliases = DISPLAY_PROVIDER_ALIASES[provider];
|
|
374
|
+
const aliasText = aliases?.length ? ` | aliases: ${aliases.join(", ")}` : "";
|
|
375
|
+
return `**${provider}** (${info.total} chunks): ${info.categories.join(", ")}${aliasText}`;
|
|
376
|
+
})
|
|
377
|
+
.join("\n");
|
|
378
|
+
return textResult(`Indexed providers:\n\n${lines}`);
|
|
379
|
+
}
|
|
380
|
+
export function compareProviders(db, args) {
|
|
381
|
+
const strictQuery = sanitiseFtsQuery(args.topic);
|
|
382
|
+
const fallbackQuery = relaxedFtsQuery(args.topic);
|
|
383
|
+
let rows;
|
|
384
|
+
let requestedProviders = [];
|
|
385
|
+
const providerSet = indexedProviders(db);
|
|
386
|
+
if (args.providers?.length) {
|
|
387
|
+
requestedProviders = [...new Set(args.providers.map(normaliseProvider))];
|
|
388
|
+
rows = requestedProviders.flatMap((provider) => {
|
|
389
|
+
if (!providerSet.has(provider))
|
|
390
|
+
return [];
|
|
391
|
+
const strictRows = compareRowsForProvider(db, strictQuery, provider, 3);
|
|
392
|
+
if (strictRows.length > 0 || fallbackQuery === strictQuery)
|
|
393
|
+
return strictRows;
|
|
394
|
+
return compareRowsForProvider(db, fallbackQuery, provider, 3);
|
|
395
|
+
});
|
|
396
|
+
}
|
|
397
|
+
else {
|
|
398
|
+
rows = compareRows(db, strictQuery, args.providers);
|
|
399
|
+
if (rows.length === 0 && fallbackQuery !== strictQuery) {
|
|
400
|
+
rows = compareRows(db, fallbackQuery, args.providers);
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
if (rows.length === 0) {
|
|
404
|
+
if (requestedProviders.length > 0) {
|
|
405
|
+
const missingProviders = requestedProviders.filter((provider) => !providerSet.has(provider));
|
|
406
|
+
const providerNote = missingProviders.length
|
|
407
|
+
? ` Requested provider(s) not indexed: ${missingProviders.join(", ")}.${missingProviders
|
|
408
|
+
.map((provider) => {
|
|
409
|
+
const suggestions = providerSuggestions(provider, providerSet);
|
|
410
|
+
return suggestions.length ? ` ${provider}: did you mean ${suggestions.join(", ")}?` : "";
|
|
411
|
+
})
|
|
412
|
+
.join("")}`
|
|
413
|
+
: "";
|
|
414
|
+
return textResult(`No matching docs found for "${args.topic}" across requested provider(s): ${requestedProviders.join(", ")}.${providerNote} Call list_providers to inspect coverage, or use request_update to suggest missing provider docs.`);
|
|
415
|
+
}
|
|
416
|
+
return textResult(`No documentation found for "${args.topic}". Try different terms.`);
|
|
417
|
+
}
|
|
418
|
+
const grouped = new Map();
|
|
419
|
+
for (const row of rows) {
|
|
420
|
+
const entries = grouped.get(row.provider) ?? [];
|
|
421
|
+
entries.push(`### ${row.title}\n${row.content}`);
|
|
422
|
+
grouped.set(row.provider, entries);
|
|
423
|
+
}
|
|
424
|
+
const sections = [...grouped.entries()]
|
|
425
|
+
.map(([provider, chunks]) => `## ${provider}\n\n${chunks.slice(0, 3).join("\n\n")}`)
|
|
426
|
+
.join("\n\n---\n\n");
|
|
427
|
+
const missingProviders = requestedProviders.filter((provider) => !grouped.has(provider));
|
|
428
|
+
const missingNote = missingProviders.length
|
|
429
|
+
? `\n\nNo matching docs found for requested provider(s): ${missingProviders.join(", ")}.${missingProviders
|
|
430
|
+
.map((provider) => {
|
|
431
|
+
if (providerSet.has(provider))
|
|
432
|
+
return "";
|
|
433
|
+
const suggestions = providerSuggestions(provider, providerSet);
|
|
434
|
+
return suggestions.length ? ` ${provider}: did you mean ${suggestions.join(", ")}?` : "";
|
|
435
|
+
})
|
|
436
|
+
.join("")}`
|
|
437
|
+
: "";
|
|
438
|
+
return textResult(`Comparison for "${args.topic}" across ${grouped.size} provider(s):\n\n${sections}${missingNote}`);
|
|
439
|
+
}
|
|
440
|
+
export function requestUpdate(db, args, options = {}) {
|
|
441
|
+
const requestedAt = (options.now ?? new Date()).toISOString();
|
|
442
|
+
const providerKey = requestProviderKey(args.provider);
|
|
443
|
+
const countRow = db.prepare("SELECT COUNT(*) as cnt FROM requests").get();
|
|
444
|
+
if (countRow.cnt >= 500) {
|
|
445
|
+
return textResult(`Request queue is full (${countRow.cnt} entries). Please file an issue at https://github.com/withqwerty/football-docs/issues instead.`, true);
|
|
446
|
+
}
|
|
447
|
+
const recentRequest = db
|
|
448
|
+
.prepare(`SELECT id, requested_at FROM requests
|
|
449
|
+
WHERE provider = ? AND status = 'pending'
|
|
450
|
+
AND datetime(requested_at) > datetime(?, '-7 days')
|
|
451
|
+
LIMIT 1`)
|
|
452
|
+
.get(providerKey, requestedAt);
|
|
453
|
+
if (recentRequest) {
|
|
454
|
+
return textResult(`A pending request for "${args.provider}" already exists (from ${recentRequest.requested_at}). Requests have a 7-day cooldown to prevent duplicate work. Request ID: ${recentRequest.id}`, true);
|
|
455
|
+
}
|
|
456
|
+
const id = options.requestId ??
|
|
457
|
+
`req_${Date.now().toString(36)}_${Math.random().toString(36).slice(2, 6)}`;
|
|
458
|
+
db.prepare(`INSERT INTO requests (id, type, provider, reason, suggested_urls, requested_at, status)
|
|
459
|
+
VALUES (?, ?, ?, ?, ?, ?, 'pending')`).run(id, args.type, providerKey, args.reason, args.suggested_urls ? JSON.stringify(args.suggested_urls) : null, requestedAt);
|
|
460
|
+
const typeLabel = {
|
|
461
|
+
new_provider: "New provider request",
|
|
462
|
+
recrawl: "Recrawl request",
|
|
463
|
+
flag_outdated: "Outdated docs flag",
|
|
464
|
+
suggest_source: "Source suggestion",
|
|
465
|
+
}[args.type];
|
|
466
|
+
return textResult(`${typeLabel} queued for "${args.provider}" (ID: ${id}).\n\nReason: ${args.reason}${args.suggested_urls?.length
|
|
467
|
+
? `\nSuggested URLs:\n${args.suggested_urls.map((url) => ` - ${url}`).join("\n")}`
|
|
468
|
+
: ""}\n\nThis local request will be reviewed by maintainers. For community visibility, also open the matching GitHub issue: ${requestIssueUrl(args)}`);
|
|
469
|
+
}
|
|
470
|
+
export async function resolveEntity(args, options = {}) {
|
|
471
|
+
const baseUrl = options.baseUrl ?? "https://reep-api.rahulkeerthi2-95d.workers.dev";
|
|
472
|
+
const fetchImpl = options.fetchImpl ?? fetch;
|
|
473
|
+
let url;
|
|
474
|
+
if (args.qid) {
|
|
475
|
+
url = `${baseUrl}/lookup?qid=${encodeURIComponent(args.qid)}`;
|
|
476
|
+
}
|
|
477
|
+
else if (args.provider && args.id) {
|
|
478
|
+
url = `${baseUrl}/resolve?provider=${encodeURIComponent(args.provider)}&id=${encodeURIComponent(args.id)}`;
|
|
479
|
+
}
|
|
480
|
+
else if (args.name) {
|
|
481
|
+
url = `${baseUrl}/search?name=${encodeURIComponent(args.name)}&limit=10`;
|
|
482
|
+
if (args.type)
|
|
483
|
+
url += `&type=${encodeURIComponent(args.type)}`;
|
|
484
|
+
}
|
|
485
|
+
else {
|
|
486
|
+
return textResult("Provide at least one of: name, qid, or provider+id. Examples:\n- name: 'Cole Palmer'\n- provider: 'transfermarkt', id: '568177'\n- qid: 'Q99760796'", true);
|
|
487
|
+
}
|
|
488
|
+
try {
|
|
489
|
+
const response = await fetchImpl(url);
|
|
490
|
+
if (!response.ok) {
|
|
491
|
+
if (response.status === 401 || response.status === 403) {
|
|
492
|
+
return textResult(`Reep API authentication failed (${response.status} ${response.statusText}). Entity resolution is optional and needs a Reep API credential/configured endpoint before provider ID lookup can work. Docs search tools still work without Reep access.`, true);
|
|
493
|
+
}
|
|
494
|
+
return textResult(`Reep API error: ${response.status} ${response.statusText}`, true);
|
|
495
|
+
}
|
|
496
|
+
const data = (await response.json());
|
|
497
|
+
if (!data.results?.length) {
|
|
498
|
+
return textResult("No entities found matching the query.");
|
|
499
|
+
}
|
|
500
|
+
const formatted = data.results
|
|
501
|
+
.map((entity) => {
|
|
502
|
+
const ids = entity.external_ids;
|
|
503
|
+
const idLines = ids
|
|
504
|
+
? Object.entries(ids)
|
|
505
|
+
.map(([provider, id]) => ` ${provider}: ${id}`)
|
|
506
|
+
.join("\n")
|
|
507
|
+
: " (none)";
|
|
508
|
+
const bio = [
|
|
509
|
+
entity.date_of_birth && `DOB: ${entity.date_of_birth}`,
|
|
510
|
+
entity.nationality && `Nationality: ${entity.nationality}`,
|
|
511
|
+
entity.position && `Position: ${entity.position}`,
|
|
512
|
+
entity.height_cm && `Height: ${entity.height_cm}cm`,
|
|
513
|
+
entity.country && `Country: ${entity.country}`,
|
|
514
|
+
entity.stadium && `Stadium: ${entity.stadium}`,
|
|
515
|
+
]
|
|
516
|
+
.filter(Boolean)
|
|
517
|
+
.join(" | ");
|
|
518
|
+
return `### ${entity.name_en} (${entity.type})\nWikidata: ${entity.qid}${entity.aliases_en ? `\nAliases: ${entity.aliases_en}` : ""}${bio ? `\n${bio}` : ""}\nProvider IDs:\n${idLines}`;
|
|
519
|
+
})
|
|
520
|
+
.join("\n\n");
|
|
521
|
+
return textResult(`Found ${data.results.length} result(s):\n\n${formatted}`);
|
|
522
|
+
}
|
|
523
|
+
catch (error) {
|
|
524
|
+
return textResult(`Failed to reach Reep API: ${error instanceof Error ? error.message : String(error)}`, true);
|
|
525
|
+
}
|
|
526
|
+
}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
---
|
|
2
|
+
source_url: https://skillcorner.crunch.help/en/getting-started/api-access-dynamic-events
|
|
3
|
+
source_type: crunch_help_kb
|
|
4
|
+
upstream_version:
|
|
5
|
+
crawled_at: 2026-07-13T14:06:38.861Z
|
|
6
|
+
---
|
|
7
|
+
The aim of this page is to guide you when accessing SkillCorner Dynamic Events via SkillCorner API.
|
|
8
|
+
|
|
9
|
+
The last part of the article provides a code snippet for Python users.
|
|
10
|
+
|
|
11
|
+
If you have not already, you can start by reading
|
|
12
|
+
|
|
13
|
+
- The glossary section dedicated to [Dynamic Events](https://skillcorner.crunch.help/en/glossaries#dynamic-events).
|
|
14
|
+
- [Our article](https://skillcorner.crunch.help/en/getting-started/first-requests) about the global overview of the SkillCorner API.
|
|
15
|
+
|
|
16
|
+
## Dynamic Events CSV and Sportscode XML
|
|
17
|
+
|
|
18
|
+
SkillCorner delivers two data formats.
|
|
19
|
+
|
|
20
|
+
- CSV files that contains either one type of Dynamic Events or all Dynamic Events that occurs during a match. You can access the specifications [here](https://skillcorner.crunch.help/en/glossaries/off-ball-runs-csv-specifications).
|
|
21
|
+
- Video Analysis XML (Sportscode XML format) files that can be used to track visualise Dynamic Events in video clips in combination with Sportscode, SBG Focus or SBG MatchTracker.
|
|
22
|
+
|
|
23
|
+
## Using the API
|
|
24
|
+
|
|
25
|
+
Dynamic events are available through SkillCorner API.
|
|
26
|
+
|
|
27
|
+
The API documentation is available [here](https://skillcorner.com/api/docs/#/match/match_dynamic_events_off_ball_runs_list). You can use this page to test the API.
|
|
28
|
+
|
|
29
|
+
The endpoint are
|
|
30
|
+
|
|
31
|
+
- https://skillcorner.com/api/match/{match\_id}/dynamic\_events
|
|
32
|
+
- https://skillcorner.com/api/match/{match\_id}/dynamic\_events/player\_possessions
|
|
33
|
+
- https://skillcorner.com/api/match/{match\_id}/dynamic\_events/passing\_options
|
|
34
|
+
- https://skillcorner.com/api/match/{match\_id}/dynamic\_events/off\_ball\_runs
|
|
35
|
+
|
|
36
|
+
Where {match\_id} should be replaced with the id of the match you want to access events for.
|
|
37
|
+
|
|
38
|
+
Example: _https://skillcorner.com/api/match/911858/dynamic\_events_
|
|
39
|
+
|
|
40
|
+
By default the endpoint returns a CSV file containing the Dynamic Events associated with the match\_id you specified assuming
|
|
41
|
+
|
|
42
|
+
- The match was processed
|
|
43
|
+
|
|
44
|
+
- The Dynamic Events Check is passed (see more [here](https://skillcorner.crunch.help/en/getting-started/dynamic-events-check))
|
|
45
|
+
|
|
46
|
+
- There was no error during the generation of the dynamic events.
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
In order to access the Video Analysis XML, you need to specify the query parameter file\_format with the value “sportscode-xml”.
|
|
50
|
+
|
|
51
|
+
Example: _https://skillcorner.com/api/match/911858/dynamic\_events/off\_ball\_runs?file\_format=sportscode-xml_
|
|
52
|
+
|
|
53
|
+
The file should be available within a couple of seconds.
|
|
54
|
+
|
|
55
|
+
## Manage updates of the Dynamic Events
|
|
56
|
+
|
|
57
|
+
Via the data\_collection endpoint, you can determine when the dynamic events were last generated.
|
|
58
|
+
|
|
59
|
+
1. Send a call to the data\_collection endpoint https://skillcorner.com/api/match/{march\_id}/data\_collection where {match\_id} should be replaced with the id of the match you want to access events for.
|
|
60
|
+
2. Look for dynamic\_events\_last\_modified in the response.
|
|
61
|
+
3. The date corresponds to the last time we generated the dynamic events for the specific match ID.
|
|
62
|
+
|
|
63
|
+
## Using Python
|
|
64
|
+
|
|
65
|
+
You can use the SkillCorner Python client to access csv and xml files.
|
|
66
|
+
|
|
67
|
+
- If you have not installed the package yet go [here](https://skillcorner.crunch.help/en/getting-started/skillcorner-python-client).
|
|
68
|
+
- Otherwise make sure you upgrade it using the following command
|
|
69
|
+
`pip install -U skillcorner`
|
|
70
|
+
|
|
71
|
+
The Python Client documentation is available [here](https://skillcorner.readthedocs.io/en/latest/getting_started.html).
|
|
72
|
+
|
|
73
|
+
### Saving a file
|
|
74
|
+
|
|
75
|
+
Here is a snippet you can use to save the data for a given match ID
|
|
76
|
+
|
|
77
|
+
- Replace "your\_username", "your\_password", and "your\_match\_id".
|
|
78
|
+
- \[optional\] Modify the filepath within the save\_dynamic\_events method if you want to save the files elsewhere
|
|
79
|
+
- \[optional\] Change the format of the file to "sportscode-xml" and the filepath accordingly to retrieve the xml rather than the csv file.
|
|
80
|
+
|
|
81
|
+
```
|
|
82
|
+
from skillcorner.client import SkillcornerClient
|
|
83
|
+
|
|
84
|
+
# Instantiate the client
|
|
85
|
+
username = "your_username"
|
|
86
|
+
password = "your_password"
|
|
87
|
+
client = SkillcornerClient(username=username, password=password)
|
|
88
|
+
|
|
89
|
+
# Retrieve the data for a given match ID
|
|
90
|
+
match_id = your_match_id
|
|
91
|
+
|
|
92
|
+
data_collection = client.get_match_data_collection(match_id)
|
|
93
|
+
|
|
94
|
+
# The data is available if the "dynamic_events_check" value is True
|
|
95
|
+
if data_collection['dynamic_events_check']:
|
|
96
|
+
filepath = f"{match_id}.csv"
|
|
97
|
+
client.save_dynamic_events(match_id, params=
|
|
98
|
+
{
|
|
99
|
+
'file_format': 'csv'
|
|
100
|
+
},
|
|
101
|
+
filepath=filepath)
|
|
102
|
+
else:
|
|
103
|
+
print(f"Match {match_id} does not have Dynamic Events data available")
|
|
104
|
+
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
**Opening the CSV**
|
|
108
|
+
|
|
109
|
+
Here is a snippet you can use to open a csv for a given match ID
|
|
110
|
+
|
|
111
|
+
- Replace "your\_username", "your\_password", and "your\_match\_id".
|
|
112
|
+
|
|
113
|
+
```
|
|
114
|
+
from skillcorner.client import SkillcornerClient
|
|
115
|
+
import pandas as pd
|
|
116
|
+
|
|
117
|
+
# Instantiate the client
|
|
118
|
+
username = "your_username"
|
|
119
|
+
password = "your_password"
|
|
120
|
+
client = SkillcornerClient(username=username, password=password)
|
|
121
|
+
|
|
122
|
+
# Retrieve the data for a given match ID
|
|
123
|
+
match_id = your_match_id
|
|
124
|
+
|
|
125
|
+
data_collection = client.get_match_data_collection(match_id)
|
|
126
|
+
|
|
127
|
+
# The data is available if the "dynamic_events_check" value is True
|
|
128
|
+
if data_collection['dynamic_events_check']:
|
|
129
|
+
file = client.get_dynamic_events(match_id)
|
|
130
|
+
dynamic_events_df = pd.read_csv(file)
|
|
131
|
+
else:
|
|
132
|
+
print(f"Match {match_id} does not have Dynamic Events data available")
|
|
133
|
+
|
|
134
|
+
```
|