Skip to content

Conversation

@mhovd
Copy link
Collaborator

@mhovd mhovd commented Jan 14, 2026

No description provided.

Copilot AI review requested due to automatic review settings January 14, 2026 09:26
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR aims to consolidate index conversion from 1-indexed to 0-indexed at the Pmetrics parser level rather than during event conversion. The Pmetrics format uses 1-indexed values for compartment and equation indices, while the internal representation uses 0-indexed values.

Changes:

  • Removed index conversion logic from row.rs for outeq and input fields
  • Added 0-indexing conversion for outeq in the Pmetrics parser
  • Simplified variable naming by removing _0indexed suffix

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
src/data/row.rs Removed .saturating_sub(1) calls that converted indices from 1-indexed to 0-indexed during event creation, and removed _0indexed variable name suffix
src/data/parser/pmetrics.rs Added .saturating_sub(1) conversion for outeq field when reading Pmetrics format

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

.out
.and_then(|v| if v == -99.0 { None } else { Some(v) }),
outeq: self.outeq,
outeq: self.outeq.map(|v| v.saturating_sub(1)),
Copy link

Copilot AI Jan 14, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The input field should also be converted from 1-indexed to 0-indexed when reading Pmetrics format, similar to how outeq is now being converted on line 142. The Pmetrics format uses 1-indexed values for both fields (as evidenced by the write_pmetrics method at lines 341 and 362 that adds 1 to both when writing), but the internal representation is 0-indexed. The conversion for input was removed from row.rs but not added here in the parser, which will cause incorrect compartment indexing. Line 137 should be changed to: input: self.input.map(|v| v.saturating_sub(1))

Copilot uses AI. Check for mistakes.
time: self.time,
})?
.saturating_sub(1), // Convert 1-indexed to 0-indexed
})?, // Convert 1-indexed to 0-indexed
Copy link

Copilot AI Jan 14, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment "Convert 1-indexed to 0-indexed" is now outdated and misleading since the conversion has been moved to the Pmetrics parser. This comment should be removed as the DataRow now expects to receive already 0-indexed values.

Suggested change
})?, // Convert 1-indexed to 0-indexed
})?,

Copilot uses AI. Check for mistakes.
Comment on lines +198 to +201
let input = self.input.ok_or_else(|| DataError::MissingBolusInput {
id: self.id.clone(),
time: self.time,
})?;
Copy link

Copilot AI Jan 14, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The DataRow builder API is documented to accept 1-indexed values for input (see lines 369-372) and convert them internally, but this conversion was removed. This breaks the builder API contract. Either the conversion must be restored in the builder (by having the builder itself convert to 0-indexed before storing in DataRow), or the builder's documentation and all its usage must be updated to reflect that it now expects 0-indexed values. Given that the PR doesn't update documentation or usages, the likely intent is to restore the conversion. The conversion should happen in the builder's input() method at line 374, changing it to: self.row.input = Some(input.saturating_sub(1));

Suggested change
let input = self.input.ok_or_else(|| DataError::MissingBolusInput {
id: self.id.clone(),
time: self.time,
})?;
// Convert 1-indexed input (Pmetrics convention) to 0-indexed internally
let input = self
.input
.map(|i| i.saturating_sub(1))
.ok_or_else(|| DataError::MissingBolusInput {
id: self.id.clone(),
time: self.time,
})?;

Copilot uses AI. Check for mistakes.
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants