separate compose for metrics
This commit is contained in:
parent
075681ff7e
commit
ecd7283daa
2
.gitignore
vendored
2
.gitignore
vendored
@ -159,4 +159,4 @@ cython_debug/
|
||||
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
||||
#.idea/
|
||||
|
||||
metrics.png
|
||||
*.png
|
||||
|
@ -65,9 +65,3 @@ services:
|
||||
networks:
|
||||
radn: {}
|
||||
v6d: {}
|
||||
metrics:
|
||||
container_name: radn-metrics
|
||||
build:
|
||||
context: metrics
|
||||
tty: true
|
||||
stop_signal: SIGKILL
|
||||
|
@ -3,7 +3,7 @@ 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 5973fe94eb24d3bf7008eea27ef0ee42c59a60ef
|
||||
RUN git fetch && git checkout de26092abcc44fa249bbbfd0309613783107af52
|
||||
COPY metrics.py /code/metrics.py
|
||||
RUN python3 /code/metrics.py
|
||||
FROM python:3.11
|
||||
|
6
metrics/docker-compose.yml
Normal file
6
metrics/docker-compose.yml
Normal file
@ -0,0 +1,6 @@
|
||||
services:
|
||||
metrics:
|
||||
container_name: radn-metrics
|
||||
build: .
|
||||
tty: true
|
||||
stop_signal: SIGKILL
|
@ -8,13 +8,16 @@ def filter_schema(obj, schema):
|
||||
return {key: filter_schema(obj[key], value) for key, value in schema.items()}
|
||||
|
||||
|
||||
entry_schema = {"name": True, "metrics": {"halstead": {"bugs": True, "difficulty": True}}}
|
||||
entry_schema = {
|
||||
"name": True,
|
||||
"metrics": {"halstead": {"bugs": True, "difficulty": True}, "loc": {"ploc": True, "cloc": True, "blank": True}},
|
||||
}
|
||||
|
||||
commits = check_output(['git', 'log', '--pretty=%H'], text=True).splitlines()
|
||||
commits = check_output(["git", "log", "--pretty=%H"], text=True).splitlines()
|
||||
entries = []
|
||||
for (i, commit) in enumerate(commits):
|
||||
print('running', commit)
|
||||
check_output(['git', 'checkout', commit], text=True)
|
||||
for i, commit in enumerate(commits):
|
||||
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()
|
||||
@ -22,5 +25,5 @@ for (i, commit) in enumerate(commits):
|
||||
for line in lines:
|
||||
entry = json.loads(line)
|
||||
entries.append((i, filter_schema(entry, entry_schema)))
|
||||
with open('/code/metrics.json', 'w') as file:
|
||||
with open("/code/metrics.json", "w") as file:
|
||||
json.dump(entries, file)
|
||||
|
@ -19,24 +19,61 @@ def colour(k: int):
|
||||
with open("metrics.json", "r") as file:
|
||||
entries = json.load(file)
|
||||
|
||||
h_colour = True
|
||||
|
||||
units = []
|
||||
for i, entry in entries:
|
||||
x = i
|
||||
y = entry["metrics"]["halstead"]["difficulty"] or 0.0
|
||||
nh = hash(entry["name"])
|
||||
y += (nh % 201 - 100) / 500
|
||||
entries_grouped: dict[int, list] = {}
|
||||
|
||||
|
||||
def group_entries():
|
||||
for i, entry in entries:
|
||||
entries_grouped.setdefault(i, []).append(entry)
|
||||
|
||||
|
||||
group_entries()
|
||||
|
||||
|
||||
def render_halstead(h_colour: bool):
|
||||
units = []
|
||||
for i, entry in entries:
|
||||
x = -i
|
||||
y = entry["metrics"]["halstead"]["difficulty"] or 0.0
|
||||
nh = hash(entry["name"])
|
||||
y += (nh % 201 - 100) / 500
|
||||
if h_colour:
|
||||
r, g, b = colour(nh)
|
||||
units.append((x, y, r, g, b))
|
||||
else:
|
||||
c = entry["metrics"]["halstead"]["bugs"] or 0.0
|
||||
units.append((x, y, c))
|
||||
if h_colour:
|
||||
r, g, b = colour(nh)
|
||||
units.append((x, y, r, g, b))
|
||||
X, Y, R, G, B = np.array(units).transpose()
|
||||
C = np.array([R, G, B]).transpose() / 255
|
||||
C = 0.25 + 0.75 * C
|
||||
else:
|
||||
c = entry["metrics"]["halstead"]["bugs"] or 0.0
|
||||
units.append((x, y, c))
|
||||
if h_colour:
|
||||
X, Y, R, G, B = np.array(units).transpose()
|
||||
C = np.array([R, G, B]).transpose() / 255
|
||||
else:
|
||||
X, Y, C = np.array(units).transpose()
|
||||
plt.scatter(-X, Y, s=2.0, c=C)
|
||||
plt.savefig("/code/metrics.png")
|
||||
X, Y, C = np.array(units).transpose()
|
||||
plt.clf()
|
||||
plt.scatter(X, Y, s=2.0, c=C)
|
||||
plt.savefig("/code/colour.png" if h_colour else "/code/metrics.png")
|
||||
|
||||
|
||||
def render_ploc():
|
||||
units = []
|
||||
for i, group in entries_grouped.items():
|
||||
x = -i
|
||||
ys = [
|
||||
sum(entry["metrics"]["loc"]["ploc"] for entry in group),
|
||||
sum(entry["metrics"]["loc"]["cloc"] for entry in group),
|
||||
sum(entry["metrics"]["loc"]["blank"] for entry in group),
|
||||
]
|
||||
units.append((x, *ys))
|
||||
X, Yp, Yc, Yb = np.array(units).transpose()
|
||||
plt.clf()
|
||||
plt.plot(X, Yp, label="code")
|
||||
plt.plot(X, Yc, label="comments/docs")
|
||||
plt.plot(X, Yb, label="blank")
|
||||
plt.legend()
|
||||
plt.savefig("/code/ploc.png")
|
||||
|
||||
|
||||
render_halstead(False)
|
||||
render_halstead(True)
|
||||
render_ploc()
|
||||
|
7
metrics/render.sh
Executable file
7
metrics/render.sh
Executable file
@ -0,0 +1,7 @@
|
||||
clear
|
||||
docker compose up -d --build metrics
|
||||
mkdir metrics
|
||||
docker cp radn-metrics:/code/metrics.png ./metrics/metrics.png
|
||||
docker cp radn-metrics:/code/ploc.png ./metrics/metrics-ploc.png
|
||||
docker cp radn-metrics:/code/colour.png ./metrics/metrics-colour.png
|
||||
docker compose stop metrics
|
Loading…
Reference in New Issue
Block a user