import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.ticker import MaxNLocator

# Load the data
df = pd.read_csv('../data/resources.txt', sep='\s+')

# 1M
df = df[df['CPU'] == 32]
df = df[df['Mem'] == 32]

# df1 based on max CPU
df1 = df
df1['util'] = df['maxCPU']/df['CPU']*100
df1 = df1[df1['util'] <= 100]

# df2 based on 99.9% CPU
df2 = df
df2['util'] = df['999CPU']/df['CPU']*100


# create 2 sub plots
fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(12, 8))


# ax1 
counts1, bins1 = np.histogram(df1['util'], bins=30)
ax1.barh(bins1[:-1], counts1, height=((bins1[1]-bins1[0])/2))
#ax1.barh(bins1[:-1], counts1, height=1)

# ax2
counts2, bins2 = np.histogram(df2['util'], bins=30)
ax2.barh(bins2[:-1], counts2, height=((bins2[1]-bins2[0])/2))
#ax2.barh(bins2[:-1], counts2, height=1)

# Add titles and labels
fig.suptitle('Distribution of 1M tenants')

ax1.set_ylim([0, 80])
ax1.set_xlim([0, 50])
ax1.xaxis.set_major_locator(MaxNLocator(integer=True))
ax1.set_title('based on max CPU utilization')
ax1.set(ylabel='CPU Utilization')
ax1.set(xlabel='Number of Tenants')

ax2.set_ylim([0, 80])
ax2.set_xlim([0, 50])
ax2.xaxis.set_major_locator(MaxNLocator(integer=True))
ax2.set_title('based on 99.9% CPU utilization')
ax2.set(xlabel='Number of Tenants')

# Save the plot as a PNG file
fig.savefig('../img/cpu1M.png')

# Show the plot
fig.show()

