Skip to main content

PowCapabilityProfile

Struct PowCapabilityProfile 

Source
pub struct PowCapabilityProfile {
    pub domain: String,
    pub target_class: TargetClass,
    pub vendor_family: VendorId,
    pub solved_count: u32,
    pub failed_count: u32,
    pub retry_count: u32,
    pub solve_latency_ms_p50: Option<u64>,
    pub solve_latency_ms_p95: Option<u64>,
    pub failure_modes: BTreeMap<PowFailureMode, u32>,
    pub observation_window_secs: u64,
    pub recorded_at_unix_secs: u64,
}
Expand description

Aggregated PoW capability profile for one (domain, target_class, vendor_family) triple.

A profile is built by merging one or more PowCapabilitySamples through PowCapabilityProfile::merge and then consumed by PowCapabilityScorer to produce a deterministic score. The profile is the unit of persistence: the store keys profiles by (domain, target_class, vendor_family) and re-uses the LRU+TTL primitive from T83’s LruTtlStore (the same primitive that backs ChallengeMemory).

§Example

use stygian_charon::pow_profile::{PowCapabilityProfile, PowCapabilitySample};
use stygian_charon::types::TargetClass;
use stygian_charon::vendor_classifier::VendorId;

let mut profile = PowCapabilityProfile::new(
    "example.com",
    TargetClass::ContentSite,
    VendorId::Cloudflare,
);
profile.merge(&PowCapabilitySample::solved(1_000, 0));
profile.merge(&PowCapabilitySample::solved(1_500, 1));
assert_eq!(profile.solved_count, 2);
assert_eq!(profile.retry_count, 1);

Fields§

§domain: String

Lower-cased host the profile was observed for.

§target_class: TargetClass

Target class the profile was observed for.

§vendor_family: VendorId

Vendor family the profile was observed for.

§solved_count: u32

Number of solved challenges inside the window.

§failed_count: u32

Number of failed challenges inside the window.

§retry_count: u32

Cumulative retry count across all attempts inside the window.

§solve_latency_ms_p50: Option<u64>

p50 solve latency in milliseconds for solved samples (median). None when no samples are present.

§solve_latency_ms_p95: Option<u64>

p95 solve latency in milliseconds for solved samples. None when fewer than the p95-eligible floor is present (see PowCapabilityProfile::merge).

§failure_modes: BTreeMap<PowFailureMode, u32>

Failure-mode histogram (mode -> count).

§observation_window_secs: u64

Width of the sampling window in seconds.

§recorded_at_unix_secs: u64

Unix epoch seconds when the profile was last updated.

Implementations§

Source§

impl PowCapabilityProfile

Source

pub fn new( domain: &str, target_class: TargetClass, vendor_family: VendorId, ) -> Self

Build a fresh, empty profile for the given key.

The observation_window_secs is seeded with DEFAULT_SAMPLE_WINDOW_SECS and recorded_at_unix_secs is seeded with the current wall-clock time (falling back to a documented zero when the clock is unavailable, so serialisation never fails).

Source

pub const fn total_attempts(&self) -> u32

Total number of attempts inside the window (solved + failed).

Source

pub fn success_rate(&self) -> f64

Solve success rate in [0.0, 1.0]. Returns 0.0 for an empty profile.

Source

pub fn average_retries(&self) -> f64

Average retries per attempt. Returns 0.0 for an empty profile.

Source

pub fn failure_severity(&self) -> f64

Failure severity in [0.0, 1.0] — a weighted average of PowFailureMode::severity_weight over the failure histogram. Returns 0.0 for a profile with no failed attempts.

Source

pub fn merge(&mut self, sample: &PowCapabilitySample)

Merge a PowCapabilitySample into the profile.

Latency p50/p95 are recomputed from the full set of solved samples (in the order they were merged) — the profile stores enough information to rebuild the samples on demand (solved count + p50/p95), so the merge is monotonic. The implementation updates recorded_at_unix_secs to the current wall-clock time so the store’s TTL semantics still apply on a read-after-merge cycle.

Source

pub fn merge_profile(&mut self, other: &Self)

Merge another PowCapabilityProfile into this one (same key assumed; the caller’s domain, target_class, and vendor_family are preserved untouched).

The merged profile keeps the larger of the two observation_window_secs values so a custom-widow profile is not silently shrunk by a merge with a default-widow one. recorded_at_unix_secs is refreshed to the current wall-clock time.

Trait Implementations§

Source§

impl Clone for PowCapabilityProfile

Source§

fn clone(&self) -> PowCapabilityProfile

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for PowCapabilityProfile

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for PowCapabilityProfile

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for PowCapabilityProfile

Source§

fn eq(&self, other: &PowCapabilityProfile) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for PowCapabilityProfile

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Eq for PowCapabilityProfile

Source§

impl StructuralPartialEq for PowCapabilityProfile

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> PolicyExt for T
where T: ?Sized,

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,