caching + adjusted line count

This commit is contained in:
AF 2023-07-01 16:15:21 +00:00
parent 9b2eaf9fe2
commit 0574470f99
4 changed files with 46 additions and 13 deletions

10
.vscode/settings.json vendored
View File

@ -1,3 +1,11 @@
{
"python.analysis.typeCheckingMode": "basic"
"python.analysis.typeCheckingMode": "basic",
"python.formatting.blackArgs": [
"--line-length",
"120"
],
"isort.args": [
"--profile",
"black"
]
}

View File

@ -3,9 +3,14 @@ RUN cargo install rust-code-analysis-cli
WORKDIR /code/
RUN git clone https://gitea.parrrate.ru/PTV/radn-rs.git
WORKDIR /code/radn-rs/
RUN git fetch && git checkout 540fdce02aefcb0dae5735c55daec690c4571b18
COPY metrics.py /code/metrics.py
RUN git fetch && git checkout 664365ba728e5b566b85f4275aef556b2094f606
RUN python3 /code/metrics.py
RUN git fetch && git checkout 82141aa35e01a71f190c1ee83dd467f4153406df
RUN python3 /code/metrics.py
FROM python:3.11
RUN python3 -m pip install matplotlib
WORKDIR /code/

View File

@ -10,20 +10,34 @@ def filter_schema(obj, schema):
entry_schema = {
"name": True,
"metrics": {"halstead": {"bugs": True, "difficulty": True}, "loc": {"ploc": True, "cloc": True, "blank": True}},
"metrics": {
"halstead": {"bugs": True, "difficulty": True},
"loc": {"ploc": True, "cloc": True, "blank": True},
},
}
try:
with open("/code/cache.json", "r") as file:
cache = json.load(file)
except FileNotFoundError:
cache = {}
commits = check_output(["git", "log", "--pretty=%H"], text=True).splitlines()
entries = []
for i, commit in enumerate(commits):
if commit not in cache:
print("running", commit)
check_output(["git", "checkout", commit], text=True)
lines = check_output(
["rust-code-analysis-cli", "-m", "-p", "src", "-O", "json"], text=True
).splitlines()
print(len(lines))
commit_entries = []
for line in lines:
entry = json.loads(line)
entries.append((i, filter_schema(entry, entry_schema)))
commit_entries.append(filter_schema(entry, entry_schema))
cache[commit] = commit_entries
entries.extend((i, entry) for entry in cache[commit])
with open("/code/cache.json", "w") as file:
json.dump(cache, file)
with open("/code/metrics.json", "w") as file:
json.dump(entries, file)

View File

@ -66,13 +66,19 @@ def render_ploc():
units.append((x, *ys))
X, Yp, Yc, Yb = np.array(units).transpose()
plt.clf()
plt.axhline(7000, alpha=0.5)
plt.axhline(6000, alpha=0.5)
plt.axhline(0, alpha=0.5)
plt.plot(X, Yp, label="code")
plt.plot(X, Yc, label="comments/docs")
plt.plot(X, Yb, label="blank")
fmt, kwargs = ":", dict(alpha=0.5)
plt.plot(X, Yc * (k := Yp[0] / Yc[0]), fmt, label=f"c/d x{round(k, 1)}", c="C1", **kwargs)
plt.plot(X, Yb * (k := Yp[0] / Yb[0]), fmt, label=f"blank x{round(k, 1)}", c="C2", **kwargs)
plt.legend()
plt.savefig("/code/ploc.png")
render_ploc()
render_halstead(False)
render_halstead(True)
render_ploc()