@rine-kit/pubg-share-page 0.0.0-stage → 0.2.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/LICENSE +21 -0
- package/README.md +10 -2
- package/dist/client/assets/index-7T3zKUsK.js +11 -0
- package/dist/client/assets/index-BTXEd66p.css +1 -0
- package/dist/client/index.html +18 -0
- package/dist/server/analysis-cache.d.ts +17 -0
- package/dist/server/analysis-cache.js +81 -0
- package/dist/server/analysis-pool.d.ts +23 -0
- package/dist/server/analysis-pool.js +82 -0
- package/dist/server/analysis-worker.d.ts +1 -0
- package/dist/server/analysis-worker.js +24 -0
- package/dist/server/context.d.ts +25 -0
- package/dist/server/context.js +57 -0
- package/dist/server/handler.d.ts +72 -0
- package/dist/server/handler.js +234 -0
- package/dist/server/index.d.ts +5 -0
- package/dist/server/index.js +5 -0
- package/dist/server/match-analysis.d.ts +18 -0
- package/dist/server/match-analysis.js +51 -0
- package/dist/server/names.d.ts +2 -0
- package/dist/server/names.js +6 -0
- package/dist/server/render.d.ts +24 -0
- package/dist/server/render.js +45 -0
- package/dist/server/share-page.d.ts +37 -0
- package/dist/server/share-page.js +120 -0
- package/dist/server/story.d.ts +84 -0
- package/dist/server/story.js +116 -0
- package/package.json +42 -3
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { type NormalizedMatch } from '@rine-kit/pubg-domain';
|
|
2
|
+
import { type ResearchSquad } from '@rine-kit/pubg-intelligence';
|
|
3
|
+
import type { StoryContext } from './context.js';
|
|
4
|
+
import type { MatchTelemetryAnalysis } from './match-analysis.js';
|
|
5
|
+
/**
|
|
6
|
+
* Analyse one archived match for a squad. The result is looked up in memory, then on disk, and only computed (on a
|
|
7
|
+
* worker thread, so the server stays responsive) when neither has it. Returns 'missing' when the archive has no entry
|
|
8
|
+
* (the CDN keeps telemetry for about 14 days) and 'failed' when it cannot be parsed.
|
|
9
|
+
*/
|
|
10
|
+
export declare function analyzeMatchTelemetry(context: StoryContext, squad: ResearchSquad, match: NormalizedMatch): Promise<MatchTelemetryAnalysis | 'missing' | 'failed'>;
|
|
11
|
+
/** Plain-language story of one match: lifelines, fights, route and circle, plus each member's numbers. */
|
|
12
|
+
export declare function computeMatchStory(context: StoryContext, squad: ResearchSquad, match: NormalizedMatch): Promise<{
|
|
13
|
+
available: boolean;
|
|
14
|
+
reason: string;
|
|
15
|
+
players: {
|
|
16
|
+
accountId: string;
|
|
17
|
+
name: string;
|
|
18
|
+
damage: number;
|
|
19
|
+
kills: number;
|
|
20
|
+
knocks: number;
|
|
21
|
+
assists: number;
|
|
22
|
+
revives: number;
|
|
23
|
+
survivalSeconds: number;
|
|
24
|
+
rank: number | null;
|
|
25
|
+
hitRate: number | null;
|
|
26
|
+
damagePerMinute: number | null;
|
|
27
|
+
timesDowned: number | null;
|
|
28
|
+
heals: number | null;
|
|
29
|
+
throwables: number | null;
|
|
30
|
+
rides: number | null;
|
|
31
|
+
footKm: number | null;
|
|
32
|
+
longestStreak: number | null;
|
|
33
|
+
}[];
|
|
34
|
+
story: null;
|
|
35
|
+
matchId: string;
|
|
36
|
+
mapName: string | null;
|
|
37
|
+
mapLabel: string;
|
|
38
|
+
mapSizeKm: number | null;
|
|
39
|
+
gameMode: string;
|
|
40
|
+
durationSeconds: number;
|
|
41
|
+
createdAt: string | null;
|
|
42
|
+
names: Record<string, string>;
|
|
43
|
+
downCauses: readonly {
|
|
44
|
+
key: import("@rine-kit/pubg-intelligence").DownCause;
|
|
45
|
+
label: string;
|
|
46
|
+
advice: string;
|
|
47
|
+
}[];
|
|
48
|
+
} | {
|
|
49
|
+
available: boolean;
|
|
50
|
+
reason: null;
|
|
51
|
+
players: {
|
|
52
|
+
accountId: string;
|
|
53
|
+
name: string;
|
|
54
|
+
damage: number;
|
|
55
|
+
kills: number;
|
|
56
|
+
knocks: number;
|
|
57
|
+
assists: number;
|
|
58
|
+
revives: number;
|
|
59
|
+
survivalSeconds: number;
|
|
60
|
+
rank: number | null;
|
|
61
|
+
hitRate: number | null;
|
|
62
|
+
damagePerMinute: number | null;
|
|
63
|
+
timesDowned: number | null;
|
|
64
|
+
heals: number | null;
|
|
65
|
+
throwables: number | null;
|
|
66
|
+
rides: number | null;
|
|
67
|
+
footKm: number | null;
|
|
68
|
+
longestStreak: number | null;
|
|
69
|
+
}[];
|
|
70
|
+
story: any;
|
|
71
|
+
matchId: string;
|
|
72
|
+
mapName: string | null;
|
|
73
|
+
mapLabel: string;
|
|
74
|
+
mapSizeKm: number | null;
|
|
75
|
+
gameMode: string;
|
|
76
|
+
durationSeconds: number;
|
|
77
|
+
createdAt: string | null;
|
|
78
|
+
names: Record<string, string>;
|
|
79
|
+
downCauses: readonly {
|
|
80
|
+
key: import("@rine-kit/pubg-intelligence").DownCause;
|
|
81
|
+
label: string;
|
|
82
|
+
advice: string;
|
|
83
|
+
}[];
|
|
84
|
+
}>;
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { DOWN_CAUSES, mapDisplayName, mapSizeKm, } from '@rine-kit/pubg-intelligence';
|
|
2
|
+
import { safePlayerName } from './names.js';
|
|
3
|
+
/**
|
|
4
|
+
* Analyse one archived match for a squad. The result is looked up in memory, then on disk, and only computed (on a
|
|
5
|
+
* worker thread, so the server stays responsive) when neither has it. Returns 'missing' when the archive has no entry
|
|
6
|
+
* (the CDN keeps telemetry for about 14 days) and 'failed' when it cannot be parsed.
|
|
7
|
+
*/
|
|
8
|
+
export function analyzeMatchTelemetry(context, squad, match) {
|
|
9
|
+
const key = `${squad.id}|${match.matchId}`;
|
|
10
|
+
const cached = context.telemetry.get(key);
|
|
11
|
+
if (cached)
|
|
12
|
+
return cached;
|
|
13
|
+
const request = (async () => {
|
|
14
|
+
const stored = context.cache.read(squad.id, match.matchId);
|
|
15
|
+
if (stored)
|
|
16
|
+
return stored;
|
|
17
|
+
try {
|
|
18
|
+
const result = await context.pool.run({
|
|
19
|
+
kind: 'analysis',
|
|
20
|
+
archiveDirectory: context.archiveDirectory,
|
|
21
|
+
match,
|
|
22
|
+
memberIds: [...squad.memberIds],
|
|
23
|
+
});
|
|
24
|
+
if (result !== 'missing')
|
|
25
|
+
context.cache.write(squad.id, match.matchId, result);
|
|
26
|
+
return result;
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
return 'failed';
|
|
30
|
+
}
|
|
31
|
+
})();
|
|
32
|
+
context.telemetry.set(key, request);
|
|
33
|
+
return request;
|
|
34
|
+
}
|
|
35
|
+
/** Plain-language story of one match: lifelines, fights, route and circle, plus each member's numbers. */
|
|
36
|
+
export async function computeMatchStory(context, squad, match) {
|
|
37
|
+
const members = squad.memberIds.length
|
|
38
|
+
? match.players.filter((player) => squad.memberIds.includes(player.accountId))
|
|
39
|
+
: match.players.slice(0, 4);
|
|
40
|
+
const trackedIds = new Set(members.map((player) => player.accountId));
|
|
41
|
+
const names = {};
|
|
42
|
+
members.forEach((player, index) => {
|
|
43
|
+
names[player.accountId] = safePlayerName(player.displayName || player.playerName, index);
|
|
44
|
+
});
|
|
45
|
+
const base = {
|
|
46
|
+
matchId: match.matchId,
|
|
47
|
+
mapName: match.mapName || null,
|
|
48
|
+
mapLabel: mapDisplayName(match.mapName || '未知地图'),
|
|
49
|
+
mapSizeKm: mapSizeKm(match.mapName || ''),
|
|
50
|
+
gameMode: match.gameMode,
|
|
51
|
+
durationSeconds: match.duration,
|
|
52
|
+
createdAt: match.createdAt ?? null,
|
|
53
|
+
names,
|
|
54
|
+
downCauses: DOWN_CAUSES,
|
|
55
|
+
};
|
|
56
|
+
const archived = await context.archivedIds();
|
|
57
|
+
const rows = members.map((player) => ({
|
|
58
|
+
accountId: player.accountId,
|
|
59
|
+
name: names[player.accountId],
|
|
60
|
+
damage: player.damage,
|
|
61
|
+
kills: player.kills,
|
|
62
|
+
knocks: player.dbnos,
|
|
63
|
+
assists: player.assists,
|
|
64
|
+
revives: player.revives,
|
|
65
|
+
survivalSeconds: Math.max(0, player.survivalTime),
|
|
66
|
+
rank: player.rank,
|
|
67
|
+
hitRate: null,
|
|
68
|
+
damagePerMinute: null,
|
|
69
|
+
timesDowned: null,
|
|
70
|
+
heals: null,
|
|
71
|
+
throwables: null,
|
|
72
|
+
rides: null,
|
|
73
|
+
footKm: null,
|
|
74
|
+
longestStreak: null,
|
|
75
|
+
}));
|
|
76
|
+
if (!archived.has(match.matchId))
|
|
77
|
+
return { ...base, available: false, reason: 'no_archive', players: rows, story: null };
|
|
78
|
+
try {
|
|
79
|
+
const story = await context.pool.run({
|
|
80
|
+
kind: 'story',
|
|
81
|
+
archiveDirectory: context.archiveDirectory,
|
|
82
|
+
match,
|
|
83
|
+
memberIds: [...trackedIds],
|
|
84
|
+
});
|
|
85
|
+
if (story === 'missing')
|
|
86
|
+
return { ...base, available: false, reason: 'no_archive', players: rows, story: null };
|
|
87
|
+
const analysis = await analyzeMatchTelemetry(context, squad.memberIds.length ? squad : { ...squad, memberIds: [...trackedIds] }, match);
|
|
88
|
+
if (typeof analysis !== 'string') {
|
|
89
|
+
for (const row of rows) {
|
|
90
|
+
const style = analysis.style[row.accountId];
|
|
91
|
+
const streak = analysis.streaks.players[row.accountId];
|
|
92
|
+
if (style) {
|
|
93
|
+
const shots = style.shots;
|
|
94
|
+
const hits = style.hits;
|
|
95
|
+
row.hitRate = shots >= 30 ? hits / shots : null;
|
|
96
|
+
row.damagePerMinute =
|
|
97
|
+
style.minutes >= 1 ? (style.gunDamage + style.explosiveDamage) / style.minutes : null;
|
|
98
|
+
row.heals = style.healUses + style.boostUses;
|
|
99
|
+
row.throwables =
|
|
100
|
+
style.throwables.frag +
|
|
101
|
+
style.throwables.smoke +
|
|
102
|
+
style.throwables.flash +
|
|
103
|
+
style.throwables.fire;
|
|
104
|
+
row.rides = style.rides;
|
|
105
|
+
row.footKm = style.footMeters / 1000;
|
|
106
|
+
}
|
|
107
|
+
row.timesDowned = analysis.fights.roles[row.accountId]?.timesDowned ?? null;
|
|
108
|
+
row.longestStreak = streak?.longest ?? null;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
return { ...base, available: true, reason: null, players: rows, story };
|
|
112
|
+
}
|
|
113
|
+
catch {
|
|
114
|
+
return { ...base, available: false, reason: 'unreadable', players: rows, story: null };
|
|
115
|
+
}
|
|
116
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,45 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rine-kit/pubg-share-page",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"description": "
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "The PUBG tactical share page behind a report's link: the page (React, built), the telemetry analysis in worker threads, and a host-independent request handler. The host injects where shares and matches come from; no database, OpenClaw or secrets in here. Extracted from RINE, whose page is the port of Lab's Intelligence Lab share view.",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/server/index.d.ts",
|
|
10
|
+
"import": "./dist/server/index.js",
|
|
11
|
+
"default": "./dist/server/index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"publishConfig": {
|
|
15
|
+
"access": "public"
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"dist"
|
|
19
|
+
],
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"@rine-kit/pubg-intelligence": "0.2.0",
|
|
22
|
+
"@rine-kit/pubg-domain": "0.2.0"
|
|
23
|
+
},
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"@types/node": "^26.6.5",
|
|
26
|
+
"@types/react": "^19.3.0",
|
|
27
|
+
"@types/react-dom": "^19.3.0",
|
|
28
|
+
"@vitejs/plugin-react": "^6.1.2",
|
|
29
|
+
"react": "^19.3.1",
|
|
30
|
+
"react-dom": "^19.3.1",
|
|
31
|
+
"tsx": "^4.23.15",
|
|
32
|
+
"typescript": "^5.9.2",
|
|
33
|
+
"vite": "^8.3.4"
|
|
34
|
+
},
|
|
35
|
+
"repository": {
|
|
36
|
+
"type": "git",
|
|
37
|
+
"url": "git+ssh://git@github.com/ChristmasFox/rine-kit.git",
|
|
38
|
+
"directory": "packages/pubg-share-page"
|
|
39
|
+
},
|
|
40
|
+
"scripts": {
|
|
41
|
+
"build": "vite build && tsc -p tsconfig.build.json",
|
|
42
|
+
"typecheck": "tsc -p tsconfig.json --noEmit && tsc -p src/client/tsconfig.json --noEmit",
|
|
43
|
+
"test": "tsx --test \"tests/**/*.test.ts\""
|
|
44
|
+
}
|
|
6
45
|
}
|