forked from CSGOWTF/csgowtf
some more refactoring
This commit is contained in:
@@ -45,3 +45,24 @@ export const getPlayerArr = (stats, team, color) => {
|
||||
return arr
|
||||
}
|
||||
|
||||
export const constructAvatarUrl = (hash, size) => {
|
||||
const base = 'https://steamcdn-a.akamaihd.net/steamcommunity/public/images/avatars'
|
||||
const imgSize = size ? `_${size}` : ''
|
||||
const hashDir = hash.substring(0, 2)
|
||||
|
||||
return `${base}/${hashDir}/${hash}${imgSize}.jpg`
|
||||
}
|
||||
|
||||
export const GetAvgRank = (stats) => {
|
||||
let count = 0
|
||||
let fullRank = 0
|
||||
|
||||
stats.map(player => {
|
||||
if (player.rank?.old) {
|
||||
fullRank += player.rank?.old
|
||||
count += 1
|
||||
}
|
||||
})
|
||||
|
||||
return count === 0 ? 0 : Math.floor(fullRank / count)
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import {SaveLastVisitedToLocalStorage} from "./LocalStorage";
|
||||
import {GetHLTV_1} from "./HLTV";
|
||||
import {DisplayRank, LoadImage} from "./Display";
|
||||
import {GetUser, TrackMe} from "./ApiRequests";
|
||||
import {setTitle, GetWinLoss, truncate, checkStatEmpty, getPlayerArr} from "./Utils";
|
||||
import {setTitle, GetWinLoss, truncate, checkStatEmpty, getPlayerArr, constructAvatarUrl, GetAvgRank} from "./Utils";
|
||||
|
||||
export {
|
||||
FormatDate, FormatFullDuration, FormatFullDate, FormatDuration,
|
||||
@@ -13,5 +13,5 @@ export {
|
||||
GetHLTV_1,
|
||||
DisplayRank, LoadImage,
|
||||
GetUser, TrackMe,
|
||||
setTitle, GetWinLoss, truncate, checkStatEmpty, getPlayerArr
|
||||
setTitle, GetWinLoss, truncate, checkStatEmpty, getPlayerArr, constructAvatarUrl, GetAvgRank
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user