Fix historical ratio values and stats profile performance regression
This commit is contained in:
@@ -378,18 +378,12 @@ def get_rcon_materialized_player_stats(
|
||||
if read_model_result is not None:
|
||||
return read_model_result
|
||||
|
||||
runtime_result = _get_rcon_materialized_player_stats_runtime(
|
||||
return _build_missing_player_period_stats_result(
|
||||
player_id=normalized_player_id,
|
||||
server_id=server_id,
|
||||
timeframe=resolved_timeframe,
|
||||
db_path=db_path,
|
||||
missing_reason=fallback_reason or "player-period-stats-unavailable",
|
||||
)
|
||||
runtime_result.setdefault("source", {})
|
||||
runtime_result["source"]["fallback_used"] = True
|
||||
runtime_result["source"]["fallback_reason"] = fallback_reason or "player-period-stats-unavailable"
|
||||
runtime_result["source"]["read_model"] = "player-period-stats"
|
||||
runtime_result["source"]["freshness"] = "runtime-fallback"
|
||||
return runtime_result
|
||||
|
||||
return _get_rcon_materialized_player_stats_runtime(
|
||||
player_id=normalized_player_id,
|
||||
@@ -1655,6 +1649,21 @@ def _build_missing_player_period_stats_result(
|
||||
"kills": 0,
|
||||
"deaths": 0,
|
||||
"teamkills": 0,
|
||||
"player_active_seconds": None,
|
||||
"player_active_minutes": None,
|
||||
"kpm": None,
|
||||
"kpm_status": "missing_active_time",
|
||||
"active_time_source": "unavailable",
|
||||
"active_time_coverage": {
|
||||
"eligible_matches": 0,
|
||||
"real_source_matches": 0,
|
||||
"observed_matches": 0,
|
||||
"total_matches_considered": 0,
|
||||
"eligible_kills": 0,
|
||||
"minimum_active_seconds": get_kpm_min_active_seconds(),
|
||||
"sources": [],
|
||||
},
|
||||
**build_external_player_profile_fields(player_id=player_id),
|
||||
"weekly_ranking": None,
|
||||
"monthly_ranking": None,
|
||||
"source": {
|
||||
|
||||
@@ -11,40 +11,22 @@ from app.rcon_historical_player_stats import (
|
||||
|
||||
|
||||
class StatsPlayerProfilePayloadTests(unittest.TestCase):
|
||||
def test_player_stats_falls_back_to_runtime_when_period_read_model_is_empty(self) -> None:
|
||||
runtime_payload = {
|
||||
"player_id": "76561198000000000",
|
||||
"player_name": "Runtime Player",
|
||||
"server_id": "all-servers",
|
||||
"timeframe": "weekly",
|
||||
"window_kind": "current-week",
|
||||
"matches_considered": 3,
|
||||
"kills": 25,
|
||||
"deaths": 12,
|
||||
"teamkills": 1,
|
||||
"weekly_ranking": {"metric": "kills", "ranking_position": 5},
|
||||
"monthly_ranking": {"metric": "kills", "ranking_position": 8},
|
||||
"source": {"primary_source": "rcon"},
|
||||
}
|
||||
with (
|
||||
patch(
|
||||
"app.rcon_historical_player_stats._get_player_period_stats_read_model",
|
||||
return_value=(None, "player-period-stats-empty"),
|
||||
),
|
||||
patch(
|
||||
"app.rcon_historical_player_stats._get_rcon_materialized_player_stats_runtime",
|
||||
return_value=runtime_payload,
|
||||
) as runtime_loader,
|
||||
def test_player_stats_returns_lightweight_missing_payload_when_period_read_model_is_empty(self) -> None:
|
||||
with patch(
|
||||
"app.rcon_historical_player_stats._get_player_period_stats_read_model",
|
||||
return_value=(None, "player-period-stats-empty"),
|
||||
):
|
||||
result = get_rcon_materialized_player_stats(
|
||||
player_id="76561198000000000",
|
||||
timeframe="weekly",
|
||||
)
|
||||
|
||||
runtime_loader.assert_called_once()
|
||||
self.assertTrue(result["source"]["fallback_used"])
|
||||
self.assertEqual(result["source"]["fallback_reason"], "player-period-stats-empty")
|
||||
self.assertEqual(result["source"]["freshness"], "runtime-fallback")
|
||||
self.assertEqual(result["matches_considered"], 0)
|
||||
self.assertEqual(result["kpm_status"], "missing_active_time")
|
||||
self.assertEqual(result["platform"], "steam")
|
||||
self.assertIn("steam", result["external_profile_links"])
|
||||
self.assertEqual(result["source"]["missing_reason"], "player-period-stats-empty")
|
||||
self.assertFalse(result["source"]["fallback_used"])
|
||||
|
||||
def test_build_stats_player_profile_payload_exposes_ready_real_kpm_and_external_links(self) -> None:
|
||||
with patch(
|
||||
|
||||
Reference in New Issue
Block a user