43 lines
		
	
	
		
			990 B
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			43 lines
		
	
	
		
			990 B
		
	
	
	
		
			Python
		
	
	
	
	
	
| import gc
 | |
| import json
 | |
| 
 | |
| import matplotlib.pyplot as plt
 | |
| import numpy as np
 | |
| 
 | |
| plt.rcParams["figure.figsize"] = [18, 9]
 | |
| plt.style.use("dark_background")
 | |
| plt.subplots_adjust(left=0.05, right=0.99, top=0.95, bottom=0.05)
 | |
| 
 | |
| 
 | |
| 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)
 | |
| 
 | |
| 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
 | |
|     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:
 | |
|     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")
 |