@rine-kit/presentation 0.0.0-stage → 0.1.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/dist/src/builders/pubg.d.ts +35 -0
- package/dist/src/builders/pubg.js +725 -0
- package/dist/src/contracts/owner.d.ts +20 -0
- package/dist/src/contracts/owner.js +1 -0
- package/dist/src/contracts/pubg.d.ts +200 -0
- package/dist/src/contracts/pubg.js +1 -0
- package/dist/src/contracts/session-review.d.ts +72 -0
- package/dist/src/contracts/session-review.js +1 -0
- package/dist/src/index.d.ts +19 -0
- package/dist/src/index.js +19 -0
- package/dist/src/pubg-registry.d.ts +21 -0
- package/dist/src/pubg-registry.js +123 -0
- package/dist/src/renderers/daily-review.d.ts +22 -0
- package/dist/src/renderers/daily-review.js +149 -0
- package/dist/src/renderers/owner.d.ts +6 -0
- package/dist/src/renderers/owner.js +35 -0
- package/dist/src/renderers/pubg.d.ts +22 -0
- package/dist/src/renderers/pubg.js +603 -0
- package/dist/src/renderers/session-review.d.ts +15 -0
- package/dist/src/renderers/session-review.js +187 -0
- package/dist/src/reply-check.d.ts +3 -0
- package/dist/src/reply-check.js +44 -0
- package/dist/src/reply-guides.d.ts +10 -0
- package/dist/src/reply-guides.js +64 -0
- package/dist/src/time/format.d.ts +16 -0
- package/dist/src/time/format.js +63 -0
- package/dist/src/validation/session-review.d.ts +3 -0
- package/dist/src/validation/session-review.js +136 -0
- package/dist/src/validation/validate.d.ts +18 -0
- package/dist/src/validation/validate.js +736 -0
- package/dist/src/worldline/adapter.d.ts +3 -0
- package/dist/src/worldline/adapter.js +47 -0
- package/dist/src/worldline/contracts.d.ts +44 -0
- package/dist/src/worldline/contracts.js +40 -0
- package/dist/src/worldline/policy.d.ts +2 -0
- package/dist/src/worldline/policy.js +31 -0
- package/dist/src/worldline/renderer.d.ts +3 -0
- package/dist/src/worldline/renderer.js +5 -0
- package/dist/src/worldline/vocabulary.d.ts +2 -0
- package/dist/src/worldline/vocabulary.js +1 -0
- package/package.json +33 -3
- package/README.md +0 -3
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { formatDisplayTime } from '../time/format.js';
|
|
2
|
+
import { assertValid, validateOwnerNotificationPresentation } from '../validation/validate.js';
|
|
3
|
+
function fact(value) {
|
|
4
|
+
if (value === null)
|
|
5
|
+
return '未知';
|
|
6
|
+
if (typeof value === 'boolean')
|
|
7
|
+
return value ? '是' : '否';
|
|
8
|
+
return String(value);
|
|
9
|
+
}
|
|
10
|
+
export function renderOwnerNotification(presentation, options = {}) {
|
|
11
|
+
const validated = assertValid(validateOwnerNotificationPresentation(presentation));
|
|
12
|
+
const lines = [validated.headline];
|
|
13
|
+
if (validated.summary)
|
|
14
|
+
lines.push('', validated.summary);
|
|
15
|
+
if (validated.facts.length) {
|
|
16
|
+
lines.push('', ...validated.facts.map((item) => `- ${item.label}:${fact(item.value)}`));
|
|
17
|
+
}
|
|
18
|
+
if (validated.links?.length) {
|
|
19
|
+
lines.push('', ...validated.links.map((item) => `- ${item.label}:${item.url}`));
|
|
20
|
+
}
|
|
21
|
+
if (validated.dataUpdatedAt) {
|
|
22
|
+
const timeOptions = {
|
|
23
|
+
...(options.timezone ? { timezone: options.timezone } : {}),
|
|
24
|
+
now: options.now ?? validated.occurredAt,
|
|
25
|
+
};
|
|
26
|
+
const display = formatDisplayTime(validated.dataUpdatedAt, {
|
|
27
|
+
...timeOptions,
|
|
28
|
+
});
|
|
29
|
+
if (display)
|
|
30
|
+
lines.push('', `数据更新时间:${display}`);
|
|
31
|
+
}
|
|
32
|
+
if (validated.worldLineClosing)
|
|
33
|
+
lines.push('', 'El Psy Kongroo.');
|
|
34
|
+
return lines.join('\n');
|
|
35
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { PubgComparisonPresentation, PubgMatchDetailPresentation, PubgMatchListPresentation, PubgMatchReviewPresentation, PubgMetricRow, PubgPeriodReviewPresentation, PubgStatsPresentation, PubgStatusPresentation, PubgTeamDamagePresentation } from '../contracts/pubg.js';
|
|
2
|
+
export interface PubgRenderOptions {
|
|
3
|
+
timezone?: string;
|
|
4
|
+
now?: Date | string;
|
|
5
|
+
includeCoverage?: boolean;
|
|
6
|
+
localizedMetrics?: boolean;
|
|
7
|
+
/** Chat-reply style (implies localized): **bold** names, titles and totals, and no filler metrics. */
|
|
8
|
+
chatEmphasis?: boolean;
|
|
9
|
+
}
|
|
10
|
+
/** Round floats for chat/share display; integers stay integers. */
|
|
11
|
+
export declare function formatMetricNumber(key: string, raw: string | number | null): string;
|
|
12
|
+
/** Deterministic honorary titles for clear team leaders (strict max, ties broken by row order). */
|
|
13
|
+
export declare function assignStatTitles(rows: readonly PubgMetricRow[]): Map<number, string[]>;
|
|
14
|
+
export declare function renderPubgStatus(presentation: PubgStatusPresentation, options?: PubgRenderOptions): string;
|
|
15
|
+
export declare function renderPubgStats(presentation: PubgStatsPresentation, options?: PubgRenderOptions): string;
|
|
16
|
+
export declare function renderPubgMatchList(presentation: PubgMatchListPresentation, options?: PubgRenderOptions): string;
|
|
17
|
+
export declare function renderPubgComparison(presentation: PubgComparisonPresentation, options?: PubgRenderOptions): string;
|
|
18
|
+
export declare function renderPubgMatchDetail(presentation: PubgMatchDetailPresentation, options?: PubgRenderOptions): string;
|
|
19
|
+
export declare function renderPubgMatchReview(presentation: PubgMatchReviewPresentation, options?: PubgRenderOptions): string;
|
|
20
|
+
export declare function renderPubgPeriodReview(presentation: PubgPeriodReviewPresentation, options?: PubgRenderOptions): string;
|
|
21
|
+
export declare function renderPubgTeamDamage(presentation: PubgTeamDamagePresentation, options?: PubgRenderOptions): string;
|
|
22
|
+
export declare function formatPubgSourceRange(from: string | null, to: string | null, options?: PubgRenderOptions): string;
|
|
@@ -0,0 +1,603 @@
|
|
|
1
|
+
import { formatDisplayRange, formatDisplayTime } from '../time/format.js';
|
|
2
|
+
import { sessionMapName } from './session-review.js';
|
|
3
|
+
import { assertValid, validatePubgComparisonPresentation, validatePubgMatchDetailPresentation, validatePubgMatchListPresentation, validatePubgMatchReviewPresentation, validatePubgPeriodReviewPresentation, validatePubgStatsPresentation, validatePubgStatusPresentation, validatePubgTeamDamagePresentation, } from '../validation/validate.js';
|
|
4
|
+
function timeOptions(options, extra = {}) {
|
|
5
|
+
return {
|
|
6
|
+
...extra,
|
|
7
|
+
...(options.timezone ? { timezone: options.timezone } : {}),
|
|
8
|
+
...(options.now ? { now: options.now } : {}),
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
function userText(value) {
|
|
12
|
+
return value
|
|
13
|
+
.replace(/Asia\/Shanghai/gu, '北京时间')
|
|
14
|
+
.replace(/UTC\+?08(?::00)?/gu, '北京时间')
|
|
15
|
+
.replace(/自然日|业务日/gu, '日期');
|
|
16
|
+
}
|
|
17
|
+
function value(value) {
|
|
18
|
+
return value === null ? '未知' : userText(String(value));
|
|
19
|
+
}
|
|
20
|
+
function statusLine(status) {
|
|
21
|
+
if (status === 'partial')
|
|
22
|
+
return '结果不完整:缺失事实保持为未知。';
|
|
23
|
+
if (status === 'no_matches')
|
|
24
|
+
return '没有找到符合条件的比赛。';
|
|
25
|
+
if (status === 'error')
|
|
26
|
+
return '当前数据源无法完成这次查询,没有使用旧聊天数据代替。';
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
function sourceRangeLines(range, options) {
|
|
30
|
+
if (!range)
|
|
31
|
+
return [];
|
|
32
|
+
const segments = range.segments ?? [];
|
|
33
|
+
if (segments.length > 1) {
|
|
34
|
+
return [
|
|
35
|
+
'数据范围:',
|
|
36
|
+
...segments.map((segment) => `- ${userText(segment.label)}:${formatDisplayRange(segment.from, segment.to, timeOptions(options))}`),
|
|
37
|
+
];
|
|
38
|
+
}
|
|
39
|
+
return [`数据范围:${formatDisplayRange(range.from, range.to, timeOptions(options))}`];
|
|
40
|
+
}
|
|
41
|
+
function footer(presentation, options) {
|
|
42
|
+
const updated = formatDisplayTime(presentation.dataUpdatedAt, timeOptions(options)) ?? '未知';
|
|
43
|
+
const coverage = options.includeCoverage && presentation.coverage
|
|
44
|
+
? [
|
|
45
|
+
`数据覆盖:${presentation.coverage.complete ? '完整' : '不完整'}(${presentation.coverage.status})`,
|
|
46
|
+
`数据新鲜度:${presentation.coverage.freshness === 'fresh' ? '较新' : presentation.coverage.freshness === 'stale' ? '可能过期' : '未知'}`,
|
|
47
|
+
]
|
|
48
|
+
: [];
|
|
49
|
+
return [
|
|
50
|
+
'',
|
|
51
|
+
...sourceRangeLines(presentation.sourceRange, options),
|
|
52
|
+
...coverage,
|
|
53
|
+
`数据更新时间:${updated}`,
|
|
54
|
+
];
|
|
55
|
+
}
|
|
56
|
+
const METRIC_LABELS = {
|
|
57
|
+
matches: '场次',
|
|
58
|
+
kills: '击杀',
|
|
59
|
+
assists: '助攻',
|
|
60
|
+
damage: '伤害',
|
|
61
|
+
avg_damage: '场均伤害',
|
|
62
|
+
kd: 'KD',
|
|
63
|
+
deaths: '死亡',
|
|
64
|
+
wins: '胜利',
|
|
65
|
+
top10: '前十',
|
|
66
|
+
rank: '排名',
|
|
67
|
+
dbnos: '倒地',
|
|
68
|
+
revives: '救援',
|
|
69
|
+
headshot_kills: '爆头击杀',
|
|
70
|
+
survival_time: '生存时间',
|
|
71
|
+
longest_kill: '最远击杀',
|
|
72
|
+
avg_kills: '场均击杀',
|
|
73
|
+
avg_rank: '场均排名',
|
|
74
|
+
top10_rate: '前十率',
|
|
75
|
+
denominatorZero: '零死亡场次',
|
|
76
|
+
performance_score: '表现分',
|
|
77
|
+
chicken_index: '吃鸡指数',
|
|
78
|
+
};
|
|
79
|
+
/** Keys that are internal bookkeeping and should not appear in user-facing 战绩 lines. */
|
|
80
|
+
const HIDDEN_USER_METRICS = new Set(['denominatorZero', 'performance_score', 'chicken_index']);
|
|
81
|
+
/** Prefer this order when composing a localized player line. */
|
|
82
|
+
const RICH_METRIC_ORDER = [
|
|
83
|
+
'matches',
|
|
84
|
+
'kills',
|
|
85
|
+
'assists',
|
|
86
|
+
'damage',
|
|
87
|
+
'dbnos',
|
|
88
|
+
'revives',
|
|
89
|
+
'headshot_kills',
|
|
90
|
+
'top10',
|
|
91
|
+
'wins',
|
|
92
|
+
'kd',
|
|
93
|
+
'avg_damage',
|
|
94
|
+
'longest_kill',
|
|
95
|
+
'deaths',
|
|
96
|
+
'avg_kills',
|
|
97
|
+
'avg_rank',
|
|
98
|
+
'top10_rate',
|
|
99
|
+
'rank',
|
|
100
|
+
'survival_time',
|
|
101
|
+
];
|
|
102
|
+
const TITLE_RULES = [
|
|
103
|
+
{ key: 'assists', title: '全队助攻王' },
|
|
104
|
+
{ key: 'damage', title: '全队伤害第一' },
|
|
105
|
+
{ key: 'dbnos', title: '破点王' },
|
|
106
|
+
{ key: 'revives', title: '全队救援王' },
|
|
107
|
+
];
|
|
108
|
+
function numericMetric(value) {
|
|
109
|
+
if (typeof value === 'number' && Number.isFinite(value))
|
|
110
|
+
return value;
|
|
111
|
+
if (typeof value === 'string' && value.trim() && Number.isFinite(Number(value)))
|
|
112
|
+
return Number(value);
|
|
113
|
+
return null;
|
|
114
|
+
}
|
|
115
|
+
/** Round floats for chat/share display; integers stay integers. */
|
|
116
|
+
export function formatMetricNumber(key, raw) {
|
|
117
|
+
if (raw === null)
|
|
118
|
+
return '未知';
|
|
119
|
+
if (typeof raw === 'string')
|
|
120
|
+
return userText(raw);
|
|
121
|
+
if (!Number.isFinite(raw))
|
|
122
|
+
return '未知';
|
|
123
|
+
if (Number.isInteger(raw))
|
|
124
|
+
return String(raw);
|
|
125
|
+
if (key === 'kd' ||
|
|
126
|
+
key === 'avg_kills' ||
|
|
127
|
+
key === 'top10_rate' ||
|
|
128
|
+
key === 'avg_rank' ||
|
|
129
|
+
key === 'rank') {
|
|
130
|
+
return (Math.round(raw * 100) / 100).toFixed(2);
|
|
131
|
+
}
|
|
132
|
+
// damage / avg_damage / longest_kill → one decimal
|
|
133
|
+
return (Math.round(raw * 10) / 10).toFixed(1);
|
|
134
|
+
}
|
|
135
|
+
function formatKd(raw) {
|
|
136
|
+
if (raw === null)
|
|
137
|
+
return '未知';
|
|
138
|
+
if (typeof raw === 'string')
|
|
139
|
+
return userText(raw);
|
|
140
|
+
if (!Number.isFinite(raw))
|
|
141
|
+
return '未知';
|
|
142
|
+
return (Math.round(raw * 100) / 100).toFixed(2);
|
|
143
|
+
}
|
|
144
|
+
/** Deterministic honorary titles for clear team leaders (strict max, ties broken by row order). */
|
|
145
|
+
export function assignStatTitles(rows) {
|
|
146
|
+
const titles = new Map();
|
|
147
|
+
if (rows.length < 2)
|
|
148
|
+
return titles;
|
|
149
|
+
for (const rule of TITLE_RULES) {
|
|
150
|
+
let bestIndex = -1;
|
|
151
|
+
let bestValue = 0;
|
|
152
|
+
for (let index = 0; index < rows.length; index += 1) {
|
|
153
|
+
const amount = numericMetric(rows[index].values[rule.key] ?? null);
|
|
154
|
+
if (amount === null || amount <= 0)
|
|
155
|
+
continue;
|
|
156
|
+
if (bestIndex < 0 || amount > bestValue) {
|
|
157
|
+
bestIndex = index;
|
|
158
|
+
bestValue = amount;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
if (bestIndex < 0)
|
|
162
|
+
continue;
|
|
163
|
+
const list = titles.get(bestIndex) ?? [];
|
|
164
|
+
list.push(rule.title);
|
|
165
|
+
titles.set(bestIndex, list);
|
|
166
|
+
}
|
|
167
|
+
return titles;
|
|
168
|
+
}
|
|
169
|
+
function richMetricFragment(key, raw, title) {
|
|
170
|
+
if (raw === null)
|
|
171
|
+
return null;
|
|
172
|
+
const titleSuffix = title ? `(${title})` : '';
|
|
173
|
+
switch (key) {
|
|
174
|
+
case 'matches':
|
|
175
|
+
return `${formatMetricNumber(key, raw)} 场`;
|
|
176
|
+
case 'kills':
|
|
177
|
+
return `${formatMetricNumber(key, raw)} 杀`;
|
|
178
|
+
case 'assists':
|
|
179
|
+
return `${formatMetricNumber(key, raw)} 助攻${titleSuffix}`;
|
|
180
|
+
case 'damage':
|
|
181
|
+
return `${formatMetricNumber(key, raw)} 伤害${titleSuffix}`;
|
|
182
|
+
case 'dbnos':
|
|
183
|
+
return `${formatMetricNumber(key, raw)} 击倒${titleSuffix}`;
|
|
184
|
+
case 'revives':
|
|
185
|
+
return `${formatMetricNumber(key, raw)} 救援${titleSuffix}`;
|
|
186
|
+
case 'headshot_kills':
|
|
187
|
+
return `${formatMetricNumber(key, raw)} 爆头`;
|
|
188
|
+
case 'top10':
|
|
189
|
+
return `${formatMetricNumber(key, raw)} 次前十`;
|
|
190
|
+
case 'wins':
|
|
191
|
+
return Number(raw) > 0 ? `${formatMetricNumber(key, raw)} 吃鸡` : null;
|
|
192
|
+
case 'kd':
|
|
193
|
+
return `KD ${formatKd(raw)}`;
|
|
194
|
+
case 'avg_damage':
|
|
195
|
+
return `场均伤害 ${formatMetricNumber(key, raw)}`;
|
|
196
|
+
case 'longest_kill':
|
|
197
|
+
return `最远击杀 ${formatMetricNumber(key, raw)}m`;
|
|
198
|
+
case 'deaths':
|
|
199
|
+
return `${formatMetricNumber(key, raw)} 死`;
|
|
200
|
+
case 'avg_kills':
|
|
201
|
+
return `场均击杀 ${formatMetricNumber(key, raw)}`;
|
|
202
|
+
case 'avg_rank':
|
|
203
|
+
return `场均排名 ${formatMetricNumber(key, raw)}`;
|
|
204
|
+
case 'top10_rate':
|
|
205
|
+
return `前十率 ${formatMetricNumber(key, raw)}`;
|
|
206
|
+
case 'rank':
|
|
207
|
+
return `排名 ${formatMetricNumber(key, raw)}`;
|
|
208
|
+
case 'survival_time':
|
|
209
|
+
return `生存 ${formatMetricNumber(key, raw)}s`;
|
|
210
|
+
default: {
|
|
211
|
+
if (HIDDEN_USER_METRICS.has(key))
|
|
212
|
+
return null;
|
|
213
|
+
return `${METRIC_LABELS[key] ?? userText(key)} ${formatMetricNumber(key, raw)}`;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
const CHAT_FILLER_METRICS = new Set([
|
|
218
|
+
'avg_kills',
|
|
219
|
+
'avg_rank',
|
|
220
|
+
'top10_rate',
|
|
221
|
+
'rank',
|
|
222
|
+
'survival_time',
|
|
223
|
+
]);
|
|
224
|
+
function metricRow(row, localizedMetrics, titles = [], emphasis = false) {
|
|
225
|
+
if (!localizedMetrics) {
|
|
226
|
+
const entries = Object.entries(row.values)
|
|
227
|
+
.filter(([key]) => !HIDDEN_USER_METRICS.has(key))
|
|
228
|
+
.map(([key, item]) => `${userText(key)}=${typeof item === 'number' ? formatMetricNumber(key, item) : value(item)}`);
|
|
229
|
+
const rank = row.position === undefined ? '' : `(序号:${value(row.position)})`;
|
|
230
|
+
return `- ${userText(row.label)}${rank}${entries.length ? `:${entries.join(',')}` : ''}`;
|
|
231
|
+
}
|
|
232
|
+
const titleByKey = new Map();
|
|
233
|
+
for (const title of titles) {
|
|
234
|
+
const rule = TITLE_RULES.find((item) => item.title === title);
|
|
235
|
+
if (rule)
|
|
236
|
+
titleByKey.set(rule.key, title);
|
|
237
|
+
}
|
|
238
|
+
const seen = new Set();
|
|
239
|
+
const fragments = [];
|
|
240
|
+
for (const key of RICH_METRIC_ORDER) {
|
|
241
|
+
if (!(key in row.values) || HIDDEN_USER_METRICS.has(key))
|
|
242
|
+
continue;
|
|
243
|
+
seen.add(key);
|
|
244
|
+
if (emphasis && CHAT_FILLER_METRICS.has(key))
|
|
245
|
+
continue;
|
|
246
|
+
const fragment = richMetricFragment(key, row.values[key] ?? null, titleByKey.get(key));
|
|
247
|
+
if (fragment)
|
|
248
|
+
fragments.push(emphasis && (titleByKey.has(key) || key === 'wins' || key === 'kills' || key === 'kd')
|
|
249
|
+
? `**${fragment}**`
|
|
250
|
+
: fragment);
|
|
251
|
+
}
|
|
252
|
+
for (const [key, item] of Object.entries(row.values)) {
|
|
253
|
+
if (seen.has(key) || HIDDEN_USER_METRICS.has(key) || (emphasis && CHAT_FILLER_METRICS.has(key)))
|
|
254
|
+
continue;
|
|
255
|
+
const fragment = richMetricFragment(key, item, titleByKey.get(key));
|
|
256
|
+
if (fragment)
|
|
257
|
+
fragments.push(fragment);
|
|
258
|
+
}
|
|
259
|
+
// Leftover titles (should not happen) still get shown after the name.
|
|
260
|
+
const orphanTitles = titles.filter((title) => !TITLE_RULES.some((rule) => rule.title === title && titleByKey.get(rule.key) === title));
|
|
261
|
+
const titlePrefix = orphanTitles.length
|
|
262
|
+
? orphanTitles.map((title) => `(${title})`).join('')
|
|
263
|
+
: '';
|
|
264
|
+
const name = emphasis ? `**${userText(row.label)}**` : userText(row.label);
|
|
265
|
+
return `- ${name}${titlePrefix}${fragments.length ? `:${fragments.join(',')}` : ''}`;
|
|
266
|
+
}
|
|
267
|
+
/** "10月19日星期一" for a range covering one business day; null for anything else. */
|
|
268
|
+
function dayLabel(range, options) {
|
|
269
|
+
if (!range?.from || !range.to)
|
|
270
|
+
return null;
|
|
271
|
+
const from = new Date(range.from);
|
|
272
|
+
const hours = (new Date(range.to).getTime() - from.getTime()) / 3_600_000;
|
|
273
|
+
if (!Number.isFinite(hours) || hours < 23 || hours > 25)
|
|
274
|
+
return null;
|
|
275
|
+
try {
|
|
276
|
+
return new Intl.DateTimeFormat('zh-CN', {
|
|
277
|
+
timeZone: options.timezone ?? 'Asia/Shanghai',
|
|
278
|
+
month: 'long',
|
|
279
|
+
day: 'numeric',
|
|
280
|
+
weekday: 'long',
|
|
281
|
+
}).format(from);
|
|
282
|
+
}
|
|
283
|
+
catch {
|
|
284
|
+
return null;
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
/** A model-built time_range arrives labelled 指定时间; a one-business-day range reads better as its date. */
|
|
288
|
+
function chatHeadline(headline, range, options) {
|
|
289
|
+
const text = userText(headline);
|
|
290
|
+
const day = text === '指定时间' ? dayLabel(range, options) : null;
|
|
291
|
+
return day ? `${day} 全天战报` : text;
|
|
292
|
+
}
|
|
293
|
+
function slicesText(slices) {
|
|
294
|
+
return slices.map((slice) => `${slice.label} ${slice.hitCount} 次`).join('、');
|
|
295
|
+
}
|
|
296
|
+
/** The 队内误伤账本 a chat reply retells: totals by kind, every direction, the worst matches, and who stayed clean. */
|
|
297
|
+
function renderTeamDamageLedger(presentation, options) {
|
|
298
|
+
const day = dayLabel(presentation.sourceRange, options);
|
|
299
|
+
const ledger = presentation.ledger;
|
|
300
|
+
const lines = [`🥊 ${day ? `${day} ` : ''}队内误伤账本`, ''];
|
|
301
|
+
const status = statusLine(presentation.status);
|
|
302
|
+
if (status)
|
|
303
|
+
lines.push(status, '');
|
|
304
|
+
if (!presentation.directions.length) {
|
|
305
|
+
lines.push(userText(presentation.summary));
|
|
306
|
+
return lines.concat(footer(presentation, options)).join('\n');
|
|
307
|
+
}
|
|
308
|
+
const total = presentation.totalDamage === null
|
|
309
|
+
? '未知'
|
|
310
|
+
: formatMetricNumber('damage', presentation.totalDamage);
|
|
311
|
+
lines.push(`• 总误伤:**${total} 点**`);
|
|
312
|
+
lines.push(`• 总命中:**${value(presentation.totalHitCount)} 次**${ledger?.sources.length ? `(${slicesText(ledger.sources)})` : ''}`);
|
|
313
|
+
if (presentation.actorTotals?.length) {
|
|
314
|
+
const basis = presentation.rankingBasis === 'knownDamage' ? '(按已知伤害下限排序)' : '';
|
|
315
|
+
lines.push('', `**队员误伤输出排名${basis}:**`, ...presentation.actorTotals.map((total) => {
|
|
316
|
+
const damage = total.complete ? total.damage : total.knownDamage;
|
|
317
|
+
const hits = total.complete ? total.hitCount : total.knownHitCount;
|
|
318
|
+
return `${total.position}. ${userText(total.actor)}:${total.complete ? '' : '已知至少 '}${damage === null ? '未知' : formatMetricNumber('damage', damage)} 伤害 / ${value(hits)} 次`;
|
|
319
|
+
}));
|
|
320
|
+
}
|
|
321
|
+
lines.push('', '───', '', `**互相伤害明细(共 ${presentation.directions.length} 个方向):**`);
|
|
322
|
+
presentation.directions.forEach((direction, index) => {
|
|
323
|
+
const damage = direction.damage === null ? '未知' : formatMetricNumber('damage', direction.damage);
|
|
324
|
+
const kinds = ledger?.directionSources[index] ?? [];
|
|
325
|
+
lines.push(`${index + 1}. **${userText(direction.actor)} ➡️ ${userText(direction.victim)}**`, ` • 总输出:**${value(direction.hitCount)} 次命中,造成 ${damage} 伤害**${kinds.length ? `(${slicesText(kinds)})` : ''}${direction.complete ? '' : '(不完整)'}`);
|
|
326
|
+
});
|
|
327
|
+
if (ledger?.highlights.length) {
|
|
328
|
+
lines.push('', '───', '', '**名场面:**');
|
|
329
|
+
for (const highlight of ledger.highlights) {
|
|
330
|
+
const pairs = highlight.pairs
|
|
331
|
+
.map((pair) => `${userText(pair.actor)} ➡️ ${userText(pair.victim)} ${pair.hitCount} 次 ${formatMetricNumber('damage', pair.damage)} 点`)
|
|
332
|
+
.join(';');
|
|
333
|
+
lines.push(`• ${highlight.label}:单局 **${formatMetricNumber('damage', highlight.damage)} 点(${highlight.hitCount} 次命中)**:${pairs}`);
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
if (ledger?.quiet.length)
|
|
337
|
+
lines.push('', `清白名单:${ledger.quiet.map(userText).join('、')}(0 次主动队内输出)`);
|
|
338
|
+
return lines.concat(footer(presentation, options)).join('\n');
|
|
339
|
+
}
|
|
340
|
+
const CHAT_MEDALS = ['🥇', '🥈', '🥉'];
|
|
341
|
+
const CHAT_VOLUME_KEYS = [
|
|
342
|
+
'kills',
|
|
343
|
+
'assists',
|
|
344
|
+
'damage',
|
|
345
|
+
'dbnos',
|
|
346
|
+
'revives',
|
|
347
|
+
'headshot_kills',
|
|
348
|
+
'top10',
|
|
349
|
+
'wins',
|
|
350
|
+
];
|
|
351
|
+
const CHAT_PERSONAL_KEYS = ['kd', 'avg_damage', 'longest_kill', 'deaths'];
|
|
352
|
+
/** Chat card: medal + bold name, then a 出战 line (volume) and a 个人数据 line (rates), like the squad's 战报. */
|
|
353
|
+
function chatPlayerBlock(row, index, titles) {
|
|
354
|
+
const titleByKey = new Map();
|
|
355
|
+
for (const title of titles) {
|
|
356
|
+
const rule = TITLE_RULES.find((item) => item.title === title);
|
|
357
|
+
if (rule)
|
|
358
|
+
titleByKey.set(rule.key, title);
|
|
359
|
+
}
|
|
360
|
+
const emphasize = (key) => titleByKey.has(key) || key === 'wins' || key === 'kills' || key === 'kd';
|
|
361
|
+
const fragments = (keys) => keys.flatMap((key) => {
|
|
362
|
+
if (!(key in row.values))
|
|
363
|
+
return [];
|
|
364
|
+
const fragment = richMetricFragment(key, row.values[key] ?? null, titleByKey.get(key));
|
|
365
|
+
return fragment ? [emphasize(key) ? `**${fragment}**` : fragment] : [];
|
|
366
|
+
});
|
|
367
|
+
const matches = row.values.matches === undefined
|
|
368
|
+
? null
|
|
369
|
+
: richMetricFragment('matches', row.values.matches ?? null);
|
|
370
|
+
const volume = fragments(CHAT_VOLUME_KEYS);
|
|
371
|
+
const personal = fragments(CHAT_PERSONAL_KEYS);
|
|
372
|
+
const lines = [`${CHAT_MEDALS[index] ?? '🎖️'} **${userText(row.label)}**`];
|
|
373
|
+
if (matches || volume.length)
|
|
374
|
+
lines.push(`• **${matches ? `出战 ${matches.replace(/ 场$/u, '')} 局` : '数据'}**${volume.length ? `:${volume.join(',')}` : ''}`);
|
|
375
|
+
if (personal.length)
|
|
376
|
+
lines.push(`• 个人数据:${personal.join(',')}`);
|
|
377
|
+
return lines;
|
|
378
|
+
}
|
|
379
|
+
function teamTotalsLine(rows, emphasis = false) {
|
|
380
|
+
if (rows.length < 2)
|
|
381
|
+
return null;
|
|
382
|
+
const sum = (key) => rows.reduce((total, row) => total + (numericMetric(row.values[key] ?? null) ?? 0), 0);
|
|
383
|
+
const max = (key) => rows.reduce((best, row) => {
|
|
384
|
+
const amount = numericMetric(row.values[key] ?? null);
|
|
385
|
+
return amount === null ? best : Math.max(best, amount);
|
|
386
|
+
}, 0);
|
|
387
|
+
const kills = sum('kills');
|
|
388
|
+
const damage = sum('damage');
|
|
389
|
+
const dbnos = sum('dbnos');
|
|
390
|
+
const assists = sum('assists');
|
|
391
|
+
const revives = sum('revives');
|
|
392
|
+
// Squad chicken dinners are credited to every member of the winning match; max avoids double-counting.
|
|
393
|
+
const wins = max('wins');
|
|
394
|
+
const deaths = sum('deaths');
|
|
395
|
+
const kdPart = deaths > 0 ? `,团队 KD ${formatKd(kills / deaths)}` : '';
|
|
396
|
+
const line = `团队合计:${kills} 杀,${formatMetricNumber('damage', damage)} 伤害,${dbnos} 击倒,${assists} 助攻,${revives} 救援${kdPart}${wins > 0 ? `,吃鸡 ${wins}` : ''}`;
|
|
397
|
+
return emphasis ? `**${line}**` : line;
|
|
398
|
+
}
|
|
399
|
+
export function renderPubgStatus(presentation, options = {}) {
|
|
400
|
+
const validated = assertValid(validatePubgStatusPresentation(presentation));
|
|
401
|
+
const lines = [userText(validated.headline), ''];
|
|
402
|
+
const status = statusLine(validated.status);
|
|
403
|
+
if (status)
|
|
404
|
+
lines.push(status, '');
|
|
405
|
+
lines.push(userText(validated.message));
|
|
406
|
+
return lines.concat(footer(validated, options)).join('\n');
|
|
407
|
+
}
|
|
408
|
+
export function renderPubgStats(presentation, options = {}) {
|
|
409
|
+
const validated = assertValid(validatePubgStatsPresentation(presentation));
|
|
410
|
+
const emphasis = options.chatEmphasis === true;
|
|
411
|
+
const localized = options.localizedMetrics === true || emphasis;
|
|
412
|
+
const titles = localized ? assignStatTitles(validated.rows) : new Map();
|
|
413
|
+
const lines = [
|
|
414
|
+
emphasis
|
|
415
|
+
? `🏆 ${chatHeadline(validated.headline, validated.sourceRange, options)}`
|
|
416
|
+
: userText(validated.headline),
|
|
417
|
+
'',
|
|
418
|
+
userText(validated.summary),
|
|
419
|
+
];
|
|
420
|
+
if (validated.rows.length) {
|
|
421
|
+
if (emphasis) {
|
|
422
|
+
// Medals rank by K/D (ties: kills, then damage), whatever order the query asked for.
|
|
423
|
+
const metric = (row, key) => numericMetric(row.values[key] ?? null) ?? -1;
|
|
424
|
+
const ranked = validated.rows
|
|
425
|
+
.map((row, index) => ({
|
|
426
|
+
row,
|
|
427
|
+
titles: titles.get(index) ?? [],
|
|
428
|
+
kd: metric(row, 'kd'),
|
|
429
|
+
kills: metric(row, 'kills'),
|
|
430
|
+
damage: metric(row, 'damage'),
|
|
431
|
+
}))
|
|
432
|
+
.sort((a, b) => b.kd - a.kd || b.kills - a.kills || b.damage - a.damage);
|
|
433
|
+
ranked.forEach((entry, place) => lines.push('', ...chatPlayerBlock(entry.row, place, entry.titles)));
|
|
434
|
+
}
|
|
435
|
+
else {
|
|
436
|
+
lines.push('', ...validated.rows.map((row, index) => metricRow(row, localized, titles.get(index) ?? [], false)));
|
|
437
|
+
}
|
|
438
|
+
if (localized) {
|
|
439
|
+
const totals = teamTotalsLine(validated.rows, emphasis);
|
|
440
|
+
if (totals)
|
|
441
|
+
lines.push('', totals);
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
return lines.concat(footer(validated, options)).join('\n');
|
|
445
|
+
}
|
|
446
|
+
const MODE_NAMES = {
|
|
447
|
+
squad: '四排',
|
|
448
|
+
'squad-fpp': '四排第一人称',
|
|
449
|
+
duo: '双排',
|
|
450
|
+
'duo-fpp': '双排第一人称',
|
|
451
|
+
solo: '单排',
|
|
452
|
+
'solo-fpp': '单排第一人称',
|
|
453
|
+
};
|
|
454
|
+
/** "SG_LabmemNo004 击杀0 伤害27.903175" → "SG_LabmemNo004 0 杀 27.9 伤害". */
|
|
455
|
+
function chatMatchSummary(summary) {
|
|
456
|
+
return userText(summary).replace(/击杀(\d+)\s*伤害(\d+(?:\.\d+)?)/gu, (_all, kills, damage) => `${kills} 杀 ${formatMetricNumber('damage', Number(damage))} 伤害`);
|
|
457
|
+
}
|
|
458
|
+
function renderChatMatchList(presentation, options) {
|
|
459
|
+
const day = dayLabel(presentation.sourceRange, options);
|
|
460
|
+
const modes = new Set(presentation.matches.map((match) => MODE_NAMES[match.gameMode] ?? match.gameMode));
|
|
461
|
+
const mode = modes.size === 1 ? [...modes][0] : '';
|
|
462
|
+
const lines = [`🗂️ ${day ? `${day} ` : ''}${mode ? `${mode}` : ''}对局列表`, ''];
|
|
463
|
+
const status = statusLine(presentation.status);
|
|
464
|
+
if (status)
|
|
465
|
+
lines.push(status, '');
|
|
466
|
+
lines.push(userText(presentation.summary));
|
|
467
|
+
presentation.matches.forEach((match, index) => {
|
|
468
|
+
const at = match.startedAt
|
|
469
|
+
? formatDisplayTime(match.startedAt, timeOptions(options))
|
|
470
|
+
: '时间未知';
|
|
471
|
+
const placement = match.placement === null
|
|
472
|
+
? '名次未知'
|
|
473
|
+
: match.placement === 1
|
|
474
|
+
? '**🏆 吃鸡**'
|
|
475
|
+
: `**#${match.placement}**`;
|
|
476
|
+
lines.push('', `${index + 1}. ${at}|${sessionMapName(match.mapName)}${mode ? '' : `|${MODE_NAMES[match.gameMode] ?? userText(match.gameMode)}`}|${placement}`, ` • ${chatMatchSummary(match.summary)}`);
|
|
477
|
+
});
|
|
478
|
+
return lines.concat(footer(presentation, options)).join('\n');
|
|
479
|
+
}
|
|
480
|
+
export function renderPubgMatchList(presentation, options = {}) {
|
|
481
|
+
const validated = assertValid(validatePubgMatchListPresentation(presentation));
|
|
482
|
+
if (options.chatEmphasis)
|
|
483
|
+
return renderChatMatchList(validated, options);
|
|
484
|
+
const lines = [userText(validated.headline), '', userText(validated.summary)];
|
|
485
|
+
if (validated.matches.length) {
|
|
486
|
+
lines.push('', '对局列表:', ...validated.matches.map((match) => {
|
|
487
|
+
const startedAt = match.startedAt
|
|
488
|
+
? formatDisplayTime(match.startedAt, timeOptions(options, { forceDate: true }))
|
|
489
|
+
: '未知';
|
|
490
|
+
return `- ${startedAt}|${userText(match.mapName)}|${userText(match.gameMode)}|第${value(match.placement)}名|${userText(match.summary)}`;
|
|
491
|
+
}));
|
|
492
|
+
}
|
|
493
|
+
return lines.concat(footer(validated, options)).join('\n');
|
|
494
|
+
}
|
|
495
|
+
export function renderPubgComparison(presentation, options = {}) {
|
|
496
|
+
const validated = assertValid(validatePubgComparisonPresentation(presentation));
|
|
497
|
+
const lines = [userText(validated.headline), '', userText(validated.summary)];
|
|
498
|
+
if (validated.rows.length)
|
|
499
|
+
lines.push('', '差值(前段 - 后段):', ...validated.rows.map((row) => metricRow(row, options.localizedMetrics === true)));
|
|
500
|
+
for (const segment of validated.segments) {
|
|
501
|
+
lines.push('', `区间:${userText(segment.label)}`);
|
|
502
|
+
if (segment.sourceRange)
|
|
503
|
+
lines.push(...sourceRangeLines(segment.sourceRange, options));
|
|
504
|
+
if (segment.rows.length)
|
|
505
|
+
lines.push(...segment.rows.map((row) => metricRow(row, options.localizedMetrics === true)));
|
|
506
|
+
}
|
|
507
|
+
return lines.concat(footer(validated, options)).join('\n');
|
|
508
|
+
}
|
|
509
|
+
export function renderPubgMatchDetail(presentation, options = {}) {
|
|
510
|
+
const validated = assertValid(validatePubgMatchDetailPresentation(presentation));
|
|
511
|
+
const startedAt = validated.startedAt
|
|
512
|
+
? formatDisplayTime(validated.startedAt, timeOptions(options, { forceDate: true }))
|
|
513
|
+
: '未知';
|
|
514
|
+
const lines = [
|
|
515
|
+
userText(validated.headline),
|
|
516
|
+
'',
|
|
517
|
+
`对局:${userText(validated.matchId)}`,
|
|
518
|
+
`开始:${startedAt}`,
|
|
519
|
+
`地图:${userText(validated.mapName)}|模式:${userText(validated.gameMode)}`,
|
|
520
|
+
`时长:${value(validated.duration)}`,
|
|
521
|
+
];
|
|
522
|
+
if (validated.players.length)
|
|
523
|
+
lines.push('', '玩家:', ...validated.players.map((player) => {
|
|
524
|
+
const entries = Object.entries(player.values).map(([key, item]) => `${userText(key)}=${value(item)}`);
|
|
525
|
+
return `- ${userText(player.label)}${entries.length ? `:${entries.join(',')}` : ''}`;
|
|
526
|
+
}));
|
|
527
|
+
return lines.concat(footer(validated, options)).join('\n');
|
|
528
|
+
}
|
|
529
|
+
export function renderPubgMatchReview(presentation, options = {}) {
|
|
530
|
+
const validated = assertValid(validatePubgMatchReviewPresentation(presentation));
|
|
531
|
+
const lines = [userText(validated.headline), ''];
|
|
532
|
+
const status = statusLine(validated.status);
|
|
533
|
+
if (status)
|
|
534
|
+
lines.push(status, '');
|
|
535
|
+
lines.push(`排名:${value(validated.overview.placement)}|击杀:${value(validated.overview.kills)}|助攻:${value(validated.overview.assists)}`, `伤害:${value(validated.overview.damage)}|倒地:${value(validated.overview.dbnos)}|救援:${value(validated.overview.revives)}`);
|
|
536
|
+
if (validated.keyMoments.length)
|
|
537
|
+
lines.push('', '关键时刻:', ...validated.keyMoments.map((item) => `- ${userText(item.text)}`));
|
|
538
|
+
if (validated.highlights.length)
|
|
539
|
+
lines.push('', '亮点:', ...validated.highlights.map((item) => `- ${userText(item.text)}`));
|
|
540
|
+
if (validated.improvements.length)
|
|
541
|
+
lines.push('', '改进:', ...validated.improvements.map((item) => `- ${userText(item.text)}`));
|
|
542
|
+
lines.push('', userText(validated.analysis));
|
|
543
|
+
return lines.concat(footer(validated, options)).join('\n');
|
|
544
|
+
}
|
|
545
|
+
export function renderPubgPeriodReview(presentation, options = {}) {
|
|
546
|
+
const validated = assertValid(validatePubgPeriodReviewPresentation(presentation));
|
|
547
|
+
const lines = [
|
|
548
|
+
validated.period.displayDate
|
|
549
|
+
? `${userText(validated.period.label)}(${userText(validated.period.displayDate)})`
|
|
550
|
+
: userText(validated.period.label),
|
|
551
|
+
'',
|
|
552
|
+
];
|
|
553
|
+
const status = statusLine(validated.status);
|
|
554
|
+
if (status)
|
|
555
|
+
lines.push(status, '');
|
|
556
|
+
lines.push(userText(validated.summary));
|
|
557
|
+
if (validated.orderedMatches.length) {
|
|
558
|
+
lines.push('', '对局顺序:', ...validated.orderedMatches.map((match) => `- ${userText(match.label)} ${match.startedAt ? `(${formatDisplayTime(match.startedAt, timeOptions(options, { forceDate: true }))})` : ''}:第${value(match.placement)}名`));
|
|
559
|
+
}
|
|
560
|
+
if (validated.highlights.length)
|
|
561
|
+
lines.push('', '亮点:', ...validated.highlights.map((item) => `- ${userText(item.text)}`));
|
|
562
|
+
if (validated.patterns.length)
|
|
563
|
+
lines.push('', '模式:', ...validated.patterns.map((item) => `- ${userText(item.text)}`));
|
|
564
|
+
lines.push('', userText(validated.analysis));
|
|
565
|
+
return lines.concat(footer(validated, options)).join('\n');
|
|
566
|
+
}
|
|
567
|
+
export function renderPubgTeamDamage(presentation, options = {}) {
|
|
568
|
+
const validated = assertValid(validatePubgTeamDamagePresentation(presentation));
|
|
569
|
+
if (options.chatEmphasis)
|
|
570
|
+
return renderTeamDamageLedger(validated, options);
|
|
571
|
+
const lines = [userText(validated.headline), '', `方向:${userText(validated.direction)}`];
|
|
572
|
+
const status = statusLine(validated.status);
|
|
573
|
+
if (status)
|
|
574
|
+
lines.push(status);
|
|
575
|
+
if (validated.source || validated.meleeKind)
|
|
576
|
+
lines.push(`筛选:${userText(validated.source ?? '全部')}${validated.meleeKind ? ` / ${userText(validated.meleeKind)}` : ''}`);
|
|
577
|
+
lines.push(`总次数:${value(validated.totalHitCount)}|总伤害:${value(validated.totalDamage)}`, '', userText(validated.summary));
|
|
578
|
+
if (validated.actorTotals?.length) {
|
|
579
|
+
const ranking = validated.rankingBasis === 'knownDamage' ? '已知伤害下限' : '完整伤害';
|
|
580
|
+
lines.push('', `队员汇总(按${ranking}排序):`, ...validated.actorTotals.map((total) => {
|
|
581
|
+
const damage = total.complete ? total.damage : total.knownDamage;
|
|
582
|
+
const hitCount = total.complete ? total.hitCount : total.knownHitCount;
|
|
583
|
+
return `- ${userText(total.actor)}:${total.complete ? '' : '已知至少 '}${value(damage)} 伤害 / ${value(hitCount)} 次`;
|
|
584
|
+
}));
|
|
585
|
+
}
|
|
586
|
+
if (validated.directions.length)
|
|
587
|
+
lines.push('', '方向明细:', ...validated.directions.map((direction) => {
|
|
588
|
+
if (options.localizedMetrics) {
|
|
589
|
+
const damage = direction.complete
|
|
590
|
+
? direction.damage
|
|
591
|
+
: (direction.knownDamage ?? direction.damage);
|
|
592
|
+
const hitCount = direction.complete
|
|
593
|
+
? direction.hitCount
|
|
594
|
+
: (direction.knownHitCount ?? direction.hitCount);
|
|
595
|
+
return `- ${userText(direction.actor)} → ${userText(direction.victim)}:${direction.complete ? '' : '已知至少 '}${value(damage)} 伤害 / ${value(hitCount)} 次${direction.complete ? '' : '(不完整)'}`;
|
|
596
|
+
}
|
|
597
|
+
return `- ${userText(direction.actor)} → ${userText(direction.victim)}:${value(direction.hitCount)} 次,${value(direction.damage)} 伤害${direction.complete ? '' : '(不完整)'}`;
|
|
598
|
+
}));
|
|
599
|
+
return lines.concat(footer(validated, options)).join('\n');
|
|
600
|
+
}
|
|
601
|
+
export function formatPubgSourceRange(from, to, options = {}) {
|
|
602
|
+
return `数据范围:${formatDisplayRange(from, to, timeOptions(options))}`;
|
|
603
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { SessionReviewPresentation } from '../contracts/session-review.js';
|
|
2
|
+
/** Target size for a group-chat message: about one and a half phone screens. */
|
|
3
|
+
export declare const SESSION_REVIEW_MAX_CHARS = 1000;
|
|
4
|
+
export declare function sessionMapName(mapName: string): string;
|
|
5
|
+
export interface SessionReviewRenderOptions {
|
|
6
|
+
maxChars?: number;
|
|
7
|
+
}
|
|
8
|
+
declare function placement(rank: number | null): string;
|
|
9
|
+
export { placement as sessionPlacement, strip as sessionPlacementStrip };
|
|
10
|
+
declare function strip(placements: Array<number | null>): string;
|
|
11
|
+
/**
|
|
12
|
+
* Renders the review as WhatsApp text. When it is too long, whole sections are dropped from the least important up;
|
|
13
|
+
* the title, verdict, placements and the link always stay and nothing is cut mid-sentence.
|
|
14
|
+
*/
|
|
15
|
+
export declare function renderSessionReview(presentation: SessionReviewPresentation, options?: SessionReviewRenderOptions): string;
|