zhang qiao
Upload folder using huggingface_hub
49ba314
import matplotlib.pyplot as plt
plt.rcParams['font.size'] = '18'
class GradioFns():
def __init__(self) -> None:
pass
def format__inv_recom_df(self, inv_recom_df, inv_input_df):
inv_recom_df_cp = inv_recom_df.copy()
inv_recom_df_cp['revenue'] = 0
inv_recom_df_cp['cost'] = 0
# inv_recom_df_cp['margin'] = 0
inv_recom_df_cp['margin (%)'] = 0
inv_recom_df_cp['space_usage'] = 0
for i, row in inv_recom_df_cp.iterrows():
# print('row', row)
sku = row['SKU']
cost = float(inv_input_df[inv_input_df['SKU'] == sku]['cost'])
price = float(inv_input_df[inv_input_df['SKU'] == sku]['price'])
space = float(inv_input_df[inv_input_df['SKU']
== sku]['space_per_unit'])
margin = float(row['expected_sales'] * (price - cost))
revenue = row['expected_sales'] * price
inv_recom_df_cp.at[i, 'revenue'] = revenue
inv_recom_df_cp.at[i, 'cost'] = row['expected_sales'] * cost
# inv_recom_df_cp.at[i, 'margin'] = margin
if revenue > 0:
inv_recom_df_cp.at[i, 'margin (%)'] = round(
(margin / revenue) * 100, 2)
inv_recom_df_cp.at[i,
'space_usage'] = row['expected_sales'] * space
return inv_recom_df_cp
def plot__inv_res(self, inv_res, storage, budget, inv_recom_df):
fig, ax = plt.subplots(1, 3, figsize=(24, 7))
space_left = storage - inv_res['total_capacity_usage']
space_left = 0 if space_left < 0 else space_left
space_labels = [
f'{row["SKU"]}\n{row["space_usage"]}' for idx, row in inv_recom_df.iterrows()]
ax[0].pie([space_left] + inv_recom_df['space_usage'].tolist(),
labels=[
f'Storage Left\n{ int(space_left)}'] + space_labels,
autopct='%.0f%%')
cost_left = budget - inv_res['total_budget_usage']
cost_left = 0 if cost_left < 0 else cost_left
cost_labels = [
f'{row["SKU"]}\n{row["cost"]}' for idx, row in inv_recom_df.iterrows()]
ax[1].pie([cost_left] + inv_recom_df['cost'].tolist(),
labels=[f'Budget Left\n{int(cost_left)}'] + cost_labels,
autopct='%.0f%%')
ax[2].bar(inv_recom_df['SKU'],
inv_recom_df['inventory_level'], width=0.3)
ax[0].set_title('Forecasted Storage Space Usage')
ax[1].set_title('Costs')
ax[2].set_title('Forecasted Inventory Level')
fig.tight_layout()
return fig
def plot__rm_res(self, inv_res, storage, budget, inv_recom_df):
fig, ax = plt.subplots(1, 3, figsize=(24, 7))
space_left = storage - inv_res['total_capacity_usage']
space_left = 0 if space_left < 0 else space_left
space_labels = [
f'{row["SKU"]}\n{row["space_usage"]}' for idx, row in inv_recom_df.iterrows()]
ax[0].pie([space_left] + inv_recom_df['space_usage'].tolist(),
labels=[
f'Storage Left\n{ int(space_left)}'] + space_labels,
autopct='%.0f%%')
cost_left = budget - inv_res['total_budget_usage']
cost_left = 0 if cost_left < 0 else cost_left
cost_labels = [
f'{row["SKU"]}\n{row["cost"]}' for idx, row in inv_recom_df.iterrows()]
ax[1].pie([cost_left] + inv_recom_df['cost'].tolist(),
labels=[f'Budget Left\n{int(cost_left)}'] + cost_labels,
autopct='%.0f%%')
ax[2].bar(inv_recom_df['SKU'],
inv_recom_df['inventory_level'], width=0.3)
ax[0].set_title('Forecasted Storage Space Usage')
ax[1].set_title('Raw Material Costs')
ax[2].set_title('Forecasted Raw Material Inventory Level')
fig.tight_layout()
return fig
def plot__wip_res(self, inv_res, storage, budget, inv_recom_df):
fig, ax = plt.subplots(1, 3, figsize=(24, 7))
space_left = storage - inv_res['total_capacity_usage']
space_left = 0 if space_left < 0 else space_left
space_labels = [
f'{row["SKU"]}\n{row["space_usage"]}' for idx, row in inv_recom_df.iterrows()]
ax[0].pie([space_left] + inv_recom_df['space_usage'].tolist(),
labels=[
f'Capacity Left\n{ int(space_left)}'] + space_labels,
autopct='%.0f%%')
cost_left = budget - inv_res['total_budget_usage']
cost_left = 0 if cost_left < 0 else cost_left
cost_labels = [
f'{row["SKU"]}\n{row["cost"]}' for idx, row in inv_recom_df.iterrows()]
ax[1].pie([cost_left] + inv_recom_df['cost'].tolist(),
labels=[f'Budget Left\n{int(cost_left)}'] + cost_labels,
autopct='%.0f%%')
ax[2].bar(inv_recom_df['SKU'],
inv_recom_df['inventory_level'], width=0.3)
ax[0].set_title('Forecasted WIP Capacity Usage')
ax[1].set_title('WIP Costs')
ax[2].set_title('WIP Level')
fig.tight_layout()
return fig