Archived
74 lines
2.2 KiB
Python
74 lines
2.2 KiB
Python
import json
|
|
import matplotlib.pyplot as plt
|
|
import numpy as np
|
|
|
|
def print_info(name, data):
|
|
# Convert the list to a NumPy array
|
|
data_np = np.array(data)
|
|
|
|
# Calculate basic statistics
|
|
mean = np.mean(data_np)
|
|
median = np.median(data_np)
|
|
std_dev = np.std(data_np)
|
|
variance = np.var(data_np)
|
|
min_val = np.min(data_np)
|
|
max_val = np.max(data_np)
|
|
sum_val = np.sum(data_np)
|
|
|
|
# Calculate percentiles
|
|
percentile_25 = np.percentile(data_np, 25)
|
|
percentile_50 = np.percentile(data_np, 50) # This is the same as the median
|
|
percentile_75 = np.percentile(data_np, 75)
|
|
percentile_90 = np.percentile(data_np, 90)
|
|
|
|
# Print the results
|
|
print(f"\n\nDescriptive Statistics for {name}:")
|
|
print(f"Mean: {mean}")
|
|
print(f"Median: {median}")
|
|
print(f"Standard Deviation: {std_dev}")
|
|
print(f"Variance: {variance}")
|
|
print(f"Minimum: {min_val}")
|
|
print(f"Maximum: {max_val}")
|
|
print(f"Sum: {sum_val}")
|
|
print("\nPercentiles:")
|
|
print(f"25th Percentile: {percentile_25}")
|
|
print(f"50th Percentile (Median): {percentile_50}")
|
|
print(f"75th Percentile: {percentile_75}")
|
|
print(f"90th Percentile: {percentile_90}")
|
|
|
|
|
|
with open('output.json', 'r') as f:
|
|
json_data = json.load(f)
|
|
|
|
# print(len(data))
|
|
downloaded = [plugin["downloaded"] for plugin in json_data]
|
|
rating = [plugin["rating"] for plugin in json_data]
|
|
active_installs = [plugin["active_installs"] for plugin in json_data]
|
|
num_ratings = [plugin["num_ratings"] for plugin in json_data]
|
|
|
|
print_info("downloaded", downloaded)
|
|
print_info("rating", rating)
|
|
print_info("active_installs", active_installs)
|
|
print_info("num_ratings", num_ratings)
|
|
|
|
# plt.hist(downloaded, bins=500, log=True)
|
|
# plt.show()
|
|
fig, axs = plt.subplots(nrows=2, ncols=2, figsize=(8, 6))
|
|
axs[0,0].hist(downloaded, bins=100, log=True)
|
|
axs[0,0].set_title("Distribution of downloaded")
|
|
|
|
axs[0,1].hist(rating, bins=20, log=True)
|
|
axs[0,1].set_title("Distribution of rating")
|
|
|
|
axs[1,0].hist(active_installs, bins=10, log=True)
|
|
axs[1,0].set_title("Distribution of active_installs")
|
|
|
|
axs[1,1].hist(num_ratings, bins=100, log=True)
|
|
axs[1,1].set_title("Distribution of num_ratings")
|
|
|
|
# Add labels and title
|
|
# plt.xlabel("Value")
|
|
# plt.ylabel("Frequency (log)")
|
|
|
|
# Display the plot
|
|
plt.show() |