Add display precision to log_diagnostics_plugin#6118
Add display precision to log_diagnostics_plugin#6118zeroacez wants to merge 13 commits intobevyengine:mainfrom
log_diagnostics_plugin#6118Conversation
…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 |
| 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.
| 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.
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! |
| } | ||
| ), | ||
| 20, | ||
| 6, // TODO: let user pick num_of_decimals |
There was a problem hiding this comment.
This should be hard set to 0: you can't load a fractional asset.
|
|
||
| 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.
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 |
| 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.
| pub num_of_decimals: DisplayPercision, // Seems like it needs to be usize | |
| pub num_of_decimals: DisplayPercision, |
|
|
||
| /// 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.
Precision, not percision :) In the docs too.
| 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.
| /// 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.
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 :) |
| 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.
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.
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.
I just added the enum. Just using a usize is how I did it to begin with.
There was a problem hiding this comment.
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.
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.
Do IntegerValue and DecimalValue(0) have different behavior?
There was a problem hiding this comment.
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.
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.
| // trait DiagnosticDisplayPercision { | |
| // type DisplayPercision; | |
| // } | |
| // impl DiagnosticDisplayPercision for Diagnostic { | |
| // type DisplayPercision = DisplayPercision; | |
| // } |
| } | ||
|
|
||
| /// 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.
| /// 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. |
| 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.
| 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.
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.
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_decimalsto the structDiagnosticand modifiedlog_diagnostics_pluginto use this variable as the display precision.