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

Remove extension symbols count limit (#171) #172

Merged
merged 1 commit into from
May 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ install:
virtualenv:
system_site_packages: true
script:
- python3 -m unittest
- python3 -m unittest -v
3 changes: 0 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ Configuration file might contain following fields (all are optional):
```json
{
"max_domains": 10,
"max_ext_length": 10,
"max_authors": 7,
"max_plot_authors_count": 10,
"max_authors_of_months": 6,
Expand All @@ -113,8 +112,6 @@ of contributors and activity levels, to avoid showing too much or too little
information.

* `max_domains`: number of e-mail domains to show in author stats
* `max_ext_length`: max symbols count after `.` in a filename to
consider substring as a file extension
* `max_authors`: number of authors in the "top authors" table
(other authors are listed without detailed stats)
* `max_plot_authors_count`: number of authors to include in plots
Expand Down
6 changes: 2 additions & 4 deletions analysis/gitrevision.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import functools

from tools import get_file_extension
from .gitdata import RevisionData, FilesData

Expand All @@ -26,8 +24,8 @@ def size(self):
@property
def files_extensions_summary(self):
df = self.files_df[["size_bytes", "lines_count"]]
df["extension"] = self.files_df['file'].apply(functools.partial(get_file_extension, max_ext_length=6))
df["extension"] = self.files_df['file'].apply(get_file_extension)
df = df.groupby(by="extension").agg({"size_bytes": ["sum"], "lines_count": ["sum", "count"]})
df.columns = ["size_bytes", "lines_count", "files_count"]
df.reset_index()
return df
return df.sort_values(by="files_count", ascending=False)
18 changes: 12 additions & 6 deletions tools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,16 @@ def split_email_address(email_address):
return parts[0], parts[1]


def get_file_extension(git_file_path, max_ext_length=5):
filename = os.path.basename(git_file_path)
def get_file_extension(filepath: str):
assert filepath
filename = os.path.basename(filepath)
basename_parts = filename.split('.')
ext = basename_parts[1] if len(basename_parts) == 2 and basename_parts[0] else ''
if len(ext) > max_ext_length:
ext = ''
return ext
if len(basename_parts) == 1:
# 'folder/filename'-case
return filename
elif len(basename_parts) == 2 and not basename_parts[0]:
# 'folder/.filename'-case
return filename
else:
# "normal" case
return basename_parts[-1]
1 change: 0 additions & 1 deletion tools/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ def __init__(self, args_orig, **kwargs):
def _set_default_configuration(self):
self.update({
"max_domains": 10,
"max_ext_length": 10,
"max_authors": 20,
"max_plot_authors_count": 10,
"max_authors_of_months": 6,
Expand Down
Empty file added tools/tests/__init__.py
Empty file.
13 changes: 13 additions & 0 deletions tools/tests/test_tools.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import unittest

import tools


class TestTools(unittest.TestCase):

def test_get_file_extension(self):
self.assertEqual('extension', tools.get_file_extension("folder/filename.extension"))
self.assertEqual('.extension', tools.get_file_extension("folder/.extension"))
self.assertEqual('extension', tools.get_file_extension("folder/filename.suffix.extension"))
self.assertEqual('FILENAME', tools.get_file_extension("folder/FILENAME"))
self.assertEqual('extension', tools.get_file_extension("folder/.filename.suffix.extension"))