diff --git a/apps/webapp/app/components/billing/UsageBar.tsx b/apps/webapp/app/components/billing/UsageBar.tsx index 918e85009..08a8f2c55 100644 --- a/apps/webapp/app/components/billing/UsageBar.tsx +++ b/apps/webapp/app/components/billing/UsageBar.tsx @@ -1,57 +1,83 @@ import { cn } from "~/utils/cn"; import { Paragraph } from "../primitives/Paragraph"; -//data -const numberOfCurrentRuns = 120_000; -const tierRunLimit = 100_000; -const billingLimit = 100 / 0.00125; // $100 spend limit divided by the cost per run (80,000 runs) -const projectedRuns = 10_000; +type UsageBarProps = { + numberOfCurrentRuns: number; + billingLimit: number; + tierRunLimit: number; + projectedRuns: number; +}; -//create a maximum range for the progress bar -const getLargestNumber = Math.max(numberOfCurrentRuns, tierRunLimit, billingLimit, projectedRuns); -const maxRange = Math.round(getLargestNumber * 1.15); -console.log("Max range:", maxRange); +export function UsageBar({ + numberOfCurrentRuns, + billingLimit, + tierRunLimit, + projectedRuns, +}: UsageBarProps) { + //create a maximum range for the progress bar + const getLargestNumber = Math.max(numberOfCurrentRuns, tierRunLimit, billingLimit, projectedRuns); + const maxRange = Math.round(getLargestNumber * 1.15); -//convert numberOfCurrentRuns runs into a percentage and calculate the exceeded amount -let progressAsPercent = (numberOfCurrentRuns / tierRunLimit) * 100; // get current runs as a percentage -let currentProgress = Math.max(tierRunLimit, progressAsPercent); // set the current progress to the larger of the two -currentProgress = Math.min(progressAsPercent, 100); // set the current progress to a maximum of 100% -const exceededProgress = (numberOfCurrentRuns / tierRunLimit) * 100; // get the exceeded number of runs as a percentage + //convert the freeRunLimit into a percentage + const tierRunLimitPercentage = Math.round((tierRunLimit / maxRange) * 100); -//Todo this code is correct but the calculations above mean the exceeded progress bar can still push over 100% -//find the overall progress as a percentage of the maxRange -const exceededProgressAsRuns = Math.max(0, numberOfCurrentRuns - tierRunLimit); // get the exceeded number of runs -let overallProgress = Math.round(((numberOfCurrentRuns + exceededProgressAsRuns) / maxRange) * 100); // get the overall progress as a percentage of the maxRange -overallProgress = Math.min(progressAsPercent, 100); // set the overall progress to a maximum of 100% -console.log("number of current runs:", numberOfCurrentRuns); -console.log("Exceeded Progress as Run count:", exceededProgressAsRuns); -console.log("Overall progress:", overallProgress); + //convert the projectedRuns into a percentage + const projectedRunsPercentage = Math.round((projectedRuns / maxRange) * 100); -//convert the freeRunLimit into a percentage -const freeRunLimit = Math.round((tierRunLimit / maxRange) * 100); + //convert the BillingLimit into a percentage + const billingLimitPercentage = Math.round((billingLimit / maxRange) * 100); -export function UsageBar() { + const usagePercentage = Math.round((numberOfCurrentRuns / maxRange) * 100); + + const usageCappedToLimitPercentage = Math.min(usagePercentage, tierRunLimitPercentage); return ( -