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

Choose calculation variant to calculate the code churn metric #176

Merged
merged 3 commits into from
May 19, 2021

Conversation

glato
Copy link
Contributor

@glato glato commented May 17, 2021

Hi @ishepard,

as propsed in #175 I have implemented another variant of the churn metric calculation, that can be configured in the initialization of the CodeChurn class:

def __init__(self, path_to_repo: str,
                 since=None,
                 to=None,
                 from_commit: str = None,
                 to_commit: str = None,
                 ignore_added_files=False,
                 add_deleted_lines_to_churn=False):

To ensure that this new calculation will not break anything, add_deleted_lines_to_churn is set to False per default.

The calculation variant switch is trivial:

if self.add_deleted_lines_to_churn:
        churn = modified_file.added_lines + modified_file.deleted_lines
else:
        churn = modified_file.added_lines - modified_file.deleted_lines

I've added the corresponding unit test test_with_add_deleted_lines_flag() in test_code_churn.py that proves the correct behavior of the new variant.

I've also added/modified a part of the documentation (processmetrics.rst) to include the new variant and the parameter.

I hope I haven't missed anything else.

glato added 2 commits May 17, 2021 20:36
…er, so that the churn calculation can be configured to also add removed lines
@ishepard
Copy link
Owner

ishepard commented May 18, 2021

Thanks @glato for the amazing PR! Everything looks great!
You just need to fix some flake8 errors (just run pip install flake8 && flake8) and you will be able to reproduce.

Thanks!

@glato
Copy link
Contributor Author

glato commented May 18, 2021

@ishepard Thanks for the hint, should be fine now.

@codecov
Copy link

codecov bot commented May 19, 2021

Codecov Report

Merging #176 (ed25356) into master (0e6c225) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #176   +/-   ##
=======================================
  Coverage   98.32%   98.32%           
=======================================
  Files          15       15           
  Lines        1012     1015    +3     
=======================================
+ Hits          995      998    +3     
  Misses         17       17           
Impacted Files Coverage Δ
pydriller/metrics/process/code_churn.py 100.00% <100.00%> (ø)

@ishepard ishepard merged commit f613705 into ishepard:master May 19, 2021
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.

None yet

2 participants