Skip to content

Commit 56a4f43

Browse files
authored
Merge pull request #66 from sommersoft/squishy_core_stats
Combine & Tabulate Board DL Stats; Fix Core Insights
2 parents 980b6f2 + fe04c61 commit 56a4f43

File tree

1 file changed

+100
-20
lines changed

1 file changed

+100
-20
lines changed

adabot/circuitpython_libraries.py

Lines changed: 100 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,10 @@
127127
# Cache the CircuitPython driver page so we can make sure every driver is linked to.
128128
core_driver_page = None
129129

130+
# GitHub API Serch has stopped returning the core repo for some reason. Tried several
131+
# different search params, and came up emtpy. Hardcoding it as a failsafe.
132+
core_repo_url = "/repos/adafruit/circuitpython"
133+
130134
def parse_gitmodules(input_text):
131135
"""Parse a .gitmodules file and return a list of all the git submodules
132136
defined inside of it. Each list item is 2-tuple with:
@@ -282,6 +286,10 @@ def list_repos():
282286
break
283287
# Subsequent links have our access token already so we use requests directly.
284288
result = requests.get(link, timeout=30)
289+
if "circuitpython" not in [repo["name"] for repo in repos]:
290+
core = github.get(core_repo_url)
291+
if core.ok:
292+
repos.append(core.json())
285293

286294
return repos
287295

@@ -1023,20 +1031,27 @@ def print_circuitpython_download_stats():
10231031
if not response.ok:
10241032
output_handler("Core CircuitPython GitHub analytics request failed.")
10251033
releases = response.json()
1034+
10261035
found_unstable = False
10271036
found_stable = False
1037+
stable_tag = None
1038+
prerelease_tag = None
1039+
1040+
by_board = {}
1041+
by_language = {}
1042+
by_both = {}
1043+
total = {}
1044+
10281045
for release in releases:
10291046
if not found_unstable and not release["draft"] and release["prerelease"]:
10301047
found_unstable = True
1048+
prerelease_tag = release["tag_name"]
10311049
elif not found_stable and not release["draft"] and not release["prerelease"]:
10321050
found_stable = True
1051+
stable_tag = release["tag_name"]
10331052
else:
10341053
continue
10351054

1036-
by_board = {}
1037-
by_language = {}
1038-
by_both = {}
1039-
total = 0
10401055
for asset in release["assets"]:
10411056
if not asset["name"].startswith("adafruit-circuitpython"):
10421057
continue
@@ -1047,26 +1062,91 @@ def print_circuitpython_download_stats():
10471062
if len(parts) == 6:
10481063
language = parts[3]
10491064
if language not in by_language:
1050-
by_language[language] = 0
1051-
by_language[language] += count
1065+
by_language[language] = {release["tag_name"]: 0}
1066+
if release["tag_name"] not in by_language[language]:
1067+
by_language[language][release["tag_name"]] = 0
1068+
by_language[language][release["tag_name"]] += count
10521069
if board not in by_board:
1053-
by_board[board] = 0
1070+
by_board[board] = {release["tag_name"]: 0}
10541071
by_both[board] = {}
1055-
by_board[board] += count
1072+
if release["tag_name"] not in by_board[board]:
1073+
by_board[board][release["tag_name"]] = 0
1074+
by_board[board][release["tag_name"]] += count
10561075
by_both[board][language] = count
10571076

1058-
total += count
1059-
output_handler("Download stats for {}".format(release["tag_name"]))
1060-
output_handler("{} total".format(total))
1061-
output_handler()
1062-
output_handler("By board:")
1063-
for board in by_board:
1064-
output_handler("* {} - {}".format(board, by_board[board]))
1065-
output_handler()
1066-
output_handler("By language:")
1067-
for language in by_language:
1068-
output_handler("* {} - {}".format(language, by_language[language]))
1069-
output_handler()
1077+
if release["tag_name"] not in total:
1078+
total[release["tag_name"]] = 0
1079+
total[release["tag_name"]] += count
1080+
1081+
output_handler("Download stats by board:")
1082+
output_handler()
1083+
by_board_list = [["Board", "{}".format(stable_tag.strip(" ")), "{}".format(prerelease_tag.strip(" "))],]
1084+
for board in sorted(by_board.items()):
1085+
by_board_list.append([str(board[0]),
1086+
(str(board[1][stable_tag]) if stable_tag in board[1] else "-"),
1087+
(str(board[1][prerelease_tag]) if prerelease_tag in board[1] else "-")])
1088+
1089+
long_col = [(max([len(str(row[i])) for row in by_board_list]) + 3)
1090+
for i in range(len(by_board_list[0]))]
1091+
#row_format = "".join(["{:<" + str(this_col) + "}" for this_col in long_col])
1092+
row_format = "".join(["| {:<" + str(long_col[0]) + "}",
1093+
"|{:^" + str(long_col[1]) + "}",
1094+
"|{:^" + str(long_col[2]) + "}|"])
1095+
1096+
by_board_list.insert(1,
1097+
["{}".format("-"*(long_col[0])),
1098+
"{}".format("-"*(long_col[1])),
1099+
"{}".format("-"*(long_col[2]))])
1100+
1101+
by_board_list.extend((["{}".format("-"*(long_col[0])),
1102+
"{}".format("-"*(long_col[1])),
1103+
"{}".format("-"*(long_col[2]))],
1104+
["{0}{1}".format(" "*(long_col[0] - 6), "Total"),
1105+
"{}".format(total[stable_tag]),
1106+
"{}".format(total[prerelease_tag])],
1107+
["{}".format("-"*(long_col[0])),
1108+
"{}".format("-"*(long_col[1])),
1109+
"{}".format("-"*(long_col[2]))]))
1110+
1111+
for row in by_board_list:
1112+
output_handler(row_format.format(*row))
1113+
output_handler()
1114+
1115+
output_handler("Download stats by language:")
1116+
output_handler()
1117+
by_lang_list = [["Board", "{}".format(stable_tag.strip(" ")), "{}".format(prerelease_tag.strip(" "))],]
1118+
for board in sorted(by_language.items()):
1119+
by_lang_list.append([str(board[0]),
1120+
(str(board[1][stable_tag]) if stable_tag in board[1] else "-"),
1121+
(str(board[1][prerelease_tag]) if prerelease_tag in board[1] else "-")])
1122+
1123+
long_col = [(max([len(str(row[i])) for row in by_lang_list]) + 3)
1124+
for i in range(len(by_lang_list[0]))]
1125+
#row_format = "".join(["{:<" + str(this_col) + "}" for this_col in long_col])
1126+
row_format = "".join(["| {:<" + str(long_col[0]) + "}",
1127+
"|{:^" + str(long_col[1]) + "}",
1128+
"|{:^" + str(long_col[2]) + "}|"])
1129+
1130+
by_lang_list.insert(1,
1131+
["{}".format("-"*(long_col[0])),
1132+
"{}".format("-"*(long_col[1])),
1133+
"{}".format("-"*(long_col[2]))])
1134+
1135+
by_lang_list.extend((["{}".format("-"*(long_col[0])),
1136+
"{}".format("-"*(long_col[1])),
1137+
"{}".format("-"*(long_col[2]))],
1138+
["{0}{1}".format(" "*(long_col[0] - 6), "Total"),
1139+
"{}".format(total[stable_tag]),
1140+
"{}".format(total[prerelease_tag])],
1141+
["{}".format("-"*(long_col[0])),
1142+
"{}".format("-"*(long_col[1])),
1143+
"{}".format("-"*(long_col[2]))]))
1144+
1145+
for row in by_lang_list:
1146+
output_handler(row_format.format(*row))
1147+
#for language in by_language:
1148+
# output_handler("* {} - {}".format(language, by_language[language]))
1149+
output_handler()
10701150

10711151
def print_pr_overview(*insights):
10721152
merged_prs = sum([x["merged_prs"] for x in insights])

0 commit comments

Comments
 (0)