feat(sector-radar): add weighted scores and rank-change views
This commit is contained in:
@@ -158,7 +158,45 @@ def test_percentile_side_is_selected_before_search_and_pagination() -> None:
|
||||
|
||||
|
||||
def test_rank_change_uses_selected_metric_days_and_pool_sides() -> None:
|
||||
reader = ReadSectorRadar(_published_repository())
|
||||
from zhixing_server.modules.sector_radar.domain.persistence import (
|
||||
PublicationSourceGroup,
|
||||
PublicationSourceRecord,
|
||||
)
|
||||
from zhixing_server.modules.sector_radar.domain.source import build_source_snapshot
|
||||
|
||||
repository = _published_repository()
|
||||
dates = [date(2026, 8, day) for day in [21, 24, 25, 26, 27, 28]]
|
||||
calendar = build_source_snapshot(
|
||||
api_name="trade_cal",
|
||||
params={},
|
||||
observed_at=NOW,
|
||||
target_trade_date=TARGET_DATE,
|
||||
rows=tuple({"exchange": "SSE", "cal_date": day.isoformat(), "is_open": 1} for day in dates),
|
||||
)
|
||||
repository.save_source_snapshots((calendar,))
|
||||
repository.save_publication_sources(
|
||||
(
|
||||
PublicationSourceRecord(
|
||||
"publication-success", PublicationSourceGroup.CALENDAR, 0, calendar
|
||||
),
|
||||
)
|
||||
)
|
||||
old = _running("past-publication", dates[0])
|
||||
repository.create_publication(old)
|
||||
past = tuple(
|
||||
replace(
|
||||
row.observation,
|
||||
trade_date=dates[0],
|
||||
value=Decimal(index),
|
||||
sector_code="BK9999.DC" if index == 5 else row.observation.sector_code,
|
||||
)
|
||||
for index, row in enumerate(_amount_rankings(), 1)
|
||||
)
|
||||
repository.save_rankings(
|
||||
RankingRecord(old.publication_id, row) for row in rank_metric_observations(past)
|
||||
)
|
||||
repository.finish_publication(_finish(old, PublicationStatus.SUCCESS))
|
||||
reader = ReadSectorRadar(repository)
|
||||
query = RadarQuery(
|
||||
view=RadarView.RANK_CHANGE,
|
||||
rank_change_metric=MetricKind.AMOUNT,
|
||||
@@ -170,12 +208,14 @@ def test_rank_change_uses_selected_metric_days_and_pool_sides() -> None:
|
||||
all_rows = reader.query(query)
|
||||
|
||||
assert top.total == 1
|
||||
assert top.rows[0].rank_change(5) == 5
|
||||
assert top.rows[0].rank_change(5) == 9
|
||||
assert bottom.total == 1
|
||||
assert bottom.rows[0].rank_change(5) == -4
|
||||
assert bottom.rows[0].rank_change(5) == -9
|
||||
assert all_rows.total == 10
|
||||
assert all_rows.rows[-1].observation.sector_code == "BK0005.DC"
|
||||
assert all_rows.rows[-1].rank_change(5) is None
|
||||
assert top.comparison_trade_date == dates[0]
|
||||
assert top.rank_change_values["BK0001.DC"][MetricKind.AMOUNT] == 9
|
||||
|
||||
|
||||
def test_latest_partial_attempt_is_visible_but_does_not_replace_last_good() -> None:
|
||||
|
||||
Reference in New Issue
Block a user