From 7b752ab6c1729b73e52d082dc09cd9da05d83d62 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 14 Nov 2026 02:25:56 +0000 Subject: [PATCH] Count only guns toward the compare page's accuracy [patch] The compare page summed hits and shots over every weapon, but only guns record shots: a knife or Zeus hit added to the numerator with nothing in the denominator, so 20 AK hits from 100 shots plus 30 knife hits showed 50%. Hits and shots are now summed over guns only, matching LifeTracker. Fixes #93 Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_017vfJW5PUccwNk8Pndsg92E --- .../Views/CompareViewBuilder.cs | 9 +++++++-- CounterStrikeProgression.Test/CompareTests.cs | 17 +++++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/CounterStrikeProgression.Site/Views/CompareViewBuilder.cs b/CounterStrikeProgression.Site/Views/CompareViewBuilder.cs index b816944..b107ea8 100644 --- a/CounterStrikeProgression.Site/Views/CompareViewBuilder.cs +++ b/CounterStrikeProgression.Site/Views/CompareViewBuilder.cs @@ -6,6 +6,7 @@ namespace ktsu.CounterStrikeProgression.Site.Views; using ktsu.CounterStrikeProgression.Core.Challenges; using ktsu.CounterStrikeProgression.Core.Progression; using ktsu.CounterStrikeProgression.Core.SkillShots; +using ktsu.CounterStrikeProgression.Core.Weapons; /// One player's totals on the compare page. /// The 64-bit Steam ID as a decimal string. @@ -126,8 +127,12 @@ private static CompareSide Side(PlayerProgress progress, PlayerView view, Player { long kills = progress.Weapons.Values.Sum(w => w.Kills); long headshots = progress.Weapons.Values.Sum(w => w.Headshots); - long hits = progress.Weapons.Values.Sum(w => w.Hits); - long shots = progress.Weapons.Values.Sum(w => w.Shots); + + // Only guns record shots, so knife and Zeus hits would raise accuracy with nothing to divide + // them by. Count hits and shots over guns alone, as LifeTracker does for a life's accuracy. + List guns = [.. progress.Weapons.Where(w => WeaponCatalog.Find(w.Key)?.IsGun == true).Select(w => w.Value)]; + long hits = guns.Sum(w => w.Hits); + long shots = guns.Sum(w => w.Shots); return new( view.SteamId, view.Name, diff --git a/CounterStrikeProgression.Test/CompareTests.cs b/CounterStrikeProgression.Test/CompareTests.cs index ac8ffae..c74970a 100644 --- a/CounterStrikeProgression.Test/CompareTests.cs +++ b/CounterStrikeProgression.Test/CompareTests.cs @@ -77,6 +77,23 @@ public void Build_TotalsEachPlayerAcrossWeapons() Assert.AreEqual(75, view.B.Accuracy); } + [TestMethod] + public void Build_AccuracyCountsOnlyGunsBecauseKnifeAndZeusRecordNoShots() + { + PlayerProgress player = Shooter(); + WeaponProgress knife = player.Weapon(TestHelpers.Weapon("knife").Key); + knife.Kills = 4; + knife.Hits = 30; + WeaponProgress taser = player.Weapon(TestHelpers.Weapon("taser").Key); + taser.Kills = 1; + taser.Hits = 1; + + CompareView view = CompareViewBuilder.Build(player, true, NoSeason, Sniper(), false, NoSeason, new ProgressionSettings()); + + Assert.AreEqual(50, view.A.Accuracy, "Knife and Zeus hits, which never record a shot, raised the gun accuracy."); + Assert.AreEqual(15, view.A.Kills, "Knife and Zeus kills still count toward the kill total."); + } + [TestMethod] public void Build_ListsEveryWeaponEitherPlayerUsed() {