Skip to content

Commit

Permalink
Conform to pylint
Browse files Browse the repository at this point in the history
Signed-off-by: Isaac Milarsky <[email protected]>
  • Loading branch information
IsaacMilarky committed Dec 13, 2023
1 parent d40a786 commit d76f0db
Show file tree
Hide file tree
Showing 10 changed files with 204 additions and 165 deletions.
13 changes: 8 additions & 5 deletions scripts/fetch_public_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
entity objects.
"""
import json
from metricsLib.metrics_definitions import SIMPLE_METRICS, ORG_METRICS, PERIODIC_METRICS, RESOURCE_METRICS
from metricsLib.metrics_definitions import SIMPLE_METRICS, ORG_METRICS
from metricsLib.metrics_definitions import PERIODIC_METRICS, RESOURCE_METRICS


def get_all_data(all_orgs, all_repos):
Expand Down Expand Up @@ -80,9 +81,9 @@ def fetch_all_new_metric_data(all_orgs, all_repos):

for metric in PERIODIC_METRICS:
repo.apply_metric_and_store_data(metric)

for metric in RESOURCE_METRICS:
repo.apply_metric_and_store_data(metric,repo)
repo.apply_metric_and_store_data(metric, repo)

# Capture all metric data for all Github orgs
for org in all_orgs:
Expand All @@ -109,15 +110,17 @@ def read_previous_metric_data(repos, orgs):
prev_data = json.load(file)
org.previous_metric_data.update(prev_data)
except FileNotFoundError:
print(f"Could not find previous data for records for org {org.login}")
print("Could not find previous data for records for org" +
f"{org.login}")

for repo in repos:
try:
with open(repo.get_path_to_json_data(), "r", encoding="utf-8") as file:
prev_data = json.load(file)
repo.previous_metric_data.update(prev_data)
except FileNotFoundError:
print(f"Could not find previous data for records for repo {repo.name}")
print("Could not find previous data for records for repo" +
repo.name)


def write_metric_data_json_to_file(orgs, repos):
Expand Down
24 changes: 13 additions & 11 deletions scripts/gen_graphs.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ def generate_all_graphs_for_repos(all_repos):
generate_solid_gauge_issue_graph(repo)
generate_repo_sparklines(repo)


def generate_all_graphs_for_orgs(all_orgs):
for org in all_orgs:
print(f"Generating graphs for org {org.name}")
Expand Down Expand Up @@ -69,7 +70,7 @@ def generate_repo_sparklines(repo):
"margin": 10
}
write_repo_chart_to_file(
repo, chart, "commit_sparklines", custom_func=chart.render_sparkline,custom_func_params=_kwargs_)
repo, chart, "commit_sparklines", custom_func=chart.render_sparkline, custom_func_params=_kwargs_)


def generate_solid_gauge_issue_graph(oss_entity):
Expand All @@ -80,24 +81,24 @@ def generate_solid_gauge_issue_graph(oss_entity):
oss_entity: the OSSEntity to create a graph for.
"""

issues_gauge = pygal.SolidGauge(inner_radius=0.70,legend_at_bottom=True)
issues_gauge = pygal.SolidGauge(inner_radius=0.70, legend_at_bottom=True)

def percent_formatter(x):
return '{:0.2f}%'.format(x)
issues_gauge.value_formatter = percent_formatter
#Generate graph to measure percentage of issues that are open

# Generate graph to measure percentage of issues that are open
try:
#calculate portion of issues that are open.
# calculate portion of issues that are open.
open_issue_percent = oss_entity.metric_data['open_issues_count'] / \
oss_entity.metric_data['issues_count']
except ZeroDivisionError:
open_issue_percent = 0
issues_gauge.add(
'Open Issues', [{'value': open_issue_percent * 100, 'max_value': 100}])


try:
#calculate portion of pull requests that are open, merged, and closed
# calculate portion of pull requests that are open, merged, and closed
open_pr_percent = oss_entity.metric_data['open_pull_requests_count'] / \
oss_entity.metric_data['pull_requests_count']
merged_pr_percent = oss_entity.metric_data['merged_pull_requests_count'] / \
Expand All @@ -109,14 +110,15 @@ def percent_formatter(x):
merged_pr_percent = 0
closed_pr_percent = 0

#Generate graph to measure portion of pull requests that are open
# Generate graph to measure portion of pull requests that are open
issues_gauge.add('Open Pull Requests', [
{'value': open_pr_percent * 100, 'max_value': 100}])
#Generate graph to measure portion of pull requests that are merged or closed.

# Generate graph to measure portion of pull requests that are merged or closed.
issues_gauge.add(
'Closed and Merged Pull Requests', [
{'label': "Merged Pull Requests",'value': merged_pr_percent * 100, 'max_value': 100},
{'label': "Merged Pull Requests",
'value': merged_pr_percent * 100, 'max_value': 100},
{'label': "Closed Pull Requests", 'value': closed_pr_percent * 100, 'max_value': 100}])

write_repo_chart_to_file(oss_entity, issues_gauge, "issue_gauge")
Expand Down
18 changes: 11 additions & 7 deletions scripts/gen_reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from datetime import date
from metricsLib.constants import REPO_REPORT_TEMPLATE, ORG_REPORT_TEMPLATE


def calc_percent_difference(latest, prev):
"""
This function calculates the percent difference between
Expand All @@ -28,7 +29,8 @@ def calc_percent_difference(latest, prev):

return int(dec * 100)

def get_heading_report_values(headings,oss_entity):

def get_heading_report_values(headings, oss_entity):
report_values = {}
for heading in headings:
prev_record = oss_entity.metric_data[heading]
Expand Down Expand Up @@ -57,12 +59,13 @@ def get_heading_report_values(headings,oss_entity):
f"{heading}_diff_color": diff_color,
f"{heading}_diff_percent_color": diff_color
})

return report_values

def write_report_to_file(report_template,report_values,oss_entity):

def write_report_to_file(report_template, report_values, oss_entity):
raw_report = report_template.format(**report_values)
with open(oss_entity.get_path_to_report_data(),"w+", encoding="utf-8") as file:
with open(oss_entity.get_path_to_report_data(), "w+", encoding="utf-8") as file:
file.write(raw_report)


Expand Down Expand Up @@ -91,11 +94,11 @@ def generate_org_report_files(orgs):
'followers_count'
]

report_values.update(get_heading_report_values(org_metric_table_headings, org))
report_values.update(get_heading_report_values(
org_metric_table_headings, org))
write_report_to_file(ORG_REPORT_TEMPLATE, report_values, org)



def generate_repo_report_files(repos):
"""
This function generates reports for each repo and writes them to file.
Expand Down Expand Up @@ -127,6 +130,7 @@ def generate_repo_report_files(repos):
'watchers_count'
]

report_values.update(get_heading_report_values(metric_table_headings, repo))
report_values.update(get_heading_report_values(
metric_table_headings, repo))

write_report_to_file(REPO_REPORT_TEMPLATE, report_values, repo)
6 changes: 3 additions & 3 deletions scripts/metricsLib/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@
template_path = os.path.join(PATH_TO_TEMPLATES, "repo_report_template.md")
with open(template_path, "r", encoding="utf-8") as file:
REPO_REPORT_TEMPLATE = file.read()
with open(os.path.join(PATH_TO_TEMPLATES, "org_report_template.md"), "r",encoding="utf-8") as file:
ORG_REPORT_TEMPLATE = file.read()

with open(os.path.join(PATH_TO_TEMPLATES, "org_report_template.md"), "r", encoding="utf-8") as file:
ORG_REPORT_TEMPLATE = file.read()
Loading

0 comments on commit d76f0db

Please sign in to comment.