This repository contains a Python script that models the cumulative cloud storage usage using an exponential function. The script fits an exponential model to daily usage data and plots the cumulative usage over a period of days.[default= 7 days]
- Python 3.x
- NumPy
- SciPy
- Matplotlib
- Clone the repository:
git clone https://github.com/yourusername/cumulative-cloud-storage-usage.git
- Navigate to the project directory:
cd cumulative-cloud-storage-usage
- Install the required packages:
pip install numpy scipy matplotlib
Run the script to see the cumulative usage plot:
python cumulative_usage_model.py
The script performs the following steps:
Data Preparation:
- Define the number of days and daily usage.
- Calculate the cumulative usage.
Model Definition:
- Define the exponential model for cumulative usage.
Model Fitting:
- Fit the model to the data to determine the parameters π΄ and π.
Plotting:
- Plot the actual cumulative usage and the model's cumulative usage.
In a world overflowing with pay-as-you-go services, such as AWS, Azure, and OCI, you can probably check cumulative metrics... But wouldnβt you like to know the formulas and graphs representing cumulative usage?
(No, it's just that I thought it would make a good Qiita article, not that I always think this way... haha)
Assume cumulative usage of 28 GB over 7 days. Set daily usage as [3, 3, 5, 2, 8, 4, 2]. The goal is to find a function that returns the following values (in GB) for the given number of days. πππ
This is nonlinear. Once you realize itβs not a linear graph, using an exponential function usually works well.
Let the machine handle fitting in the nonlinear function model!πππ
Search for the specific values of the parameter constants (A, k) through fitting.
πΉ(π‘): The integral of daily usage π(π‘) representing cumulative usage (GB)
π(π‘): The derivative of cumulative usage
import numpy as np
from scipy.optimize import curve_fit
import matplotlib.pyplot as plt
# Number of days
days = np.array([1, 2, 3, 4, 5, 6, 7])
# Daily usage
daily_usage = np.array([3, 3, 5, 2, 8, 4, 2])
# Cumulative usage
cumulative_usage = np.cumsum(daily_usage)
# Cumulative usage model
def cumulative_model(t, A, k):
return A * np.exp(k * t) - A
# Fitting
params, covariance = curve_fit(cumulative_model, days, cumulative_usage, p0=[1, 0.1])
A, k = params
print(f"A: {A}, k: {k}")
# Plotting the graph
plt.figure(figsize=(10, 6))
plt.plot(days, cumulative_usage, 'o', label='Cumulative Usage (Observed)')
plt.plot(days, cumulative_model(days, A, k), '-', label='Cumulative Usage (Model)')
plt.xlabel('Days')
plt.ylabel('Cumulative Usage (GB)')
plt.legend()
plt.title(f'Cumulative Usage Model: A={A:.2f}, k={k:.2f}')
plt.grid(True)
plt.show()
π΄=56.14 π=0.0584 π©βπ»π©βπ»π©βπ»
It may look linear due to the small data sample, but it is a nonlinear function. π§βπ»π§βπ»π§βπ»