-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaddStatistics.py
62 lines (45 loc) · 1.84 KB
/
addStatistics.py
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
"""
Most the statistics for the site, are generated by Hugo. This script,
generates other statistics like number of lines in the AFP using the
scripts from the current AFP.
For this script to work, `return data` needs to be added at
line 212 in templates.py
"""
import os
import sys
from writeFile import writeFile
sys.path.append("sitegen-lib")
import afpstats
import metadata
import templates
from config import options
from sitegen import associate_releases, parse, read_versions
def addStatistics():
"""Creates the necessary objects to generates the statistics,
then outputs them to the data directory"""
hugoDir = "hugo/"
dataDir = hugoDir + "data/"
options.templates_dir = "../metadata/templates"
entries = parse(os.path.join("..", "metadata", "metadata"))
versions = read_versions(os.path.join("..", "metadata", "release-dates"))
associate_releases(entries, versions, os.path.join("..", "metadata", "releases"))
deps_dict = metadata.empty_deps(entries)
afp_dict = afpstats.afp_dict(entries, "../thys", deps_dict)
afp_dict.build_stats()
builder = templates.Builder(options, entries, afp_dict)
stats = builder.generate_statistics()
loc_articles = [article.loc for article in stats["articles_by_time"]]
all_articles = [a.name for a in stats["articles_by_time"]]
data = {
"num_lemmas": stats["num_lemmas"],
"num_loc": stats["num_loc"],
"articles_year": stats["articles_year"],
"loc_years": stats["loc_years"],
"author_years": stats["author_years"],
"author_years_cumulative": stats["author_years_cumulative"],
"loc_articles": loc_articles,
"all_articles": all_articles,
}
writeFile(dataDir + "statistics.json", data)
if __name__ == "__main__":
addStatistics()