-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot-db.py
More file actions
executable file
·64 lines (50 loc) · 1.88 KB
/
plot-db.py
File metadata and controls
executable file
·64 lines (50 loc) · 1.88 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
#!/usr/bin/env python3
from sys import argv
import sqlite3
import pandas as pd
import plotly.express as px
def get_path_and_link(origpath,localrepopath,repolink,sep,default_branch="main"):
localpath = origpath
path_from_reporoot = localpath.replace(localrepopath,'')
path_split = path_from_reporoot.split('/')
dirname = path_split[:-1]
basename = path_split[-1]
path = repolink.replace('.git','') +f"/blob/{default_branch}/" + path_from_reporoot
res = sep.join(dirname) + sep + '<a href="{}" style="color: #000000; text-decoration: underline;">{}</a>'.format(path,basename)
return res
def main(cloc_db_filename,
output_fig_filename,
repolink=None,
localrepopath=None,
default_branch=None):
connection = sqlite3.connect(cloc_db_filename)
df = pd.read_sql_query("SELECT * from t;",connection)
connection.close()
separator_for_trick = "####"
paths = (df["File"]
.apply(lambda p:
get_path_and_link(p, localrepopath, repolink, separator_for_trick,default_branch)
if repolink else p.replace('/',separator_for_trick))
.str.split(separator_for_trick,expand=True))
df_expanded = df.merge(paths,
left_index=True,
right_index=True)
fig = px.treemap(df_expanded,
path=list(range(0,len(paths.columns))),
color="Language",
values="nCode")
fig.show()
print(f"Writing file {output_fig_filename}")
fig.write_html(output_fig_filename)
cloc_db_filename = argv[1]
output_fig_filename = argv[2]
try:
repolink=argv[3]
localrepopath=argv[4]
default_branch=argv[5]
except:
repolink=None
localrepopath=None
default_branch=None
pass
main(cloc_db_filename,output_fig_filename,repolink,localrepopath,default_branch)