-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstatistics.py
More file actions
executable file
·78 lines (55 loc) · 2.67 KB
/
statistics.py
File metadata and controls
executable file
·78 lines (55 loc) · 2.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/env python3
import argparse
import os
import sys
import typing
from lib.detector.common import *
# Will be initialized by the ArgumentParser
ARGS: argparse.Namespace = None
def init_argument_parser() -> None:
parser = argparse.ArgumentParser()
parser.add_argument("--report-directory", type=str, default="reports", help="""
A directory path to load the reports from
[default: reports]""")
parser.add_argument("--qmeta-file", type=str, default="qmeta.csv", help="""
A file to store the query metadata in
[default: qmeta.csv]""")
parser.add_argument("--print-args", action="store_true", help="""
Print the given command line arguments to stderr
[default: disabled]""")
global ARGS
ARGS = parser.parse_args()
if ARGS.print_args:
print(ARGS, file=sys.stderr)
def main() -> None:
init_argument_parser()
repositories = get_repositories(ARGS.report_directory)
qmeta_dict = {}
languages_dict = {}
global_min, global_max = 2e64, 0
global_repo_count = 0
with open(ARGS.qmeta_file, "r", encoding="utf-8") as f:
for line in sorted(f.readlines())[::-1]:
repository, primary_language, stars_count = line.split(",")
if repository not in repositories:
continue
if repository in qmeta_dict:
continue
global_repo_count += 1
stars_count = int(stars_count)
qmeta_dict[repository] = (primary_language, stars_count)
repo_count, old_min, old_max = languages_dict.get(primary_language, (0, 2e64, 0))
languages_dict[primary_language] = (repo_count + 1,
min(old_min, stars_count),
max(old_max, stars_count))
global_min, global_max = min(global_min, stars_count), max(global_max, stars_count)
print("| Language | Repositories | Stars |")
print("|======================|==============|=================|")
for language, (repo_count, lang_min, lang_max) in sorted(languages_dict.items(),
key=lambda kv: kv[0],
reverse=False):
print(f"| {language:20} | {repo_count:12d} | {lang_min:6d} - {lang_max:6d} |")
print("|======================|==============|=================|")
print(f"| Global | {global_repo_count:12d} | {global_min:6d} - {global_max:6d} |")
if __name__ == "__main__":
main()