feat: rank 4K first, fall back to good 1080p
Resolution preference becomes strict tiers (step 10 000) and every size band gains a ceiling that waives bloated releases, so a 60 GB remux cannot win the top tier unattended. Movie grab, TV grab, RSS and the search deck now share one ranking key from arr-core. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
abb7e0a489
commit
cd9e8a891c
@@ -212,7 +212,8 @@ pub struct HdrRules {
|
||||
|
||||
/// One resolution's size band (`DESIGN.md` §5.5). Below the floor is a hard
|
||||
/// filter; the target is where the score peaks; above it the penalty grows
|
||||
/// with every gibibyte.
|
||||
/// with every gibibyte, and above the ceiling the release is waived rather
|
||||
/// than eligible.
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
||||
pub struct SizeBand {
|
||||
pub floor_bytes: u64,
|
||||
@@ -223,6 +224,11 @@ pub struct SizeBand {
|
||||
/// fractional type. Applied per byte over, so a partial gibibyte costs
|
||||
/// its fraction.
|
||||
pub penalty_points_per_gib_over: i32,
|
||||
/// Above this the release is bloated: automatic selection never takes
|
||||
/// it, a manual grab still can. `None` is no ceiling. It is what keeps
|
||||
/// strict resolution tiers from preferring a 60 GB 4K remux over every
|
||||
/// good 1080p (§5.4).
|
||||
pub ceiling_bytes: Option<u64>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Eq, PartialEq)]
|
||||
|
||||
@@ -256,6 +256,18 @@ impl PolicyRule for SizeRule {
|
||||
else {
|
||||
return RuleEvaluation::Unknown(RuleKind::Size);
|
||||
};
|
||||
// Bloat is never a reason to throw a release away, only a reason not
|
||||
// to pick it unattended: the ceiling waives in both phases.
|
||||
if crate::score::is_above_ceiling(
|
||||
context.policy,
|
||||
resolution,
|
||||
size,
|
||||
context.episode_count,
|
||||
context.runtime_minutes,
|
||||
) == Some(true)
|
||||
{
|
||||
return RuleEvaluation::SoftFail(Rule::Size);
|
||||
}
|
||||
match crate::score::is_below_floor(
|
||||
context.policy,
|
||||
resolution,
|
||||
@@ -700,6 +712,7 @@ mod tests {
|
||||
floor_bytes: 2 << 30,
|
||||
target_bytes: 4 << 30,
|
||||
penalty_points_per_gib_over: 600,
|
||||
ceiling_bytes: None,
|
||||
},
|
||||
)]),
|
||||
resolution_preference: vec![Resolution::R1080p],
|
||||
@@ -707,6 +720,32 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn above_the_ceiling_is_waived_and_a_pack_is_measured_per_episode() {
|
||||
let mut policy = banded_policy();
|
||||
if let Some(band) = policy.size_bands.get_mut(&Resolution::R1080p) {
|
||||
band.ceiling_bytes = Some(10 << 30);
|
||||
}
|
||||
let claims = claims(Some(ClaimedResolution::P1080), Some(ClaimedSource::Remux));
|
||||
let verdict_at = |size: u64, episodes: u32| {
|
||||
evaluate(
|
||||
&policy,
|
||||
&TitleOverrides::default(),
|
||||
&en(),
|
||||
Candidate::PreGrab(&claims),
|
||||
Some(size),
|
||||
episodes,
|
||||
0,
|
||||
)
|
||||
.verdict
|
||||
};
|
||||
|
||||
assert_eq!(verdict_at(12 << 30, 1), Verdict::Waived(Rule::Size));
|
||||
assert_eq!(verdict_at(10 << 30, 1), Verdict::Eligible);
|
||||
// Ten episodes at 3 GiB each sit well under a 10 GiB ceiling.
|
||||
assert_eq!(verdict_at(30 << 30, 10), Verdict::Eligible);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_below_floor_release_is_rejected_without_the_override() {
|
||||
let claims = claims(Some(ClaimedResolution::P1080), Some(ClaimedSource::WebDl));
|
||||
|
||||
@@ -8,7 +8,8 @@
|
||||
//! Size is scored against the band for the release's own resolution, so it
|
||||
//! says nothing about how resolutions rank against each other. That is the
|
||||
//! resolution-rank term: the policy's `resolution_preference` is ordered, and
|
||||
//! each step up it is worth a fixed number of points.
|
||||
//! each step up it is worth more than every other term together, so the list
|
||||
//! reads as tiers — 4K if there is any, otherwise the best 1080p.
|
||||
//!
|
||||
//! Below the floor is a hard filter rather than a low score, and lives in
|
||||
//! [`crate::policy::SizeRule`]: unbounded "smaller is better" would otherwise
|
||||
@@ -50,12 +51,11 @@ pub struct ScoreWeights {
|
||||
/// that already decides eligibility also decides how resolutions rank
|
||||
/// against each other.
|
||||
///
|
||||
/// Sized against the size term deliberately. With the seeded bands — 4K
|
||||
/// target 22 GiB, 60 points per gibibyte over — 300 points is five
|
||||
/// gibibytes of overshoot: a 4K release up to 27 GiB outranks an
|
||||
/// at-target 1080p, and a bloated 4K past that does not. Below its
|
||||
/// target a 4K has to be within about four gibibytes of it to win, which
|
||||
/// keeps a mud-quality 8 GiB 4K from beating a good 1080p.
|
||||
/// Sized to dwarf every other term, so the steps are tiers: any eligible
|
||||
/// release of a preferred resolution outranks every release of the next
|
||||
/// one, and the size, source and seeder terms only order releases inside
|
||||
/// a tier (§5.4). The size band's floor and ceiling are what keep a mud
|
||||
/// encode or a bloated remux out of the top tier, not this weight.
|
||||
pub resolution_step: i32,
|
||||
}
|
||||
|
||||
@@ -65,7 +65,7 @@ impl Default for ScoreWeights {
|
||||
size_at_target: 1000,
|
||||
source_tier: 25,
|
||||
seeder_doubling: 8,
|
||||
resolution_step: 300,
|
||||
resolution_step: 10_000,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -141,6 +141,35 @@ pub fn score(
|
||||
}
|
||||
}
|
||||
|
||||
/// Where a candidate sits in the one order every selection uses: targeted
|
||||
/// movie search, TV search, RSS and the manual-search deck. Higher score
|
||||
/// first, then lower indexer id, then guid, so the same candidates always
|
||||
/// produce the same winner whichever trigger looked at them.
|
||||
///
|
||||
/// Sorting ascending by this key puts the best candidate first.
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
||||
pub struct RankKey<'a> {
|
||||
pub score: i64,
|
||||
pub indexer_id: i64,
|
||||
pub guid: &'a str,
|
||||
}
|
||||
|
||||
impl Ord for RankKey<'_> {
|
||||
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
|
||||
other
|
||||
.score
|
||||
.cmp(&self.score)
|
||||
.then_with(|| self.indexer_id.cmp(&other.indexer_id))
|
||||
.then_with(|| self.guid.cmp(other.guid))
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialOrd for RankKey<'_> {
|
||||
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
|
||||
Some(self.cmp(other))
|
||||
}
|
||||
}
|
||||
|
||||
/// Score a stored release from the claims parsed out of its name.
|
||||
///
|
||||
/// Pre-grab, the name is all there is (`DESIGN.md` §5.6).
|
||||
@@ -185,6 +214,25 @@ pub fn is_below_floor(
|
||||
})
|
||||
}
|
||||
|
||||
/// Whether a size sits above its band's ceiling: bloated, so waived rather
|
||||
/// than eligible (`DESIGN.md` §5.4). Measured and scaled exactly as
|
||||
/// [`is_below_floor`] measures the floor.
|
||||
///
|
||||
/// `None` when the policy carries no band for that resolution, or the band
|
||||
/// carries no ceiling.
|
||||
#[must_use]
|
||||
pub fn is_above_ceiling(
|
||||
policy: &Policy,
|
||||
resolution: Resolution,
|
||||
size_bytes: u64,
|
||||
episode_count: u32,
|
||||
runtime_minutes: u32,
|
||||
) -> Option<bool> {
|
||||
let band = scaled_band(policy.size_bands.get(&resolution)?, runtime_minutes);
|
||||
band.ceiling_bytes
|
||||
.map(|ceiling| per_episode_size(size_bytes, episode_count) > ceiling)
|
||||
}
|
||||
|
||||
/// How many episodes a release's size covers (`DESIGN.md` §5.5): the divisor
|
||||
/// behind [`score`] and [`is_below_floor`].
|
||||
///
|
||||
@@ -230,6 +278,9 @@ fn scaled_band(band: &SizeBand, runtime_minutes: u32) -> SizeBand {
|
||||
floor_bytes: scale_by_runtime(band.floor_bytes, runtime_minutes),
|
||||
target_bytes: scale_by_runtime(band.target_bytes, runtime_minutes),
|
||||
penalty_points_per_gib_over: band.penalty_points_per_gib_over,
|
||||
ceiling_bytes: band
|
||||
.ceiling_bytes
|
||||
.map(|ceiling| scale_by_runtime(ceiling, runtime_minutes)),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -334,6 +385,7 @@ mod tests {
|
||||
floor_bytes: gib(8),
|
||||
target_bytes: gib(22),
|
||||
penalty_points_per_gib_over: 60,
|
||||
ceiling_bytes: None,
|
||||
},
|
||||
),
|
||||
(
|
||||
@@ -342,6 +394,7 @@ mod tests {
|
||||
floor_bytes: gib(3),
|
||||
target_bytes: gib(8),
|
||||
penalty_points_per_gib_over: 60,
|
||||
ceiling_bytes: None,
|
||||
},
|
||||
),
|
||||
]),
|
||||
@@ -456,7 +509,7 @@ mod tests {
|
||||
|
||||
// A bad score, but a score: nothing filters it out, so a selection
|
||||
// with one candidate takes it.
|
||||
assert!(scored(ClaimedSource::Remux, gib(60), 12).total < 0);
|
||||
assert!(scored(ClaimedSource::Remux, gib(60), 12).size < 0);
|
||||
assert_eq!(evaluation.verdict, Verdict::Eligible);
|
||||
}
|
||||
|
||||
@@ -548,6 +601,7 @@ mod tests {
|
||||
floor_bytes: gib(10),
|
||||
target_bytes: gib(10),
|
||||
penalty_points_per_gib_over: 60,
|
||||
ceiling_bytes: None,
|
||||
},
|
||||
);
|
||||
let claims = claims(ClaimedSource::WebDl);
|
||||
@@ -569,12 +623,16 @@ mod tests {
|
||||
assert!(uhd.total > hd.total);
|
||||
}
|
||||
|
||||
/// §5.4: 4K if there is any. Inside the band a 4K outranks every 1080p,
|
||||
/// however far over target it is and however good the 1080p.
|
||||
#[test]
|
||||
fn a_4k_far_over_target_still_loses_to_an_at_target_1080p() {
|
||||
let bloated = scored_at(ClaimedResolution::P2160, ClaimedSource::WebDl, gib(40), 20);
|
||||
let hd = scored_at(ClaimedResolution::P1080, ClaimedSource::WebDl, gib(8), 20);
|
||||
fn a_4k_far_over_target_still_outranks_an_at_target_1080p() {
|
||||
let bloated = scored_at(ClaimedResolution::P2160, ClaimedSource::WebDl, gib(40), 2);
|
||||
let mud = scored_at(ClaimedResolution::P2160, ClaimedSource::WebDl, gib(9), 2);
|
||||
let hd = scored_at(ClaimedResolution::P1080, ClaimedSource::Remux, gib(8), 4096);
|
||||
|
||||
assert!(bloated.total < hd.total);
|
||||
assert!(bloated.total > hd.total);
|
||||
assert!(mud.total > hd.total);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -644,11 +702,11 @@ mod tests {
|
||||
assert_eq!(
|
||||
at_target,
|
||||
Score {
|
||||
total: 1398,
|
||||
total: 11098,
|
||||
size: 1000,
|
||||
source: 50,
|
||||
seeders: 48,
|
||||
resolution: 300,
|
||||
resolution: 10_000,
|
||||
}
|
||||
);
|
||||
|
||||
@@ -656,11 +714,11 @@ mod tests {
|
||||
assert_eq!(
|
||||
over_target,
|
||||
Score {
|
||||
total: 918,
|
||||
total: 10618,
|
||||
size: 520,
|
||||
source: 50,
|
||||
seeders: 48,
|
||||
resolution: 300,
|
||||
resolution: 10_000,
|
||||
}
|
||||
);
|
||||
}
|
||||
@@ -774,6 +832,7 @@ mod tests {
|
||||
floor_bytes: gib(1),
|
||||
target_bytes: gib(2),
|
||||
penalty_points_per_gib_over: 60,
|
||||
ceiling_bytes: None,
|
||||
},
|
||||
);
|
||||
let episodes = 10;
|
||||
@@ -802,11 +861,11 @@ mod tests {
|
||||
assert_eq!(
|
||||
missing,
|
||||
Score {
|
||||
total: 918,
|
||||
total: 10618,
|
||||
size: 520,
|
||||
source: 50,
|
||||
seeders: 48,
|
||||
resolution: 300,
|
||||
resolution: 10_000,
|
||||
}
|
||||
);
|
||||
assert_eq!(
|
||||
@@ -881,6 +940,7 @@ mod tests {
|
||||
floor_bytes: GIB / 4,
|
||||
target_bytes: gib(2),
|
||||
penalty_points_per_gib_over: 60,
|
||||
ceiling_bytes: None,
|
||||
},
|
||||
),
|
||||
(
|
||||
@@ -889,6 +949,7 @@ mod tests {
|
||||
floor_bytes: gib(1),
|
||||
target_bytes: gib(6),
|
||||
penalty_points_per_gib_over: 60,
|
||||
ceiling_bytes: None,
|
||||
},
|
||||
),
|
||||
]),
|
||||
|
||||
Reference in New Issue
Block a user