telemetry

This commit is contained in:
Lanta 2023-09-25 13:22:49 +02:00
parent 72708a8f2a
commit 76a4165d8a
8 changed files with 8678 additions and 882 deletions

View file

@ -39,7 +39,7 @@ $player_data = get-content "$scriptroot/../data/player_data.json" | convertfrom
$player_matches = @()
foreach ($player in $player_data) {
$lastMatches = $player.relationships.matches.data.id | Select-Object -First 5
$lastMatches = $player.relationships.matches.data.id #| Select-Object -First 10
$playermatches = @()
foreach ($match in $lastMatches) {
Write-Host "Getting match for $($player.attributes.name) match: $match "
@ -50,6 +50,8 @@ foreach ($player in $player_data) {
gameMode = $stats.data.attributes.gameMode
createdAt = $stats.data.attributes.createdAt
mapName = $stats.data.attributes.mapName
winPlace = $stats.data.attributes.winPlace
telemetry_url = ($stats.included.attributes | Where-Object {$_.name -eq 'telemetry'}).URL
}
}

71
update/matchparser.ps1 Normal file
View file

@ -0,0 +1,71 @@
function get-killstats {
param (
$player_name,
$telemetry
)
$attacks = @()
foreach ($action in $telemetry) {
if ($action.PSObject.Properties.name.contains('killer')) {
#write-output "Analyzing dBNOid $($action.dBNOId)"
$attacks += $action
}
}
$kills = $attacks | where-object { $_.killer.name -eq $player_name }
return @{
playername = $player_name
humankills = ($kills | where-object { $_.victim.accountId -notlike 'ai.*' }).count
kills = $kills.count
deaths = ($attacks | where-object { $_.victim.name -eq $player_name }).count
}
}
$all_player_matches = get-content "$scriptroot/../data/player_matches.json" | convertfrom-json -Depth 100
$killstats = @()
foreach ($player in $all_player_matches) {
$player_name = $player.playername
foreach ($match in $player.player_matches) {
write-output "Analyzing for player $player_name telemetry: $($match.telemetry_url)"
$telemetryfile = "$scriptroot/../data/telemetry_cache/$($match.telemetry_url.split("/")[-1])"
if (!(test-path -Path $telemetryfile)) {
write-output "Saving $telemetryfile"
$telemetry_content = (Invoke-WebRequest -Uri $match.telemetry_url).content
$telemetry_content | out-file $telemetryfile
$telemetry = $telemetry_content | ConvertFrom-Json
}else{
write-output "Getting from cache $telemetryfile"
$telemetry = get-content $telemetryfile | convertfrom-json
}
$killstats += get-killstats -player_name $player_name -telemetry $telemetry
}
}
$playerstats = @()
foreach ($player in $all_player_matches.playername) {
$deaths = (($killstats | where-object { $_.playername -eq $player }).deaths | Measure-Object -sum).sum
$kills = (($killstats | where-object { $_.playername -eq $player }).kills | Measure-Object -sum).sum
$humankills = (($killstats | where-object { $_.playername -eq $player }).humankills | Measure-Object -sum).sum
$playerstats += [PSCustomObject]@{
playername = $player
deaths = $deaths
kills = $kills
humankills = $humankills
matches = ($killstats | where-object { $_.playername -eq $player }).count
KD_H = $humankills / $deaths
KD_ALL = $kills / $deaths
}
}