Skip to content

Stats

Report site stats.

stats(opt)

Main driver.

Source code in mccole/stats.py
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
def stats(opt):
    """Main driver."""
    table = PrettyTable(field_names=TABLE_FMT.keys())
    for k, v in TABLE_FMT.items():
        table.align[k] = v

    files = find_files(opt, {opt.out})
    table.add_row(("bibliography entries", len(find_key_defs(files, "bibliography"))))
    table.add_row(("glossary entries", len(find_key_defs(files, "glossary"))))

    sections = {path: data["content"] for path, data in files.items()}
    table.add_row(("figures", len(find_figure_defs(sections))))
    table.add_row(("link definitions", len(find_markdown_link_defs(sections))))
    table.add_row(("tables", len(find_table_defs(sections))))
    table.add_row(("issues", get_num_issues(opt.root)))
    table.add_row(("pull requests", get_num_pull_requests(opt.root)))

    print(table)

find_figure_defs(files)

Collect all figure definitions.

Source code in mccole/stats.py
42
43
44
45
46
47
48
49
50
51
52
53
54
def find_figure_defs(files):
    """Collect all figure definitions."""
    found = defaultdict(list)
    for path, content in files.items():
        if path.suffix == ".md":
            for figure in FIGURE_DEF.finditer(content):
                text = figure.group(1)
                found[FIGURE_ID.search(text).group(1)].append({
                    "src": FIGURE_SRC.search(text).group(1),
                    "alt": FIGURE_ALT.search(text).group(1),
                    "caption": FIGURE_CAPTION.search(text).group(1),
                })
    return found

Collect Markdown link key definnitions.

Source code in mccole/stats.py
57
58
59
60
61
62
63
64
def find_markdown_link_defs(sections):
    """Collect Markdown link key definnitions."""
    found = set()
    for filepath, content in sections.items():
        if filepath.suffix == ".md":
            for link in MD_LINK_DEF.finditer(content):
                found.add(link[0])
    return found

get_num_issues(root)

Get issue count from repository.

Source code in mccole/stats.py
67
68
69
def get_num_issues(root):
    """Get issue count from repository."""
    return get_repo(root).open_issues_count

get_num_pull_requests(root)

Get pull request count from repository.

Source code in mccole/stats.py
72
73
74
def get_num_pull_requests(root):
    """Get pull request count from repository."""
    return get_repo(root).get_pulls().totalCount

parse_args(parser)

Parse command-line arguments.

Source code in mccole/stats.py
77
78
79
80
81
def parse_args(parser):
    """Parse command-line arguments."""
    parser.add_argument("--out", type=str, default="docs", help="output directory")
    parser.add_argument("--root", type=str, default=".", help="root directory")
    return parser