r6-data.js 1.5.4 → 1.6.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 +41 -1
- package/index.d.ts +151 -91
- package/index.js +4 -1
- package/methods/getPlayerComparisons.js +234 -0
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# r6-data.js — Complete R6 Rainbow Six Siege API Wrapper
|
|
2
2
|
|
|
3
|
-
**Rainbow Six Siege (R6) API wrapper
|
|
3
|
+
**Rainbow Six Siege (R6) API wrapper** - Get player stats, operators, maps, ranks, seasons, charms and more. Full TypeScript support included. Last updated Y10S3.3
|
|
4
4
|
|
|
5
5
|
<div align="center">
|
|
6
6
|
<p>
|
|
@@ -288,6 +288,46 @@ main();
|
|
|
288
288
|
}
|
|
289
289
|
```
|
|
290
290
|
|
|
291
|
+
## Comparing Player Statistics
|
|
292
|
+
|
|
293
|
+
The `getPlayerComparisons()` function compares Rainbow Six Siege statistics between multiple players, providing rankings and comparison metrics.
|
|
294
|
+
|
|
295
|
+
```javascript
|
|
296
|
+
const r6Info = require('r6-data.js');
|
|
297
|
+
|
|
298
|
+
async function main() {
|
|
299
|
+
try {
|
|
300
|
+
const comparison = await r6Info.getPlayerComparisons({
|
|
301
|
+
players: [
|
|
302
|
+
{ nameOnPlatform: 'Player1', platformType: 'uplay' },
|
|
303
|
+
{ nameOnPlatform: 'Player2', platformType: 'uplay' }
|
|
304
|
+
],
|
|
305
|
+
platform_families: 'pc',
|
|
306
|
+
board_id: 'ranked', // Optional
|
|
307
|
+
compareFields: ['kills', 'deaths', 'wins', 'losses'] // Optional
|
|
308
|
+
});
|
|
309
|
+
|
|
310
|
+
console.log('Comparison results:', comparison.comparison_summary.field_comparisons);
|
|
311
|
+
|
|
312
|
+
} catch (error) {
|
|
313
|
+
console.error('Error during comparison:', error.message);
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
main();
|
|
318
|
+
```
|
|
319
|
+
|
|
320
|
+
### Parameters
|
|
321
|
+
|
|
322
|
+
- `players`: (Required) Array of player objects with `nameOnPlatform` and `platformType`
|
|
323
|
+
- `platform_families`: (Required) "pc" or "console"
|
|
324
|
+
- `board_id`: (Optional) Game mode filter - "casual", "ranked", etc.
|
|
325
|
+
- `compareFields`: (Optional) Specific stats to compare (default: kills, deaths, wins, losses, etc.)
|
|
326
|
+
|
|
327
|
+
### Response
|
|
328
|
+
|
|
329
|
+
Returns comparison data with player stats, field rankings (highest/lowest/average), and metadata including success/failure counts.
|
|
330
|
+
|
|
291
331
|
## Creating Discord Webhooks for R6 Stats
|
|
292
332
|
|
|
293
333
|
The `createDiscordR6Webhook()` function allows you to send Rainbow Six Siege player statistics directly to a Discord channel using webhooks. This creates formatted embeds with player stats that can be customized with various options.
|
package/index.d.ts
CHANGED
|
@@ -1,92 +1,152 @@
|
|
|
1
|
-
// TypeScript declarations for r6-data.js (module-style, no ambient wrapper)
|
|
2
|
-
|
|
3
|
-
// ----- Types -----
|
|
4
|
-
export type PlatformType = "uplay" | "psn" | "xbl";
|
|
5
|
-
export type PlatformFamily = "pc" | "console";
|
|
6
|
-
export type BoardId = "casual" | "event" | "warmup" | "standard" | "ranked";
|
|
7
|
-
export type RankVersion = "v1" | "v2" | "v3" | "v4" | "v5" | "v6";
|
|
8
|
-
|
|
9
|
-
export interface AccountInfoParams {
|
|
10
|
-
nameOnPlatform: string;
|
|
11
|
-
platformType: PlatformType;
|
|
12
|
-
}
|
|
13
|
-
export interface PlayerStatsParams extends AccountInfoParams {
|
|
14
|
-
platform_families: PlatformFamily;
|
|
15
|
-
board_id?: BoardId;
|
|
16
|
-
}
|
|
17
|
-
export interface SeasonalStatsParams extends AccountInfoParams {}
|
|
18
|
-
|
|
19
|
-
export interface
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
export interface
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
export interface
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
}
|
|
46
|
-
export interface
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
export
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
export
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
1
|
+
// TypeScript declarations for r6-data.js (module-style, no ambient wrapper)
|
|
2
|
+
|
|
3
|
+
// ----- Types -----
|
|
4
|
+
export type PlatformType = "uplay" | "psn" | "xbl";
|
|
5
|
+
export type PlatformFamily = "pc" | "console";
|
|
6
|
+
export type BoardId = "casual" | "event" | "warmup" | "standard" | "ranked";
|
|
7
|
+
export type RankVersion = "v1" | "v2" | "v3" | "v4" | "v5" | "v6";
|
|
8
|
+
|
|
9
|
+
export interface AccountInfoParams {
|
|
10
|
+
nameOnPlatform: string;
|
|
11
|
+
platformType: PlatformType;
|
|
12
|
+
}
|
|
13
|
+
export interface PlayerStatsParams extends AccountInfoParams {
|
|
14
|
+
platform_families: PlatformFamily;
|
|
15
|
+
board_id?: BoardId;
|
|
16
|
+
}
|
|
17
|
+
export interface SeasonalStatsParams extends AccountInfoParams {}
|
|
18
|
+
|
|
19
|
+
export interface PlayerComparisonsParams {
|
|
20
|
+
players: Array<{
|
|
21
|
+
nameOnPlatform: string;
|
|
22
|
+
platformType: PlatformType;
|
|
23
|
+
}>;
|
|
24
|
+
platform_families: PlatformFamily;
|
|
25
|
+
board_id?: BoardId;
|
|
26
|
+
compareFields?: string[];
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface GetMapsParams {
|
|
30
|
+
name?: string; location?: string; releaseDate?: string; playlists?: string; mapReworked?: boolean;
|
|
31
|
+
}
|
|
32
|
+
export interface GetOperatorsParams {
|
|
33
|
+
name?: string; safename?: string; realname?: string; birthplace?: string; age?: number; date_of_birth?: string; season_introduced?: string;
|
|
34
|
+
}
|
|
35
|
+
export interface GetSeasonsParams {
|
|
36
|
+
name?: string; map?: string; operators?: string; weapons?: string;
|
|
37
|
+
}
|
|
38
|
+
export interface GetAttachmentParams {
|
|
39
|
+
name?: string; style?: string; rarity?: string; availability?: string;
|
|
40
|
+
}
|
|
41
|
+
export interface GetCharmsParams {
|
|
42
|
+
name?: string; collection?: string; rarity?: string; availability?: string; bundle?: string; season?: string;
|
|
43
|
+
}
|
|
44
|
+
export interface GetWeaponsParams { name?: string; }
|
|
45
|
+
export interface GetUniversalSkinsParams { name?: string; }
|
|
46
|
+
export interface GetRanksParams { version?: RankVersion; min_mmr?: number; max_mmr?: number; }
|
|
47
|
+
|
|
48
|
+
export interface SearchAllResult {
|
|
49
|
+
query: string;
|
|
50
|
+
summary: Record<string, number>;
|
|
51
|
+
results: {
|
|
52
|
+
operators: any[]; weapons: any[]; maps: any[]; seasons: any[]; charms: any[]; attachments: any[];
|
|
53
|
+
[k: string]: any;
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
export interface GameStats {
|
|
57
|
+
steam?: { concurrent?: number; estimate?: number };
|
|
58
|
+
crossPlatform?: { totalRegistered?: number; monthlyActive?: number; trendsEstimate?: number; platforms?: { pc?: number; playstation?: number; xbox?: number } };
|
|
59
|
+
ubisoft?: { onlineEstimate?: number };
|
|
60
|
+
lastUpdated?: string;
|
|
61
|
+
[k: string]: any;
|
|
62
|
+
}
|
|
63
|
+
export interface DiscordWebhookOptions {
|
|
64
|
+
playerName: string; title?: string; message?: string; color?: number; avatarUrl?: string;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export interface PlayerComparisonsResult {
|
|
68
|
+
players: Array<{
|
|
69
|
+
player: {
|
|
70
|
+
nameOnPlatform: string;
|
|
71
|
+
platformType: PlatformType;
|
|
72
|
+
};
|
|
73
|
+
stats: any;
|
|
74
|
+
success: boolean;
|
|
75
|
+
error?: string;
|
|
76
|
+
}>;
|
|
77
|
+
comparison_summary: {
|
|
78
|
+
field_comparisons: Record<string, {
|
|
79
|
+
rankings: Array<{
|
|
80
|
+
player: string;
|
|
81
|
+
value: number;
|
|
82
|
+
platform: PlatformType;
|
|
83
|
+
}>;
|
|
84
|
+
highest: {
|
|
85
|
+
player: string;
|
|
86
|
+
value: number;
|
|
87
|
+
platform: PlatformType;
|
|
88
|
+
};
|
|
89
|
+
lowest: {
|
|
90
|
+
player: string;
|
|
91
|
+
value: number;
|
|
92
|
+
platform: PlatformType;
|
|
93
|
+
};
|
|
94
|
+
average: number;
|
|
95
|
+
}>;
|
|
96
|
+
rankings: Record<string, any>;
|
|
97
|
+
};
|
|
98
|
+
metadata: {
|
|
99
|
+
total_players: number;
|
|
100
|
+
successful_fetches: number;
|
|
101
|
+
failed_fetches: number;
|
|
102
|
+
platform_families: PlatformFamily;
|
|
103
|
+
board_id: string;
|
|
104
|
+
timestamp: string;
|
|
105
|
+
};
|
|
106
|
+
errors?: Array<{
|
|
107
|
+
player: {
|
|
108
|
+
nameOnPlatform: string;
|
|
109
|
+
platformType: PlatformType;
|
|
110
|
+
};
|
|
111
|
+
error: string;
|
|
112
|
+
}>;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// ----- Function declarations -----
|
|
116
|
+
export function getAccountInfo(params: AccountInfoParams): Promise<any>;
|
|
117
|
+
export function getPlayerStats(params: PlayerStatsParams): Promise<any>;
|
|
118
|
+
export function getSeasonalStats(params: SeasonalStatsParams): Promise<any>;
|
|
119
|
+
export function getServiceStatus(): Promise<any>;
|
|
120
|
+
export function getGameStats(): Promise<GameStats>;
|
|
121
|
+
export function getMaps(params?: GetMapsParams): Promise<any[]>;
|
|
122
|
+
export function getOperators(params?: GetOperatorsParams): Promise<any[]>;
|
|
123
|
+
export function getSeasons(params?: GetSeasonsParams): Promise<any[]>;
|
|
124
|
+
export function getAttachment(params?: GetAttachmentParams): Promise<any[]>;
|
|
125
|
+
export function getCharms(params?: GetCharmsParams): Promise<any[]>;
|
|
126
|
+
export function getWeapons(params?: GetWeaponsParams): Promise<any[]>;
|
|
127
|
+
export function getUniversalSkins(params?: GetUniversalSkinsParams): Promise<any[]>;
|
|
128
|
+
export function getRanks(params?: GetRanksParams): Promise<any[]>;
|
|
129
|
+
export function getSearchAll(query: string): Promise<SearchAllResult>;
|
|
130
|
+
export function createDiscordR6Webhook(webhookUrl: string, playerData: any, options: DiscordWebhookOptions): Promise<any>;
|
|
131
|
+
export function getPlayerComparisons(params: PlayerComparisonsParams): Promise<PlayerComparisonsResult>;
|
|
132
|
+
|
|
133
|
+
// ----- Default export -----
|
|
134
|
+
declare const r6Data: {
|
|
135
|
+
getAccountInfo: typeof getAccountInfo;
|
|
136
|
+
getPlayerStats: typeof getPlayerStats;
|
|
137
|
+
getSeasonalStats: typeof getSeasonalStats;
|
|
138
|
+
getServiceStatus: typeof getServiceStatus;
|
|
139
|
+
getGameStats: typeof getGameStats;
|
|
140
|
+
getMaps: typeof getMaps;
|
|
141
|
+
getOperators: typeof getOperators;
|
|
142
|
+
getSeasons: typeof getSeasons;
|
|
143
|
+
getAttachment: typeof getAttachment;
|
|
144
|
+
getCharms: typeof getCharms;
|
|
145
|
+
getWeapons: typeof getWeapons;
|
|
146
|
+
getUniversalSkins: typeof getUniversalSkins;
|
|
147
|
+
getRanks: typeof getRanks;
|
|
148
|
+
getSearchAll: typeof getSearchAll;
|
|
149
|
+
createDiscordR6Webhook: typeof createDiscordR6Webhook;
|
|
150
|
+
getPlayerComparisons: typeof getPlayerComparisons;
|
|
151
|
+
};
|
|
92
152
|
export default r6Data;
|
package/index.js
CHANGED
|
@@ -13,6 +13,7 @@ const getPlayerStats = require('./methods/getPlayerStats');
|
|
|
13
13
|
const createDiscordR6Webhook = require('./methods/createDiscordR6Webhook');
|
|
14
14
|
const getGameStats = require('./methods/getGameStats');
|
|
15
15
|
const getSeasonalStats = require('./methods/getSeasonalStats');
|
|
16
|
+
const getPlayerComparisons = require('./methods/getPlayerComparisons');
|
|
16
17
|
|
|
17
18
|
// Export individual functions for named imports
|
|
18
19
|
module.exports = {
|
|
@@ -31,6 +32,7 @@ module.exports = {
|
|
|
31
32
|
createDiscordR6Webhook,
|
|
32
33
|
getGameStats,
|
|
33
34
|
getSeasonalStats,
|
|
35
|
+
getPlayerComparisons,
|
|
34
36
|
};
|
|
35
37
|
|
|
36
38
|
// Export individual functions as named exports for ES6 compatibility
|
|
@@ -48,4 +50,5 @@ module.exports.getAccountInfo = getAccountInfo;
|
|
|
48
50
|
module.exports.getPlayerStats = getPlayerStats;
|
|
49
51
|
module.exports.createDiscordR6Webhook = createDiscordR6Webhook;
|
|
50
52
|
module.exports.getGameStats = getGameStats;
|
|
51
|
-
module.exports.getSeasonalStats = getSeasonalStats;
|
|
53
|
+
module.exports.getSeasonalStats = getSeasonalStats;
|
|
54
|
+
module.exports.getPlayerComparisons = getPlayerComparisons;
|
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
const axiosInstance = require('../axiosInstance/axiosInstance');
|
|
2
|
+
const buildUrlAndParams = require('./util');
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Compare Rainbow Six Siege player statistics between multiple players
|
|
6
|
+
* @param {Object} params - Parameters for the request
|
|
7
|
+
* @param {Array<Object>} params.players - Array of player objects to compare
|
|
8
|
+
* @param {string} params.players[].nameOnPlatform - Player name on the platform
|
|
9
|
+
* @param {string} params.players[].platformType - Platform type (uplay, psn, xbl)
|
|
10
|
+
* @param {string} params.platform_families - Platform families: "pc" or "console"
|
|
11
|
+
* @param {string} [params.board_id] - Game mode to filter stats (casual, event, warmup, standard, ranked)
|
|
12
|
+
* @param {Array<string>} [params.compareFields] - Specific fields to compare (e.g., ['kills', 'deaths', 'wins', 'losses'])
|
|
13
|
+
* @returns {Promise<Object>} - Comparison results with player statistics and comparison metrics
|
|
14
|
+
*/
|
|
15
|
+
async function getPlayerComparisons({ players, platform_families, board_id, compareFields } = {}) {
|
|
16
|
+
try {
|
|
17
|
+
// Validate required parameters
|
|
18
|
+
if (!players || !Array.isArray(players) || players.length < 2) {
|
|
19
|
+
throw new Error('At least 2 players are required for comparison');
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
if (!platform_families) {
|
|
23
|
+
throw new Error('Missing required parameter: platform_families');
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// Validate each player object
|
|
27
|
+
for (let i = 0; i < players.length; i++) {
|
|
28
|
+
const player = players[i];
|
|
29
|
+
if (!player.nameOnPlatform || !player.platformType) {
|
|
30
|
+
throw new Error(`Player ${i + 1} is missing required fields: nameOnPlatform, platformType`);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// Validate board_id if provided
|
|
35
|
+
if (board_id && !['casual', 'event', 'warmup', 'standard', 'ranked'].includes(board_id)) {
|
|
36
|
+
throw new Error('Invalid board_id. Must be one of: casual, event, warmup, standard, ranked');
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// Fetch stats for each player
|
|
40
|
+
const playerStats = [];
|
|
41
|
+
const errors = [];
|
|
42
|
+
|
|
43
|
+
for (const player of players) {
|
|
44
|
+
try {
|
|
45
|
+
const params = {
|
|
46
|
+
type: 'stats',
|
|
47
|
+
nameOnPlatform: player.nameOnPlatform,
|
|
48
|
+
platformType: player.platformType,
|
|
49
|
+
platform_families
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
if (board_id) {
|
|
53
|
+
params.board_id = board_id;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const url = buildUrlAndParams('/stats', params);
|
|
57
|
+
const response = await axiosInstance.get(url);
|
|
58
|
+
|
|
59
|
+
if (response.data &&
|
|
60
|
+
response.data.platform_families_full_profiles &&
|
|
61
|
+
response.data.platform_families_full_profiles.length > 0) {
|
|
62
|
+
|
|
63
|
+
// Filter by board_id if specified
|
|
64
|
+
if (board_id && response.data.platform_families_full_profiles) {
|
|
65
|
+
response.data.platform_families_full_profiles.forEach(profile => {
|
|
66
|
+
if (profile.board_ids_full_profiles) {
|
|
67
|
+
profile.board_ids_full_profiles = profile.board_ids_full_profiles.filter(
|
|
68
|
+
board => board.board_id === board_id
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
playerStats.push({
|
|
75
|
+
player: player,
|
|
76
|
+
stats: response.data,
|
|
77
|
+
success: true
|
|
78
|
+
});
|
|
79
|
+
} else {
|
|
80
|
+
playerStats.push({
|
|
81
|
+
player: player,
|
|
82
|
+
stats: null,
|
|
83
|
+
success: false,
|
|
84
|
+
error: 'No stats found for player'
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
} catch (error) {
|
|
88
|
+
errors.push({
|
|
89
|
+
player: player,
|
|
90
|
+
error: error.message
|
|
91
|
+
});
|
|
92
|
+
playerStats.push({
|
|
93
|
+
player: player,
|
|
94
|
+
stats: null,
|
|
95
|
+
success: false,
|
|
96
|
+
error: error.message
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// Generate comparison results
|
|
102
|
+
const comparison = {
|
|
103
|
+
players: playerStats,
|
|
104
|
+
comparison_summary: generateComparisonSummary(playerStats, compareFields),
|
|
105
|
+
metadata: {
|
|
106
|
+
total_players: players.length,
|
|
107
|
+
successful_fetches: playerStats.filter(p => p.success).length,
|
|
108
|
+
failed_fetches: playerStats.filter(p => !p.success).length,
|
|
109
|
+
platform_families,
|
|
110
|
+
board_id: board_id || 'all',
|
|
111
|
+
timestamp: new Date().toISOString()
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
if (errors.length > 0) {
|
|
116
|
+
comparison.errors = errors;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
return comparison;
|
|
120
|
+
|
|
121
|
+
} catch (error) {
|
|
122
|
+
console.error('Error during the getPlayerComparisons request:', error.message);
|
|
123
|
+
if (error.response && error.response.status === 401) {
|
|
124
|
+
throw new Error('Authentication error');
|
|
125
|
+
}
|
|
126
|
+
throw error;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Generate comparison summary between players
|
|
132
|
+
* @param {Array} playerStats - Array of player statistics
|
|
133
|
+
* @param {Array} compareFields - Fields to compare
|
|
134
|
+
* @returns {Object} - Comparison summary
|
|
135
|
+
*/
|
|
136
|
+
function generateComparisonSummary(playerStats, compareFields) {
|
|
137
|
+
const successfulStats = playerStats.filter(p => p.success && p.stats);
|
|
138
|
+
|
|
139
|
+
if (successfulStats.length < 2) {
|
|
140
|
+
return {
|
|
141
|
+
message: 'Not enough valid player data for comparison',
|
|
142
|
+
valid_players: successfulStats.length
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
const summary = {
|
|
147
|
+
field_comparisons: {},
|
|
148
|
+
rankings: {}
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
// Default fields to compare if none specified
|
|
152
|
+
const fieldsToCompare = compareFields || [
|
|
153
|
+
'kills', 'deaths', 'wins', 'losses', 'matches_played',
|
|
154
|
+
'time_played', 'headshots', 'melee_kills', 'revives'
|
|
155
|
+
];
|
|
156
|
+
|
|
157
|
+
// Extract and compare stats
|
|
158
|
+
fieldsToCompare.forEach(field => {
|
|
159
|
+
const fieldData = [];
|
|
160
|
+
|
|
161
|
+
successfulStats.forEach(playerStat => {
|
|
162
|
+
const stats = extractFieldFromStats(playerStat.stats, field);
|
|
163
|
+
if (stats !== null) {
|
|
164
|
+
fieldData.push({
|
|
165
|
+
player: playerStat.player.nameOnPlatform,
|
|
166
|
+
value: stats,
|
|
167
|
+
platform: playerStat.player.platformType
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
if (fieldData.length > 0) {
|
|
173
|
+
// Sort by value (descending)
|
|
174
|
+
fieldData.sort((a, b) => b.value - a.value);
|
|
175
|
+
|
|
176
|
+
summary.field_comparisons[field] = {
|
|
177
|
+
rankings: fieldData,
|
|
178
|
+
highest: fieldData[0],
|
|
179
|
+
lowest: fieldData[fieldData.length - 1],
|
|
180
|
+
average: fieldData.reduce((sum, item) => sum + item.value, 0) / fieldData.length
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
return summary;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* Extract a specific field value from player stats
|
|
190
|
+
* @param {Object} stats - Player statistics object
|
|
191
|
+
* @param {string} field - Field name to extract
|
|
192
|
+
* @returns {number|null} - Field value or null if not found
|
|
193
|
+
*/
|
|
194
|
+
function extractFieldFromStats(stats, field) {
|
|
195
|
+
try {
|
|
196
|
+
if (!stats.platform_families_full_profiles || stats.platform_families_full_profiles.length === 0) {
|
|
197
|
+
return null;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
const profile = stats.platform_families_full_profiles[0];
|
|
201
|
+
if (!profile.board_ids_full_profiles || profile.board_ids_full_profiles.length === 0) {
|
|
202
|
+
return null;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
const boardProfile = profile.board_ids_full_profiles[0];
|
|
206
|
+
if (!boardProfile.full_profiles || boardProfile.full_profiles.length === 0) {
|
|
207
|
+
return null;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
const fullProfile = boardProfile.full_profiles[0];
|
|
211
|
+
|
|
212
|
+
// Map common field names to actual API field names
|
|
213
|
+
const fieldMapping = {
|
|
214
|
+
'kills': 'kills',
|
|
215
|
+
'deaths': 'deaths',
|
|
216
|
+
'wins': 'wins',
|
|
217
|
+
'losses': 'losses',
|
|
218
|
+
'matches_played': 'matches_played',
|
|
219
|
+
'time_played': 'time_played',
|
|
220
|
+
'headshots': 'headshots',
|
|
221
|
+
'melee_kills': 'melee_kills',
|
|
222
|
+
'revives': 'revives'
|
|
223
|
+
};
|
|
224
|
+
|
|
225
|
+
const actualField = fieldMapping[field] || field;
|
|
226
|
+
return fullProfile[actualField] || 0;
|
|
227
|
+
|
|
228
|
+
} catch (error) {
|
|
229
|
+
console.warn(`Error extracting field ${field}:`, error.message);
|
|
230
|
+
return null;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
module.exports = getPlayerComparisons;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "r6-data.js",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.0",
|
|
4
4
|
"description": "R6 (Rainbow Six Siege) API wrapper for player stats, operators, maps, ranks, seasons, and game data. Typescript support. Last Updated Y10S3",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"module": "index.js",
|
|
@@ -59,8 +59,8 @@
|
|
|
59
59
|
"ms": "^2.1.3"
|
|
60
60
|
},
|
|
61
61
|
"devDependencies": {
|
|
62
|
-
"@types/node": "^24.
|
|
63
|
-
"eslint": "^9.
|
|
62
|
+
"@types/node": "^24.9.1",
|
|
63
|
+
"eslint": "^9.38.0",
|
|
64
64
|
"typescript": "^5.9.3"
|
|
65
65
|
}
|
|
66
66
|
}
|