Smartcollegeai: Automated Python Scripts

Customer Information & Request
Name: Rohan Duhaney
Your magic request: "Write a code snippet to solve "Generate a Python script to automate inventory tracking and health monitoring of data center 10 hardware components." Be creative with fictitious data using python."
Email: smartduhaney@gmail.com

Dear Rohan Duhaney,

# Import necessary libraries
import pandas as pd
import numpy as np

# Create a fictitious data set for hardware components
components = {
    'Component': ['CPU', 'Memory', 'Storage', 'Power Supply', 'Cooling System', 'Network Card', 'Motherboard', 'GPU', 'RAID Controller', 'Chassis'],
    'Inventory': [50, 100, 75, 25, 30, 40, 50, 20, 10, 15],
    'Health': [90, 95, 85, 80, 90, 95, 90, 85, 80, 95]
}

# Convert data set into a pandas DataFrame
df = pd.DataFrame(components)

# Calculate the total inventory count
total_inventory = df['Inventory'].sum()
print("Total Inventory Count: {}".format(total_inventory))

# Calculate the average health of all components
avg_health = df['Health'].mean()
print("Average Health: {}%".format(avg_health))

# Calculate the percentage of components with health above 90%
above_90 = (df['Health'] > 90).sum()
percent_above_90 = (above_90 / len(df)) * 100
print("Percentage of Components with Health Above 90%: {}%".format(percent_above_90))

# Calculate the percentage of components with inventory below 50
below_50 = (df['Inventory'] < 50).sum()
percent_below_50 = (below_50 / len(df)) * 100
print("Percentage of Components with Inventory Below 50: {}%".format(percent_below_50))

# Create a new column to calculate the health to inventory ratio
df['Health to Inventory Ratio'] = df['Health'] / df['Inventory']

# Find the component with the highest health to inventory ratio
highest_ratio = df['Health to Inventory Ratio'].idxmax()
print("Component with Highest Health to Inventory Ratio: {}".format(df['Component'][highest_ratio]))

# Find the component with the lowest health to inventory ratio
lowest_ratio = df['Health to Inventory Ratio'].idxmin()
print("Component with Lowest Health to Inventory Ratio: {}".format(df['Component'][lowest_ratio]))

# Create a bar chart to visualize the health and inventory levels of all components
df.plot.bar(x='Component', y=['Health', 'Inventory'], figsize=(10,6))
plt.xlabel("Component")
plt.ylabel("Count")
plt.title("Component Health and Inventory Levels")
plt.legend()
plt.show()
Back to blog