-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add display precision to log_diagnostics_plugin
#6118
Conversation
…Temp standard 6.
… display precision.
I think I have done some sort of solution to the problem but I'm a little unsure of how the |
@@ -39,6 +39,7 @@ pub struct Diagnostic { | |||
sum: f64, | |||
max_history_length: usize, | |||
pub is_enabled: bool, | |||
pub num_of_decimals: usize, // Seams like it needs to be usize |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pub num_of_decimals: usize, // Seams like it needs to be usize | |
pub num_of_decimals: usize, // Seems like it needs to be usize |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well that was a little bit embarrassing but it has been fixed now! ;)
Progress so far is great, but I'd like to see about making this user configurable before merging it. |
Thank you! |
@@ -48,6 +48,7 @@ impl<T: Asset> AssetCountDiagnosticsPlugin<T> { | |||
} | |||
), | |||
20, | |||
6, // TODO: let user pick num_of_decimals |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be hard set to 0: you can't load a fractional asset.
@@ -19,7 +19,8 @@ impl EntityCountDiagnosticsPlugin { | |||
DiagnosticId::from_u128(187513512115068938494459732780662867798); | |||
|
|||
pub fn setup_system(mut diagnostics: ResMut<Diagnostics>) { | |||
diagnostics.add(Diagnostic::new(Self::ENTITY_COUNT, "entity_count", 20)); | |||
diagnostics.add(Diagnostic::new(Self::ENTITY_COUNT, "entity_count", 20, 6)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here: fractional entities aren't a thing.
Let me take a look in earnest! So, we can already configure this when building them manually, which is great. But for the plugins, it looks like there's two kinds in play:
For 2, I'd recommend the new pattern introduced in #6360 :) |
Hey! I'm back looking at this and I don't think I really understand what you want me to do. Are you suggesting that I update the Sorry I've been busy lately but now I'm ready and hoping to get this done ASAP. |
Good questions, sorry for being unclear.
Yes: I think we can use this pattern to solve |
…ed get fuctunality for the number of decimals to be displayed.
…imals` function to display number of decimals
Ok I got some help to understand what you wanted, still a little bit unsure if this is what you were thinking about, and we came up with this solution. So now it's an enum and there is a Also we put some |
@@ -41,7 +65,7 @@ pub struct Diagnostic { | |||
ema_smoothing_factor: f64, | |||
max_history_length: usize, | |||
pub is_enabled: bool, | |||
pub num_of_decimals: usize, // Seems like it needs to be usize | |||
pub num_of_decimals: DisplayPercision, // Seems like it needs to be usize |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pub num_of_decimals: DisplayPercision, // Seems like it needs to be usize | |
pub num_of_decimals: DisplayPercision, |
@@ -28,6 +28,30 @@ pub struct DiagnosticMeasurement { | |||
pub value: f64, | |||
} | |||
|
|||
/// Enum for display percision. Choose IntergerValue for discrete values and DecimalValue(num_of_decimals) to specify the number of decimals | |||
#[derive(Debug)] | |||
pub enum DisplayPercision { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Precision, not percision :) In the docs too.
@@ -28,6 +28,30 @@ pub struct DiagnosticMeasurement { | |||
pub value: f64, | |||
} | |||
|
|||
/// Enum for display percision. Choose `IntegerValue` for discrete values and `DecimalValue(num_of_decimals)` to specify the number of decimals |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// Enum for display percision. Choose `IntegerValue` for discrete values and `DecimalValue(num_of_decimals)` to specify the number of decimals | |
/// The number of digits that should be displayed for a diagnostic. | |
/// | |
/// Choose `IntegerValue` for discrete values and `DecimalValue(num_of_decimals)` to specify the number of decimals. |
} | ||
|
||
impl DisplayPercision { | ||
pub fn get_num_of_decimals(&self) -> usize { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think num_decimals
is a perfectly clear and shorter name here :)
Good progress! This is the right direction for sure.
Unsure; let me ask for some additional eyes to help get you unstuck :) |
@@ -41,6 +65,7 @@ pub struct Diagnostic { | |||
ema_smoothing_factor: f64, | |||
max_history_length: usize, | |||
pub is_enabled: bool, | |||
pub num_of_decimals: DisplayPercision, // Seems like it needs to be usize |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the name num_of_decimals
is clunky and does not clarify its intent. I prefer the name precision
as mentioned in the original issue.
pub enum DisplayPercision { | ||
IntegerValue, | ||
DecimalValue(usize), | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why have an enum for this?
Running the code in the rust playground:
fn main() {
let x = 5.678912345;
dbg!(format!("{x:.6}"));
dbg!(format!("{x:.0}"));
}
This prints:
[src/main.rs:3] format!("{x:.6}") = "5.678912"
[src/main.rs:4] format!("{x:.0}") = "6"
I don't think an enum is necessary? You can just use 0
to print an integer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just added the enum. Just using a usize is how I did it to begin with.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm. @alice-i-cecile I have a hard time understanding why turning this into an enum is better. Can you clarify why?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Certain diagnostics will always be integer-valued: users should not be able to configure the number of decimals for them. Other diagnostics are float-like, and users may want to round to the nearest whole number.
To me, these cases are distinct (even though the same number of decimal places are shown). Representing that in the type system means that we'll be able to expose the correct controls to users later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do IntegerValue
and DecimalValue(0)
have different behavior?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not in the current version of this PR. I'll play with this by next Monday, and try to get a full design here as a PR to @zeroacez branch :)
match self { | ||
DisplayPercision::IntegerValue => 0, | ||
DisplayPercision::DecimalValue(x) => *x, | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This indicates that making an enum is redundant, as you can just use usize
directly here.
// trait DiagnosticDisplayPercision { | ||
// type DisplayPercision; | ||
// } | ||
|
||
// impl DiagnosticDisplayPercision for Diagnostic { | ||
// type DisplayPercision = DisplayPercision; | ||
// } | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// trait DiagnosticDisplayPercision { | |
// type DisplayPercision; | |
// } | |
// impl DiagnosticDisplayPercision for Diagnostic { | |
// type DisplayPercision = DisplayPercision; | |
// } |
@@ -73,11 +98,12 @@ impl Diagnostic { | |||
.push_back(DiagnosticMeasurement { time, value }); | |||
} | |||
|
|||
/// Create a new diagnostic with the given ID, name and maximum history. | |||
/// Create a new diagnostic with the given ID, name, maximum history and number of decimals. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// Create a new diagnostic with the given ID, name, maximum history and number of decimals. | |
/// Create a new diagnostic with the given ID, name, maximum history and decimal precision. |
pub fn new( | ||
id: DiagnosticId, | ||
name: impl Into<Cow<'static, str>>, | ||
max_history_length: usize, | ||
num_of_decimals: DisplayPercision, // Choose number of decimals for display precision. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
num_of_decimals: DisplayPercision, // Choose number of decimals for display precision. | |
num_of_decimals: DisplayPercision, |
…m_of_decimals` to `precision`
|
||
// trait DiagnosticDisplayPercision { | ||
// type DisplayPercision; | ||
// } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please do not leave intentionally commented out code in the codebase. If it's not meant to be included, please remove it. Otherwise, please complete the implementation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I left it in in regards to this:
Also we put some trait code in comments that we tried to use so we don't have to do any new imports but it didn't work. Could it be done using this? Or is there maybe an other way?
But if there is no answer I'll remove it :)
Backlog cleanup: closing due to inactivity, existing issue #6033 remains. |
Objective
Fixes #6033
Solution
Added a variable
num_of_decimals
to the structDiagnostic
and modifiedlog_diagnostics_plugin
to use this variable as the display precision.