Skip to content

Commit c620a64

Browse files
unhappychoiceclaude
andcommitted
fix(scoring): correct real-time CPM calculation during pauses
- Replace calculate_real_time_result method to use elapsed_time instead of start_time.elapsed() - Fix issue where CPM would decrease during pause periods - Use actual elapsed time (excluding paused duration) for accurate metrics - Ensure real-time display matches final results consistency 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 5a345e7 commit c620a64

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/scoring/engine.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -493,24 +493,24 @@ impl ScoringEngine {
493493
}
494494

495495
/// Calculate metrics from current position during real-time typing
496-
/// This uses the same logic as the full ScoringEngine but works with current state
496+
/// This version correctly handles paused time by using the actual elapsed time
497497
pub fn calculate_real_time_result(
498498
current_position: usize,
499499
mistakes: usize,
500-
start_time: &std::time::Instant,
500+
elapsed_time: std::time::Duration,
501501
) -> StageResult {
502-
// Create temporary engine with real-time data
502+
// Create temporary engine with real-time data using correct elapsed time
503503
let mut temp_engine = ScoringEngine::new(String::new());
504-
temp_engine.start_time = Some(*start_time);
505-
temp_engine.recorded_duration = Some(start_time.elapsed());
504+
temp_engine.start_time = Some(std::time::Instant::now() - elapsed_time);
505+
temp_engine.recorded_duration = Some(elapsed_time);
506506

507507
// Simulate keystrokes for calculations
508508
for i in 0..current_position {
509509
temp_engine.keystrokes.push(Keystroke {
510510
character: 'x', // Placeholder
511511
position: i,
512512
is_correct: i < current_position.saturating_sub(mistakes),
513-
timestamp: *start_time,
513+
timestamp: temp_engine.start_time.unwrap(),
514514
});
515515
}
516516

0 commit comments

Comments
 (0)