Skip to content

Commit

Permalink
Adds types links to docs
Browse files Browse the repository at this point in the history
fixes total playtime
  • Loading branch information
Eein authored and CryZe committed Nov 14, 2022
1 parent 7e673df commit 78f0621
Show file tree
Hide file tree
Showing 46 changed files with 203 additions and 186 deletions.
2 changes: 1 addition & 1 deletion src/analysis/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//! The analysis module provides a variety of functions for calculating
//! information about runs.
//! information about a [`Run`](crate::run::Run).

pub mod current_pace;
pub mod delta;
Expand Down
30 changes: 16 additions & 14 deletions src/analysis/pb_chance/mod.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
//! Provides functionality to calculate the chance to beat the Personal Best for
//! either a Run or a Timer. For a Run it calculates the general chance to beat
//! the Personal Best. For a Timer the chance is calculated in terms of the
//! either a [`Run`](crate::Run) or a [`Timer`](crate::timing::Timer). For a
//! [`Run`](crate::Run) it calculates the general chance to beat the Personal Best.
//! For a [`Timer`](crate::timing::Timer) the chance is calculated in terms of the
//! current attempt. If there is no attempt in progress it yields the same
//! result as the PB chance for the Run. The value is being reported as a
//! result as the PB chance for the run. The value is being reported as a
//! floating point number in the range from 0 (0%) to 1 (100%).
//!
//! The PB chance is currently calculated with the skill curve. The PB chance is
//! the percentile at which the PB is located on the skill curve. This is also
//! where the Balanced PB would source its split times.
//! where the [`BalancedPB`](crate::comparison::balanced_pb::BalancedPB) would
//! source its split times.

use super::SkillCurve;
use crate::{comparison, timing::Snapshot, Run, Segment, TimeSpan, TimingMethod};
Expand All @@ -28,20 +30,20 @@ fn calculate(segments: &[Segment], method: TimingMethod, offset: TimeSpan) -> f6
comparison::goal::determine_percentile(offset, segments, method, None, &mut SkillCurve::new())
}

/// Calculates the PB chance for a run. No information about an active attempt
/// is used. Instead the general chance to beat the Personal Best is calculated.
/// The value is being reported as a floating point number in the range from 0
/// (0%) to 1 (100%).
/// Calculates the PB chance for a [`Run`](crate::Run). No information about
/// an active attempt is used. Instead the general chance to beat the Personal
/// Best is calculated. The value is being reported as a floating point number
/// in the range from 0 (0%) to 1 (100%).
pub fn for_run(run: &Run, method: TimingMethod) -> f64 {
calculate(run.segments(), method, TimeSpan::zero())
}

/// Calculates the PB chance for a timer. The chance is calculated in terms of
/// the current attempt. If there is no attempt in progress it yields the same
/// result as the PB chance for the run. The value is being reported as a
/// floating point number in the range from 0 (0%) to 1 (100%). Additionally a
/// boolean is returned that indicates if the value is currently actively
/// changing as time is being lost.
/// Calculates the PB chance for a [`Timer`](crate::timing::Timer). The chance
/// is calculated in terms of the current attempt. If there is no attempt in
/// progress it yields the same result as the PB chance for the run.
/// The value is being reported as a floating point number in the range
/// from 0 (0%) to 1 (100%). Additionally a boolean is returned that
/// indicates if the value is currently actively changing as time is being lost.
pub fn for_timer(timer: &Snapshot<'_>) -> (f64, bool) {
let method = timer.current_timing_method();
let all_segments = timer.run().segments();
Expand Down
17 changes: 10 additions & 7 deletions src/analysis/skill_curve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ use core::cmp::Ordering;
const WEIGHT: f64 = 0.75;
const TRIES: usize = 50;

/// The skill curve analyzes the segment history across all segments. For each
/// segment, all the segment times are sorted by length and weighted by their
/// recency. Plotting this on a graph with the y-axis representing the segment
/// time and the x-axis representing the percentile, with the shortest time at 0
/// The skill curve analyzes the [`SegmentHistory`](crate::run::SegmentHistory)
/// segment history across all segments. For each [`Segment`](crate::run::Segment),
/// the segment times are sorted by length and weighted by their recency.
///
/// Plotting this on a graph with the y-axis representing the segment time and
/// the x-axis representing the percentile, with the shortest time at 0
/// and the longest time at 1, yields the so called "skill curve". If you sum
/// all the different curves together for all the segments, you get the overall
/// curve for the whole run.
Expand All @@ -16,9 +18,10 @@ const TRIES: usize = 50;
///
/// If you sample the curve at 0, you get the simple sum of best segments, and if
/// you sample the curve at 1, you get the simple sum of worst segments. At 0.5,
/// you get the median segments. If you sample the individual segments at the same percentile where you
/// find the Personal Best on the overall run's curve, you get the Balanced PB.
/// The position of the Balanced PB on the x-axis is the PB chance.
/// you get the median segments. If you sample the individual segments at the
/// same percentile where you find the Personal Best on the overall run's curve,
/// you get the Balanced PB. The position of the Balanced PB on the x-axis is the
/// PB chance.
#[derive(Default, Clone)]
pub struct SkillCurve {
all_weighted_segment_times: Vec<Vec<(f64, TimeSpan)>>,
Expand Down
38 changes: 20 additions & 18 deletions src/analysis/state_helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ use crate::{
Timer, TimerPhase, TimingMethod,
};

/// Gets the last non-live delta in the run starting from `segment_index`.
/// Gets the last non-live delta in the [`Run`](crate::Run) starting
/// from `segment_index`.
///
/// - `run`: The current run.
/// - `run`: The current [`Run`](crate::Run).
/// - `segment_index`: The split number to start checking deltas from.
/// - `comparison`: The comparison that you are comparing with.
/// - `method`: The timing method that you are using.
/// - `method`: The [`TimingMethod`](crate::timing::TimingMethod) that you are using.
///
/// Returns the last non-live delta or None if there have been no deltas yet.
pub fn last_delta(
Expand Down Expand Up @@ -156,10 +157,10 @@ fn segment_time(

/// Gets the length of the last segment that leads up to a certain split.
///
/// - `timer`: The current timer.
/// - `timer`: The current [`Timer`](crate::timing::Timer).
/// - `segment_index`: The index of the split that represents the end of the
/// segment.
/// - `method`: The timing method that you are using.
/// - `method`: The [`TimingMethod`](crate::timing::TimingMethod) that you are using.
///
/// Returns the length of the segment leading up to `segment_index`, returning
/// None if the split is not completed yet.
Expand All @@ -180,10 +181,10 @@ pub fn previous_segment_time(
/// Gets the length of the last segment that leads up to a certain split, using
/// the live segment time if the split is not completed yet.
///
/// - `timer`: The current timer.
/// - `timer`: The current [`Timer`](crate::timing::Timer).
/// - `segment_index`: The index of the split that represents the end of the
/// segment.
/// - `method`: The timing method that you are using.
/// - `method`: The [`TimingMethod`](crate::timing::TimingMethod) that you are using.
///
/// Returns the length of the segment leading up to `segment_index`, returning
/// the live segment time if the split is not completed yet.
Expand All @@ -203,10 +204,10 @@ pub fn live_segment_time(

/// Gets the amount of time lost or gained on a certain split.
///
/// - `timer`: The current timer.
/// - `timer`: The current [`Timer`](crate::timing::Timer).
/// - `segment_index`: The index of the split for which the delta is calculated.
/// - `comparison`: The comparison that you are comparing with.
/// - `method`: The timing method that you are using.
/// - `method`: The [`TimingMethod`](crate::timing::TimingMethod) that you are using.
///
/// Returns the segment delta for a certain split, returning None if the split
/// is not completed yet.
Expand All @@ -228,10 +229,10 @@ pub fn previous_segment_delta(
/// Gets the amount of time lost or gained on a certain split, using the live
/// segment delta if the split is not completed yet.
///
/// - `timer`: The current timer.
/// - `timer`: The current [`Timer`](crate::timing::Timer).
/// - `segment_index`: The index of the split for which the delta is calculated.
/// - `comparison`: The comparison that you are comparing with.
/// - `method`: The timing method that you are using.
/// - `method`: The [`TimingMethod`](crate::timing::TimingMethod) that you are using.
///
/// Returns the segment delta for a certain split, returning the live segment
/// delta if the split is not completed yet.
Expand All @@ -252,12 +253,12 @@ pub fn live_segment_delta(

/// Checks whether the live segment should now be shown.
///
/// - `timer`: The current timer.
/// - `timer`: The current [`Timer`](crate::timing::Timer).
/// - `split_delta`: Specifies whether to return a split delta
/// rather than a segment delta and to start showing the live
/// segment once you are behind.
/// - `comparison`: The comparison that you are comparing with.
/// - `method`: The timing method that you are using.
/// - `method`: The [`TimingMethod`](crate::timing::TimingMethod) that you are using.
///
/// Returns the current live delta.
pub fn check_live_delta(
Expand Down Expand Up @@ -294,16 +295,17 @@ pub fn check_live_delta(
None
}

/// Chooses a split color from the Layout Settings based on the current run.
/// Chooses a split color from the [`LayoutSettings`](crate::layout::LayoutSettings)
/// based on the current run.
///
/// - `timer`: The current timer.
/// - `timer`: The current [`Timer`](crate::timing::Timer).
/// - `time_difference`: The delta that you want to find a color for.
/// - `segment_index`: The split number that is associated with this delta.
/// - `show_segment_deltas`: Can show ahead gaining and behind losing colors if
/// true.
/// - `show_best_segments`: Can show the best segment color if true.
/// - `comparison`: The comparison that you are comparing this delta to.
/// - `method`: The timing method of this delta.
/// - `method`: The [`TimingMethod`](crate::timing::TimingMethod) of this delta.
///
/// Returns the chosen color.
pub fn split_color(
Expand Down Expand Up @@ -340,9 +342,9 @@ pub fn split_color(
/// Calculates whether or not the Split Times for the indicated split qualify as
/// a Best Segment.
///
/// - `timer`: The current timer.
/// - `timer`: The current [`Timer`](crate::timing::Timer).
/// - `segment_index`: The split to check.
/// - `method`: The timing method to use.
/// - `method`: The [`TimingMethod`](crate::timing::TimingMethod) to use.
///
/// Returns whether or not the indicated split is a Best Segment.
pub fn check_best_segment(timer: &Timer, segment_index: usize, method: TimingMethod) -> bool {
Expand Down
43 changes: 23 additions & 20 deletions src/analysis/sum_of_segments/best.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Provides functionality for calculating the Sum of Best Segments for whole
//! runs or specific parts. The Sum of Best Segments is the fastest time
//! possible to complete a run of a category, based on information collected
//! [`Run`](crate::Run) or specific parts. The Sum of Best Segments is the fastest
//! time possible to complete a run of a category, based on information collected
//! from all the previous attempts. This often matches up with the sum of the
//! best segment times of all the segments, but that may not always be the case,
//! as skipped segments may introduce combined segments that may be faster than
Expand Down Expand Up @@ -81,24 +81,27 @@ fn populate_predictions(
}

/// Calculates the Sum of Best Segments for the timing method provided. This is
/// the fastest time possible to complete a run of a category, based on
/// information collected from all the previous attempts. This often matches up
/// with the sum of the best segment times of all the segments, but that may not
/// always be the case, as skipped segments may introduce combined segments that
/// may be faster than the actual sum of their best segment times. The name is
/// therefore a bit misleading, but sticks around for historical reasons. You
/// can choose to do a simple calculation instead, which excludes the Segment
/// History from the calculation process. If there's an active attempt, you can
/// choose to take it into account as well. This lower level function requires
/// you to provide a buffer to fill up with the shortest paths to reach each of
/// the segments. This means that the first segment will always be reached at a
/// time of 0:00. However, if you are interested in the total Sum of Best
/// Segments, then you can't look at the predictions value with the index of the
/// last segment, as that only tells you what the best time to reach that
/// segment is, not the best time to complete it. This means that the
/// predictions buffer needs to have one more element than the list of segments
/// provided, so that you can properly query the total Sum of Best Segments.
/// This value is also the value that is being returned.
/// the fastest time possible to complete a [`Run`](crate::Run) of a category,
/// based on information collected from all the previous attempts.
///
/// This often matches up with the sum of the best segment times of all the
/// segments, but that may not always be the case, as skipped segments may
/// introduce combined segments that may be faster than the actual sum of their
/// best segment times.
///
/// The name is therefore a bit misleading, but sticks around for historical
/// reasons. You can choose to do a simple calculation instead, which excludes
/// the Segment History from the calculation process. If there's an active
/// attempt, you can choose to take it into account as well. This lower level
/// function requires you to provide a buffer to fill up with the shortest
/// paths to reach each of the segments. This means that the first segment
/// will always be reached at a time of 0:00. However, if you are interested
/// in the total Sum of Best Segments, then you can't look at the predictions
/// value with the index of the last segment, as that only tells you what the
/// best time to reach that segment is, not the best time to complete it. This
/// means that the predictions buffer needs to have one more element than the
/// list of segments provided, so that you can properly query the total Sum of
/// Best Segments. This value is also the value that is being returned.
#[allow(clippy::needless_range_loop)]
pub fn calculate(
segments: &[Segment],
Expand Down
6 changes: 3 additions & 3 deletions src/analysis/sum_of_segments/worst.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Provides functionality for calculating the Sum of Worst Segments for whole
//! runs or specific parts. The Sum of Worst Segments is the slowest time
//! possible to complete a run of a category, based on information collected
//! from all the previous attempts. This obviously isn't really the worst
//! [`Run`](crate::Run) or specific parts. The Sum of Worst Segments is the
//! slowest time possible to complete a run of a category, based on information
//! collected from all the previous attempts. This obviously isn't really the worst
//! possible time, but may be useful information regardless.

use super::{track_branch, track_current_run, track_personal_best_run, Prediction};
Expand Down
12 changes: 6 additions & 6 deletions src/analysis/total_playtime.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
//! Provides functionality to calculate the total playtime for either a Run or a
//! Timer. For a Run, all the durations stored in the Attempt History are summed
//! together. For a Timer, the current attempt's duration is also factored in.
//! Provides functionality to calculate the total playtime for either a
//! [`Run`] or a [`Timer`]. For a [`Run`], all the durations stored in the attempt
//! history are summed together. For a [`Timer`], the current attempt's duration
//! is also factored in.

use crate::{Run, TimeSpan, Timer, TimingMethod};

/// Allows calculating the total playtime.
pub trait TotalPlaytime {
/// Calculates the total playtime.
Expand Down Expand Up @@ -56,8 +56,8 @@ impl<'a, T: 'a + TotalPlaytime> TotalPlaytime for &'a T {
}
}

/// Calculates the total playtime. The source can be a `Run`, `Timer` or any
/// other type that implements the `TotalPlaytime` trait.
/// Calculates the total playtime. The source can be a [`Run`], [`Timer`] or any
/// other type that implements the [`TotalPlaytime`] trait.
pub fn calculate<T: TotalPlaytime>(source: T) -> TimeSpan {
source.total_playtime()
}
6 changes: 3 additions & 3 deletions src/auto_splitting/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//! The auto splitting module provides a runtime for running auto splitters that
//! can control the timer. These auto splitters are provided as WebAssembly
//! can control the [`Timer`](crate::timing::Timer). These auto splitters are provided as WebAssembly
//! modules.
//!
//! # Requirements for the Auto Splitters
Expand Down Expand Up @@ -241,8 +241,8 @@ enum Request {
UnloadScript(oneshot::Sender<()>),
}

// This newtype is required because SharedTimer is an Arc<RwLock<T>>, so we
// can't implement the trait directly on it.
// This newtype is required because [`SharedTimer`](crate::timing::SharedTimer)
// is an Arc<RwLock<T>>, so we can't implement the trait directly on it.
struct Timer(SharedTimer);

impl AutoSplitTimer for Timer {
Expand Down
17 changes: 9 additions & 8 deletions src/comparison/average_segments.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
//! Defines the Comparison Generator for calculating the Average Segments of a
//! Run. The Average Segments are calculated through a weighted arithmetic mean
//! that gives more recent segments a larger weight so that the Average
//! Segments are more suited to represent the current performance of a
//! runner.
//! [`Run`](crate::Run). The Average Segments are calculated through a
//! weighted arithmetic mean that gives more recent segments a larger
//! weight so that the Average Segments are more suited to represent
//! the current performance of a runner.

use super::ComparisonGenerator;
use crate::{Attempt, Segment, TimeSpan, TimingMethod};

/// The Comparison Generator for calculating the Average Segments of a Run. The
/// Average Segments are calculated through a weighted arithmetic mean that
/// gives more recent segments a larger weight so that the Average Segments are
/// more suited to represent the current performance of a runner.
/// The Comparison Generator for calculating the Average Segments of a
/// [`Run`](crate::Run). The Average Segments are calculated through a weighted
/// arithmetic mean that gives more recent segments a larger weight so that
/// the Average Segments are more suited to represent the current performance
/// of a runner.
#[derive(Copy, Clone, Debug)]
pub struct AverageSegments;

Expand Down
6 changes: 4 additions & 2 deletions src/comparison/best_segments.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
//! Defines the Comparison Generator for calculating the Best Segments of a Run.
//! Defines the Comparison Generator for calculating the Best Segments of a
//! [`Run`](crate::Run).

use super::ComparisonGenerator;
use crate::{
analysis::sum_of_segments::best::calculate, platform::prelude::*, Attempt, Segment, Time,
TimingMethod,
};

/// The Comparison Generator for calculating the Best Segments of a Run.
/// Defines the Comparison Generator for calculating the Best Segments of a
/// [`Run`](crate::Run).
#[derive(Copy, Clone, Debug)]
pub struct BestSegments;

Expand Down
10 changes: 6 additions & 4 deletions src/comparison/latest_run.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//! Defines the Comparison Generator for calculating the Latest Run. Using the
//! Segment History, this comparison reconstructs the splits of the furthest,
//! Defines the Comparison Generator for calculating the Latest
//! [`Run`](crate::Run). Using the [`SegmentHistory`](crate::run::SegmentHistory),
//! this comparison reconstructs the splits of the furthest,
//! most recent attempt. If at least one attempt has been finished, this
//! comparison will show the most recent finished attempt. If no attempts have
//! been finished yet, this comparison will show the attempt that got the
Expand All @@ -8,8 +9,9 @@
use super::ComparisonGenerator;
use crate::{Attempt, Segment, TimeSpan, TimingMethod};

/// The Comparison Generator for calculating the Latest Run. Using the
/// Segment History, this comparison reconstructs the splits of the furthest,
/// Defines the Comparison Generator for calculating the Latest
/// [`Run`](crate::Run). Using the [`SegmentHistory`](crate::run::SegmentHistory),
/// this comparison reconstructs the splits of the furthest,
/// most recent attempt. If at least one attempt has been finished, this
/// comparison will show the most recent finished attempt. If no attempts have
/// been finished yet, this comparison will show the attempt that got the
Expand Down
Loading

0 comments on commit 78f0621

Please sign in to comment.