From e5334c6344c201b2ecf424f75b31d3bb5a11f637 Mon Sep 17 00:00:00 2001 From: Thijs Stobbelaar Date: Wed, 22 Nov 2023 08:49:35 +0100 Subject: [PATCH] lock improvement --- discord/report_to_discord.ps1 | 4 ++-- includes/ps1/lockfile.ps1 | 7 ++----- update/get_matches.ps1 | 5 ++++- update/matchparser.ps1 | 12 +++++------- update/update_clan.ps1 | 5 +---- 5 files changed, 14 insertions(+), 19 deletions(-) diff --git a/discord/report_to_discord.ps1 b/discord/report_to_discord.ps1 index c738e0c..c72c8eb 100644 --- a/discord/report_to_discord.ps1 +++ b/discord/report_to_discord.ps1 @@ -59,10 +59,10 @@ $content = " Hey toppers! -Laten we eens duiken in de cijfers van onze supergamers van de afgelopen twee weken: +Laten we eens duiken in de cijfers van onze supergamers van de afgelopen maand: :dart: Meeste Kills: -Hats off voor **$($most_kills['name'])**! Met **$($most_kills['stat'])** kills is hij/zij onze scherpschutter van de week! +Hats off voor **$($most_kills['name'])**! Met **$($most_kills['stat'])** kills is hij/zij onze scherpschutter van de maand! :skull_crossbones: Meeste Deaths: Oei, oei, oei... **$($most_deaths['name'])** is helaas het vaakst naar het hiernamaals gestuurd met **$($most_deaths['stat'])** deaths. Kop op, volgende keer beter! diff --git a/includes/ps1/lockfile.ps1 b/includes/ps1/lockfile.ps1 index 2e6cc83..5804ae4 100644 --- a/includes/ps1/lockfile.ps1 +++ b/includes/ps1/lockfile.ps1 @@ -22,7 +22,8 @@ function new-lock { } else { try { - New-Item -ItemType File -Path $lockFile | Out-Null + $content = if ($by) { $by } else { "" } + New-Item -ItemType File -Path $lockFile -Value $content $lock = $false } catch { @@ -36,10 +37,6 @@ function new-lock { } $i++ } - if ($by) { - $by | Out-File -FilePath $lockFile -Append - } - } function remove-lock { Write-Output 'Removing lock' diff --git a/update/get_matches.ps1 b/update/get_matches.ps1 index 832c312..376ab26 100644 --- a/update/get_matches.ps1 +++ b/update/get_matches.ps1 @@ -1,3 +1,5 @@ +Start-Transcript -Path '/var/log/dtch/get_matches.log' -Append + if ($PSScriptRoot.length -eq 0) { $scriptroot = Get-Location } @@ -90,4 +92,5 @@ $playermatches += [PSCustomObject]@{ $player_matches | convertto-json -Depth 100 | out-file "$scriptroot/../data/player_matches.json" -remove-lock \ No newline at end of file +remove-lock +Stop-Transcript \ No newline at end of file diff --git a/update/matchparser.ps1 b/update/matchparser.ps1 index b87c86c..c1f8eca 100644 --- a/update/matchparser.ps1 +++ b/update/matchparser.ps1 @@ -45,13 +45,9 @@ function get-killstats { $matchType, $gameMode ) - $attacks = @() - foreach ($action in $telemetry) { - $attacks += $action - - } - $kills = $attacks | where-object { $_.killer.name -eq $player_name } + $kills = $telemetry | where-object { $_.killer.name -eq $player_name -and $_._T -eq 'LOGPLAYERKILLV2'} + $HumanDmg = $([math]::Round(($telemetry | Where-Object { $_._T -eq 'LOGPLAYERTAKEDAMAGE' -and $_.attacker.name -eq $player_name -and $_.victim.accountId -notlike "ai.*" -and $_.victim.teamId -ne $_.attacker.teamId } | Measure-Object -Property damage -Sum).Sum)) return @{ playername = $player_name humankills = ($kills | where-object { $_.victim.accountId -notlike 'ai.*' }).count @@ -60,6 +56,8 @@ function get-killstats { gameMode = $gameMode matchType = $matchType dbno = ($attacks | where-object { $_.dBNOMaker.name -eq $player_name }).count + HumanDmg = $HumanDmg + } } @@ -119,7 +117,7 @@ foreach ($player in $all_player_matches) { } write-output "Analyzing for player $player_name telemetry: $($match.telemetry_url)" - $killstat = get-killstats -player_name $player_name -telemetry ($telemetry | where-object { $_._T -eq 'LOGPLAYERKILLV2' }) -gameMode $match.gameMode -matchType $match.matchType + $killstat = get-killstats -player_name $player_name -telemetry ($telemetry | where-object { ($_._T -eq 'LOGPLAYERTAKEDAMAGE') -or ($_._T -eq 'LOGPLAYERKILLV2') }) -gameMode $match.gameMode -matchType $match.matchType $savekillstats = @{ diff --git a/update/update_clan.ps1 b/update/update_clan.ps1 index 7573ee0..17d4756 100644 --- a/update/update_clan.ps1 +++ b/update/update_clan.ps1 @@ -1,7 +1,4 @@ - - - -if($PSScriptRoot.length -eq 0){ +if($PSScriptRoot.length -eq 0){ $scriptroot = Get-Location }else{ $scriptroot = $PSScriptRoot