Skip to content
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 percent column #258

Closed

Conversation

BrainMaestro
Copy link

@BrainMaestro BrainMaestro commented Sep 5, 2018

Fixes #230


fn add(self, rhs: &Self) -> Self {
let mut stats = self.stats;
stats.extend(rhs.stats.clone());
Copy link
Author

Choose a reason for hiding this comment

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

The clone here is unfortunate, the only way I see around it is for stats to be Vec<Rc<Stat>>, do you have a better solution?

@BrainMaestro
Copy link
Author

I decided not to add a test for this because it was basically pointless since percentage is 100% for the individual files.

@@ -29,6 +30,8 @@ pub struct Language {
pub lines: usize,
/// A collection of statistics based on the files provide from `files`
pub stats: Vec<Stats>,
/// Total percentage of the language in the project
pub percent: usize,
Copy link
Author

Choose a reason for hiding this comment

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

would you prefer a float?

@XAMPPRocky
Copy link
Owner

Thank you for your PR! I'm sorry I should have given more guidance and said what I think the feature should be. As I didn't actually want to add a column. The way I saw this working was behind a flag. I also saw instead of and extra column I saw the output looking like below. Where it showed the absolute and relative values of each compared to the total. For the —files output they would be compared to the language.

--------------------------------------------------------
 Language                                        Files
--------------------------------------------------------
 Batch                                         1|0.29%
 C                                             1|0.29%
 Makefile                                      1|0.29%
 Markdown                                     19|5.5%
 Python                                       75|22%
 ReStructuredText                              7|2%
 Rust                                        210|61%
 Shell                                         7|2%
 TOML                                         17|5%
 Vim Script                                    2|0.58%
-------------------------------------------------------
 Total                                          340
-------------------------------------------------------

@BrainMaestro
Copy link
Author

That is indeed much better. I wasn't comfortable with the way it was implemented anyway. I'll fix

@XAMPPRocky
Copy link
Owner

@BrainMaestro Thank you for working on this, and if you have any questions don't hesitate to ask.

@BrainMaestro
Copy link
Author

See what it looks like

 Language              Files        Lines         Code     Comments       Blanks
---------------------------------------------------------------------------------
 JSON               1|23.26%         1622         1622            0            0
 Markdown           5|26.40%         1841         1841            0            0
 Rust              13|29.43%         2052         1557          207          288
 Shell              4|1.84%           128           92            8           28
 SVG                8|16.72%         1166         1126            0           40
 TOML               1|1.20%            84           69            0           15
 YAML               1|1.15%            80           60            8           12
---------------------------------------------------------------------------------
 Total                    33         6973         6367          223          383
---------------------------------------------------------------------------------

Should the total files be aligned with the files not the percentages?

@XAMPPRocky
Copy link
Owner

@BrainMaestro I think aligned with the number but I'll have to see to confirm.

@BrainMaestro
Copy link
Author

Hi @Aaronepower can you take another look at it? The output is now more inline with what you posted initially.

--------------------------------------------------------------------------------------------
 Language                         Files        Lines         Code     Comments       Blanks
--------------------------------------------------------------------------------------------
 JSON                           1|23%           1637         1637            0            0
 Markdown                       5|26%           1841         1841            0            0
 Rust                          13|29%           2078         1580          208          290
 Shell                          4|1.8%           128           92            8           28
 SVG                            8|16%           1166         1126            0           40
 TOML                           1|1.2%            84           69            0           15
 YAML                           1|1.1%            80           60            8           12
--------------------------------------------------------------------------------------------
 Total                           33             7014         6405          224          385
--------------------------------------------------------------------------------------------

I tried to reduce the noise a bit. The code isn't so great though


let percent_char_count = 5;
// don't show percentage for the total row because that would be pointless
if language.lines == total.lines {
Copy link
Owner

@XAMPPRocky XAMPPRocky Sep 17, 2018

Choose a reason for hiding this comment

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

Instead of passing in total and performing this if statement, why not call total's print_language with show_percentage as always false.

Copy link
Author

Choose a reason for hiding this comment

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

I still need to perform special formatting for total when show_percentage is true. It's so that the total number of files line up well. You can see the difference in the last two outputs I posted

Copy link
Owner

Choose a reason for hiding this comment

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

I think then that there should probably be a seperate function for printing total. Currently this implementation changes a lot of behaviour (such as moving the total around which adds additional allocations in AddAssign) which is not desired.

Copy link
Author

Choose a reason for hiding this comment

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

How would you suggest I do that?

Copy link
Owner

Choose a reason for hiding this comment

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

So I've refactored all the printing code into src/cli_utils.rs so you'll need to move your changes to that. I would suggest having a function called print_total that handles all the logic of printing out the total.

Copy link
Author

Choose a reason for hiding this comment

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

I'm not able to rework this now, so I'll pick it up again later when I can. I'll just go ahead and close the PR until then. thanks

Copy link
Owner

@XAMPPRocky XAMPPRocky Sep 21, 2018

Choose a reason for hiding this comment

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

@BrainMaestro Okay, thank you again for your PR! I'm going to take some time and write a comment on the issue detailing exact requirements so that if and when you do get back to it you'll have a much clearer sense of the task.

Copy link
Author

Choose a reason for hiding this comment

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

@Aaronepower that sounds great.

Copy link

Choose a reason for hiding this comment

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

I'm going to take some time and write a comment on the issue detailing exact requirements

Hi, was this ever written? I'm interested in trying to (re)implement this. Although I'm new to Rust and open source.

@BrainMaestro BrainMaestro deleted the add-percent-column branch September 21, 2018 20:07
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.

3 participants