The Budget Calculator project is a .NET application designed to calculate the maximum budget for a specific ad within a total campaign budget, using the Goal Seek algorithm. The application allows users to determine how much budget can be allocated to a single ad while ensuring the total campaign budget remains within an approved amount.
- Calculate Maximum Ad Budget: Determine the maximum budget for a specific ad while keeping the total campaign budget within the approved amount.
- Goal Seek Algorithm: Utilizes a binary search method to find the optimal budget allocation.
- Unit Testing: Includes comprehensive unit tests to ensure the accuracy and reliability of the calculations.
- .NET Core: Framework for building the application.
- xUnit: Testing framework used for unit testing.
- ASP.NET Core MVC: Web framework for building the user interface.
Z = X + Y1 * X + Y2 * (X1 + X2 + ... + Xi) + HOURS
The formula used to calculate the total campaign budget Z is:
Where:
Xis the total ad spend.Y1is the agency fee percentage.Y2is the third-party tool fee percentage.X1,X2,Xiare the budgets for individual ads.HOURSis the fixed cost for agency hours.
In the context of the application:
Xis split intoX_target(budget for the specific ad) andOtherAdsBudget(budget for other ads).Y1andY2are percentages that apply toXand the sum of all ad budgets, respectively.HOURSremains a fixed cost.
Find more details at original prompt here.
To find the maximum budget for the specific ad, we use a binary search algorithm. This approach is used to iteratively adjust the budget for the specific ad until the total budget Z does not exceed the approved amount.
- Initialize Variables: Set the initial low and high bounds for the binary search range.
- Calculate Midpoint: Compute the midpoint of the current range.
- Calculate Total Cost: Using the midpoint value, compute the total cost using the formula.
- Adjust Range: If the total cost is less than the approved budget
Z, adjust the low bound. Otherwise, adjust the high bound. - Repeat: Continue adjusting the range until the difference between the high and low bounds is within a specified tolerance.
- BudgetCalculator: Main project containing the business logic and controllers.
Services/BudgetService.cs: Contains theBudgetServiceclass with the Goal Seek algorithm.Controllers/BudgetController.cs: Handles user input and interacts with theBudgetService.Views/Budget/Index.cshtml: View for user interaction.
- BudgetCalculator.Tests: Test project containing unit tests for the
BudgetService.BudgetServiceTests.cs: Contains unit tests for theGoalSeekmethod.
This application is deployed to Azure App Service, which provides a scalable and managed environment for hosting web applications. To access the deployed application, follow these steps: Go to BudgetCalculatorJu
- .NET Core SDK (version 6.0)
- A code editor like Visual Studio, Visual Studio Code, or JetBrains Rider
-
Clone the Repository
git clone https://github.com/c20chin/BudgetCalculator.git cd BudgetCalculator -
Navigate to the project directory and restore the dependencies:
dotnet restore
-
Build the solution to ensure everything is set up correctly:
dotnet build
-
Run the application:
dotnet run --project BudgetCalculator
-
Open a web browser and navigate to http://localhost:5000 to use the application.
-
Navigate to the Application
-
Open a web browser and go to http://localhost:5000.(or your setup localhost)
-
Input Data
- Total Budget (Z): Enter the approved total budget for the campaign.
- Agency Fee Percentage (Y1): Enter the agency fee percentage.
- Third-Party Tool Fee Percentage (Y2): Enter the third-party tool fee percentage.
- Fixed Costs (HOURS): Enter the fixed costs for agency hours.
- Budget for Other Ads: Enter the budget for other ads.
- Submit Click the "Calculate" button to determine the maximum budget for the specific ad.
To ensure the application is working correctly, run the unit tests:
- Navigate to the Test Project
cd BudgetCalculator.Tests- Run the Tests
dotnet testThis will execute all the unit tests and display the results.