1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
//! Defines the Comparison Generator for calculating the Best Segments of a Run.

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

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

/// The short name of this comparison. Suitable for situations where not a lot
/// of space for text is available.
pub const SHORT_NAME: &str = "Best";
/// The name of this comparison.
pub const NAME: &str = "Best Segments";

impl ComparisonGenerator for BestSegments {
    fn name(&self) -> &str {
        NAME
    }

    fn generate(&mut self, segments: &mut [Segment], _: &[Attempt]) {
        let mut real_time_predictions = vec![None; segments.len() + 1];
        let mut game_time_predictions = vec![None; segments.len() + 1];

        calculate(
            segments,
            &mut real_time_predictions,
            false,
            false,
            TimingMethod::RealTime,
        );
        calculate(
            segments,
            &mut game_time_predictions,
            false,
            false,
            TimingMethod::GameTime,
        );

        for ((segment, &real_time), &game_time) in segments
            .iter_mut()
            .zip(real_time_predictions[1..].iter())
            .zip(game_time_predictions[1..].iter())
        {
            *segment.comparison_mut(NAME) = Time::new()
                .with_real_time(real_time)
                .with_game_time(game_time);
        }
    }
}