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.
|
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
||||||
#.idea/
|
#.idea/
|
||||||
|
|
||||||
metrics.png
|
*.png
|
||||||
|
@ -65,9 +65,3 @@ services:
|
|||||||
networks:
|
networks:
|
||||||
radn: {}
|
radn: {}
|
||||||
v6d: {}
|
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/
|
WORKDIR /code/
|
||||||
RUN git clone https://gitea.parrrate.ru/PTV/radn-rs.git
|
RUN git clone https://gitea.parrrate.ru/PTV/radn-rs.git
|
||||||
WORKDIR /code/radn-rs/
|
WORKDIR /code/radn-rs/
|
||||||
RUN git fetch && git checkout 5973fe94eb24d3bf7008eea27ef0ee42c59a60ef
|
RUN git fetch && git checkout de26092abcc44fa249bbbfd0309613783107af52
|
||||||
COPY metrics.py /code/metrics.py
|
COPY metrics.py /code/metrics.py
|
||||||
RUN python3 /code/metrics.py
|
RUN python3 /code/metrics.py
|
||||||
FROM python:3.11
|
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()}
|
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 = []
|
entries = []
|
||||||
for (i, commit) in enumerate(commits):
|
for i, commit in enumerate(commits):
|
||||||
print('running', commit)
|
print("running", commit)
|
||||||
check_output(['git', 'checkout', commit], text=True)
|
check_output(["git", "checkout", commit], text=True)
|
||||||
lines = check_output(
|
lines = check_output(
|
||||||
["rust-code-analysis-cli", "-m", "-p", "src", "-O", "json"], text=True
|
["rust-code-analysis-cli", "-m", "-p", "src", "-O", "json"], text=True
|
||||||
).splitlines()
|
).splitlines()
|
||||||
@ -22,5 +25,5 @@ for (i, commit) in enumerate(commits):
|
|||||||
for line in lines:
|
for line in lines:
|
||||||
entry = json.loads(line)
|
entry = json.loads(line)
|
||||||
entries.append((i, filter_schema(entry, entry_schema)))
|
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)
|
json.dump(entries, file)
|
||||||
|
@ -19,11 +19,22 @@ def colour(k: int):
|
|||||||
with open("metrics.json", "r") as file:
|
with open("metrics.json", "r") as file:
|
||||||
entries = json.load(file)
|
entries = json.load(file)
|
||||||
|
|
||||||
h_colour = True
|
|
||||||
|
|
||||||
units = []
|
entries_grouped: dict[int, list] = {}
|
||||||
for i, entry in entries:
|
|
||||||
x = i
|
|
||||||
|
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
|
y = entry["metrics"]["halstead"]["difficulty"] or 0.0
|
||||||
nh = hash(entry["name"])
|
nh = hash(entry["name"])
|
||||||
y += (nh % 201 - 100) / 500
|
y += (nh % 201 - 100) / 500
|
||||||
@ -33,10 +44,36 @@ for i, entry in entries:
|
|||||||
else:
|
else:
|
||||||
c = entry["metrics"]["halstead"]["bugs"] or 0.0
|
c = entry["metrics"]["halstead"]["bugs"] or 0.0
|
||||||
units.append((x, y, c))
|
units.append((x, y, c))
|
||||||
if h_colour:
|
if h_colour:
|
||||||
X, Y, R, G, B = np.array(units).transpose()
|
X, Y, R, G, B = np.array(units).transpose()
|
||||||
C = np.array([R, G, B]).transpose() / 255
|
C = np.array([R, G, B]).transpose() / 255
|
||||||
else:
|
C = 0.25 + 0.75 * C
|
||||||
|
else:
|
||||||
X, Y, C = np.array(units).transpose()
|
X, Y, C = np.array(units).transpose()
|
||||||
plt.scatter(-X, Y, s=2.0, c=C)
|
plt.clf()
|
||||||
plt.savefig("/code/metrics.png")
|
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