Skip to content

Commit

Permalink
Limit count of tags rendered in "tags" page (#89, #20)
Browse files Browse the repository at this point in the history
 -do not add "tags"-page tab if "max_recent_tags" is zero

- do not fetch tags if "max_recent_tags" is zero
  • Loading branch information
vifactor committed Jan 29, 2020
1 parent ab7e32c commit af7f813
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 23 deletions.
7 changes: 5 additions & 2 deletions analysis/gitstatistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def check_last_commit_stamp(cls, author: dict, time):
class GitStatistics:
is_mailmap_supported = True if version.LooseVersion(git.LIBGIT2_VERSION) >= '0.28.0' else False

def __init__(self, path, fetch_contribution=False):
def __init__(self, path, fetch_contribution=False, fetch_tags=True):
"""
:param path: path to a repository
"""
Expand Down Expand Up @@ -165,7 +165,10 @@ def mapsig(sig: git.Signature):
self.contribution = self.fetch_contributors()
else:
self.contribution = {}
self.tags = self.fetch_tags_info()
if fetch_tags:
self.tags = self.fetch_tags_info()
else:
self.tags = {}
self.domains = self.fetch_domains_info()
self.timezones = self.fetch_timezone_info()
self.first_commit_timestamp = min(commit.author.time for commit in self.repo.walk(self.repo.head.target))
Expand Down
4 changes: 3 additions & 1 deletion analysis/repostat.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ def main():

print('Git path: %s' % config.git_repository_path)
print('Collecting data...', config.do_calculate_contribution())
repository_statistics = GitStatistics(config.git_repository_path, config.do_calculate_contribution())
repository_statistics = GitStatistics(config.git_repository_path,
config.do_calculate_contribution(),
config.do_process_tags())

output_path = config.statistics_output_path
print('Output path: %s' % output_path)
Expand Down
53 changes: 34 additions & 19 deletions report/htmlreportcreator.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ def __init__(self, config: Configuration, repo_stat):
self.configuration = config
self.assets_path = os.path.join(HERE, self.assets_subdir)
self.git_repo_statistics = repo_stat
self.has_tags_page = config.do_process_tags()

self.common_rendering_data = {
"assets_path": self.assets_path,
"has_tags_page": self.has_tags_page
}

templates_dir = os.path.join(HERE, self.templates_subdir)
self.j2_env = Environment(loader=FileSystemLoader(templates_dir), trim_blocks=True)
Expand Down Expand Up @@ -65,16 +71,19 @@ def create(self, path):

if self.configuration.is_report_relocatable():
self._bundle_assets()
self.common_rendering_data.update({
"assets_path": self.assets_path
})

###
# General
general_html = self.render_general_page(None)
general_html = self.render_general_page()
with open(os.path.join(path, "general.html"), 'w', encoding='utf-8') as f:
f.write(general_html)

###
# Activity
activity_html = self.render_activity_page(None)
activity_html = self.render_activity_page()
with open(os.path.join(path, "activity.html"), 'w', encoding='utf-8') as f:
f.write(activity_html)

Expand All @@ -93,7 +102,7 @@ def create(self, path):

###
# Authors
authors_html = self.render_authors_page(None)
authors_html = self.render_authors_page()
with open(os.path.join(path, "authors.html"), 'w', encoding='utf-8') as f:
f.write(authors_html.decode('utf-8'))

Expand Down Expand Up @@ -151,7 +160,7 @@ def create(self, path):

###
# Files
files_html = self.render_files_page(None)
files_html = self.render_files_page()
with open(os.path.join(path, "files.html"), 'w', encoding='utf-8') as f:
f.write(files_html)

Expand All @@ -165,9 +174,11 @@ def create(self, path):

###
# tags.html
tags_html = self.render_tags_page(None)
with open(os.path.join(path, "tags.html"), 'w', encoding='utf-8') as f:
f.write(tags_html.decode('utf-8'))

if self.has_tags_page:
tags_html = self.render_tags_page()
with open(os.path.join(path, "tags.html"), 'w', encoding='utf-8') as f:
f.write(tags_html.decode('utf-8'))

###
# about.html
Expand All @@ -180,7 +191,7 @@ def create(self, path):
data_path=path,
output_images_path=path)

def render_general_page(self, data):
def render_general_page(self):
date_format_str = '%Y-%m-%d %H:%M'
first_commit_datetime = datetime.datetime.fromtimestamp(self.git_repo_statistics.first_commit_timestamp)
last_commit_datetime = datetime.datetime.fromtimestamp(self.git_repo_statistics.last_commit_timestamp)
Expand Down Expand Up @@ -210,11 +221,11 @@ def render_general_page(self, data):
project=project_data,
generation=generation_data,
page_title="General",
assets_path=self.assets_path
**self.common_rendering_data
)
return template_rendered

def render_activity_page(self, data):
def render_activity_page(self):
# TODO: this conversion from old 'data' to new 'project data' should perhaps be removed in future
project_data = {
'hourly_activity': [],
Expand Down Expand Up @@ -254,11 +265,11 @@ def render_activity_page(self, data):
template_rendered = self.j2_env.get_template('activity.html').render(
project=project_data,
page_title="Activity",
assets_path=self.assets_path
**self.common_rendering_data
)
return template_rendered

def render_authors_page(self, data):
def render_authors_page(self):
# TODO: this conversion from old 'data' to new 'project data' should perhaps be removed in future
project_data = {
'top_authors': [],
Expand Down Expand Up @@ -317,7 +328,8 @@ def render_authors_page(self, data):
'latest_commit_date': info['date_last'],
'contributed_days_count': info['timedelta'],
'active_days_count': len(info['active_days']),
'contribution': self.git_repo_statistics.contribution.get(author, 0) if self.git_repo_statistics.contribution else None,
'contribution': self.git_repo_statistics.contribution.get(author,
0) if self.git_repo_statistics.contribution else None,
}

project_data['top_authors'].append(author_dict)
Expand All @@ -326,11 +338,11 @@ def render_authors_page(self, data):
template_rendered = self.j2_env.get_template('authors.html').render(
project=project_data,
page_title="Authors",
assets_path=self.assets_path
**self.common_rendering_data
)
return template_rendered.encode('utf-8')

def render_files_page(self, data):
def render_files_page(self):
# TODO: this conversion from old 'data' to new 'project data' should perhaps be removed in future
project_data = {
'files_count': self.git_repo_statistics.total_files_count,
Expand All @@ -352,11 +364,11 @@ def render_files_page(self, data):
template_rendered = self.j2_env.get_template('files.html').render(
project=project_data,
page_title="Files",
assets_path=self.assets_path
**self.common_rendering_data
)
return template_rendered

def render_tags_page(self, data):
def render_tags_page(self):
# TODO: this conversion from old 'data' to new 'project data' should perhaps be removed in future
project_data = {
'tags_count': len(self.git_repo_statistics.tags),
Expand All @@ -371,6 +383,9 @@ def render_tags_page(self, data):
"""
tags_sorted_by_date_desc = sort_keys_by_value_of_key(self.git_repo_statistics.tags, 'date', reverse=True)
for tag in tags_sorted_by_date_desc:
if 'max_recent_tags' in self.configuration \
and self.configuration['max_recent_tags'] <= len(project_data['tags']):
break
# there are tags containing no commits
if 'authors' in self.git_repo_statistics.tags[tag].keys():
authordict = self.git_repo_statistics.tags[tag]['authors']
Expand All @@ -392,7 +407,7 @@ def render_tags_page(self, data):
template_rendered = self.j2_env.get_template('tags.html').render(
project=project_data,
page_title="Tags",
assets_path=self.assets_path
**self.common_rendering_data
)
return template_rendered.encode('utf-8')

Expand All @@ -409,7 +424,7 @@ def render_about_page(self):
template_rendered = self.j2_env.get_template('about.html').render(
repostat=page_data,
page_title="About",
assets_path=self.assets_path
**self.common_rendering_data
)
return template_rendered.encode('utf-8')

Expand Down
2 changes: 2 additions & 0 deletions report/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ <h1>{{page_title}}</h1>
<li><a href="activity.html">Activity</a></li>
<li><a href="authors.html">Authors</a></li>
<li><a href="files.html">Files</a></li>
{% if has_tags_page %}
<li><a href="tags.html">Tags</a></li>
{% endif %}
<li><a href="about.html">About</a></li>
</ul>
</div>
Expand Down
5 changes: 4 additions & 1 deletion tools/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def _set_default_configuration(self):
"max_ext_length": 10,
"max_authors": 10,
"max_authors_of_months": 6,
"authors_top": 5
"authors_top": 5,
})

def do_open_in_browser(self):
Expand All @@ -114,6 +114,9 @@ def is_report_relocatable(self):
def do_calculate_contribution(self):
return self.args.contribution

def do_process_tags(self):
return self["max_recent_tags"] > 0 if "max_recent_tags" in self else True

@classmethod
def _parse_sys_argv(cls, argv):
release_info = cls.get_release_data_info()
Expand Down

0 comments on commit af7f813

Please sign in to comment.