Skip to content

Commit

Permalink
Merge pull request #17 from tannewt/lib_language
Browse files Browse the repository at this point in the history
Split some library stats and handle language
  • Loading branch information
kattni authored Oct 2, 2018
2 parents 43f2906 + cc35b62 commit b008dd8
Showing 1 changed file with 92 additions and 21 deletions.
113 changes: 92 additions & 21 deletions adabot/circuitpython_libraries.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
import copy
import datetime
import re
import sys
Expand Down Expand Up @@ -773,15 +774,58 @@ def print_circuitpython_download_stats():
else:
continue

print("Download stats for {}".format(release["tag_name"]))
by_board = {}
by_language = {}
by_both = {}
total = 0
for asset in release["assets"]:
if not asset["name"].startswith("adafruit-circuitpython"):
continue
board = asset["name"].split("-")[2]
print("* {} - {}".format(board, asset["download_count"]))
total += asset["download_count"]
count = asset["download_count"]
parts = asset["name"].split("-")
board = parts[2]
language = "en_US"
if len(parts) == 6:
language = parts[3]
if language not in by_language:
by_language[language] = 0
by_language[language] += count
if board not in by_board:
by_board[board] = 0
by_both[board] = {}
by_board[board] += count
by_both[board][language] = count

total += count
print("Download stats for {}".format(release["tag_name"]))
print("{} total".format(total))
print()
print("By board:")
for board in by_board:
print("* {} - {}".format(board, by_board[board]))
print()
print("By language:")
for language in by_language:
print("* {} - {}".format(language, by_language[language]))
print()

def print_pr_overview(*insights):
merged_prs = sum([x["merged_prs"] for x in insights])
authors = set().union(*[x["pr_merged_authors"] for x in insights])
reviewers = set().union(*[x["pr_reviewers"] for x in insights])

print("* {} pull requests merged".format(merged_prs))
print(" * {} authors - {}".format(len(authors), ", ".join(authors)))
print(" * {} reviewers - {}".format(len(reviewers), ", ".join(reviewers)))

def print_issue_overview(*insights):
closed_issues = sum([x["closed_issues"] for x in insights])
issue_closers = set().union(*[x["issue_closers"] for x in insights])
new_issues = sum([x["new_issues"] for x in insights])
issue_authors = set().union(*[x["issue_authors"] for x in insights])
print("* {} closed issues by {} people, {} opened by {} people"
.format(closed_issues, len(issue_closers),
new_issues, len(issue_authors)))


# Define global state shared by the functions above:
Expand Down Expand Up @@ -815,7 +859,7 @@ def print_circuitpython_download_stats():
travis_user = travis.get("/user").json()
print("Running Travis checks as " + travis_user["login"])
need_work = 0
insights = {
lib_insights = {
"merged_prs": 0,
"closed_prs": 0,
"new_prs": 0,
Expand All @@ -831,9 +875,16 @@ def print_circuitpython_download_stats():
"issue_authors": set(),
"issue_closers": set(),
}
core_insights = copy.deepcopy(lib_insights)
for k in core_insights:
if isinstance(core_insights[k], set):
core_insights[k] = set()
if isinstance(core_insights[k], list):
core_insights[k] = []
repo_needs_work = []
since = datetime.datetime.now() - datetime.timedelta(days=7)
repos_by_error = {}

for repo in repos:
errors = validate_repo(repo)
if errors:
Expand All @@ -846,27 +897,47 @@ def print_circuitpython_download_stats():
if error not in repos_by_error:
repos_by_error[error] = []
repos_by_error[error].append(repo["html_url"])
insights = lib_insights
if repo["name"] == "circuitpython" and repo["owner"]["login"] == "adafruit":
insights = core_insights
gather_insights(repo, insights, since)
print()
print("State of CircuitPython + Libraries")
print("* {} pull requests merged".format(insights["merged_prs"]))
authors = insights["pr_merged_authors"]
print(" * {} authors - {}".format(len(authors), ", ".join(authors)))
reviewers = insights["pr_reviewers"]
print(" * {} reviewers - {}".format(len(reviewers), ", ".join(reviewers)))
new_authors = insights["pr_authors"]
print("* {} new PRs, {} authors - {}".format(insights["new_prs"], len(new_authors), ", ".join(new_authors)))
print("* {} closed issues by {} people, {} opened by {} people"
.format(insights["closed_issues"], len(insights["issue_closers"]),
insights["new_issues"], len(insights["issue_authors"])))
print("* {} open pull requests".format(len(insights["open_prs"])))
for pr in insights["open_prs"]:

print("Overall")
print_pr_overview(lib_insights, core_insights)
print_issue_overview(lib_insights, core_insights)

print()
print("Core")
print_pr_overview(core_insights)
print("* {} open pull requests".format(len(core_insights["open_prs"])))
for pr in core_insights["open_prs"]:
print(" * {}".format(pr))
print_issue_overview(core_insights)
print("* {} open issues".format(len(insights["open_issues"])))
for issue in insights["open_issues"]:
print(" * {}".format(issue))
print(" * https://github.com/adafruit/circuitpython/issues")
print()
print_circuitpython_download_stats()

print()
print("Libraries")
print_pr_overview(lib_insights)
print("* {} open pull requests".format(len(lib_insights["open_prs"])))
for pr in lib_insights["open_prs"]:
print(" * {}".format(pr))
print_issue_overview(lib_insights)
print("* {} open issues".format(len(lib_insights["open_issues"])))
for issue in lib_insights["open_issues"]:
print(" * {}".format(issue))

lib_repos = []
for repo in repos:
if repo["owner"]["login"] == "adafruit" and repo["name"].startswith("Adafruit_CircuitPython"):
lib_repos.append(repo)

# print("- [ ] [{0}](https://github.com/{1})".format(repo["name"], repo["full_name"]))
print("{} out of {} repos need work.".format(need_work, len(repos)))
print("{} out of {} repos need work.".format(need_work, len(lib_repos)))

list_repos_for_errors = [ERROR_NOT_IN_BUNDLE]

Expand All @@ -877,4 +948,4 @@ def print_circuitpython_download_stats():
error_count = len(repos_by_error[error])
print("{} - {}".format(error, error_count))
if error_count <= 5 or error in list_repos_for_errors:
print("\n".join(repos_by_error[error]))
print("\n".join(["* " + x for x in repos_by_error[error]]))

0 comments on commit b008dd8

Please sign in to comment.