colourful render

This commit is contained in:
AF 2023-06-18 16:29:48 +00:00
parent f4c9076ccc
commit 075681ff7e
2 changed files with 28 additions and 9 deletions

View File

@ -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 e8142ba869bffa60d9a3a809d1c7e2093afd8ba5 RUN git fetch && git checkout 5973fe94eb24d3bf7008eea27ef0ee42c59a60ef
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

View File

@ -4,20 +4,39 @@ import json
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
import numpy as np import numpy as np
plt.rcParams['figure.figsize'] = [18, 9] plt.rcParams["figure.figsize"] = [18, 9]
plt.style.use('dark_background') plt.style.use("dark_background")
plt.subplots_adjust(left=0.05, right=0.99, top=0.95, bottom=0.05) plt.subplots_adjust(left=0.05, right=0.99, top=0.95, bottom=0.05)
with open('metrics.json', 'r') as file:
def colour(k: int):
k, r = divmod(k, 256)
k, g = divmod(k, 256)
k, b = divmod(k, 256)
return r, g, b
with open("metrics.json", "r") as file:
entries = json.load(file) entries = json.load(file)
h_colour = True
units = [] units = []
for i, entry in entries: for i, entry in entries:
x = i x = i
y = entry["metrics"]["halstead"]["difficulty"] or 0.0 y = entry["metrics"]["halstead"]["difficulty"] or 0.0
y += (hash(entry["name"]) % 201 - 100) / 500 nh = hash(entry["name"])
c = entry["metrics"]["halstead"]["bugs"] or 0.0 y += (nh % 201 - 100) / 500
units.append((x, y, c)) if h_colour:
X, Y, C = np.array(units).transpose() 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:
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.scatter(-X, Y, s=2.0, c=C)
plt.savefig('/code/metrics.png') plt.savefig("/code/metrics.png")