Created
January 24, 2020 12:16
-
-
Save convexhull/5186e326c2b28006a067f73ccd9f6418 to your computer and use it in GitHub Desktop.
file for testing deepdive business model functionality
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const testJSON = require('./testCases/test1'); | |
| const arrSum = function(arr){ | |
| return arr.reduce(function(a,b){ | |
| return a + b | |
| }, 0); | |
| } | |
| const totalRevenue = []; | |
| const totalCustomers = []; | |
| const revenueCalculator = (input) => { | |
| input.customerGrowth /= 100; | |
| input.persistence /= 100; | |
| if(input.subscriptionService && !input.anyAdditionalPurchase){ | |
| input.units = 0; | |
| input.unitPrice = 0; | |
| } | |
| if(!input.subscriptionService){ | |
| input.persistence = 0; | |
| input.subscriptionPrice = 0; | |
| input.anyAdditionalPurchase = 0; // this should not be 0 . Confirm from titash! | |
| } | |
| let fullMarketRevenue = 0; | |
| let annualRevenueFromSubscription = 0; | |
| let annualRevenueFromOtherSales = 0; | |
| for(let j = 1; j <= input.totalMonths; j++) { | |
| let multiplier = 0; | |
| for(let i = 0; i < j; i++) { | |
| multiplier += Math.pow(input.persistence,i); | |
| } | |
| // console.log(`Multiplier after ${j} th month : `, multiplier); | |
| totalCustomers[j-1] = Math.floor(input.newCustomers*Math.pow((1+input.customerGrowth),j-1)*multiplier); | |
| let monthlyRevenueFromSubscription = (input.subscriptionService*totalCustomers[j-1]*input.subscriptionPrice); | |
| let monthlyRevenueFromOtherSales = totalCustomers[j-1]*input.unitPrice*input.units; | |
| totalRevenue[j-1] = Math.round(monthlyRevenueFromSubscription + monthlyRevenueFromOtherSales); | |
| annualRevenueFromSubscription += monthlyRevenueFromSubscription; | |
| annualRevenueFromOtherSales += monthlyRevenueFromOtherSales; | |
| console.log(`subscript revenue for ${j} th month : `, monthlyRevenueFromSubscription); | |
| console.log(`other sales revenue for ${j} th month : `, monthlyRevenueFromOtherSales); | |
| } | |
| fullMarketRevenue = (input.totalMarketSize*input.units*input.unitPrice*input.totalMonths)+(input.subscriptionService*input.subscriptionPrice*input.totalMonths); | |
| console.log("Total customers : " , totalCustomers) | |
| console.log("Monthwise revenue : " , totalRevenue) | |
| console.log("Total Annual Revenue : " , arrSum(totalRevenue)) | |
| console.log("Full market Revenue : " , fullMarketRevenue) | |
| console.log("Annual revenue from subscription : ", annualRevenueFromSubscription); | |
| console.log("Annual revenue from other sales : ", annualRevenueFromOtherSales); | |
| } | |
| const costCalculator = (input) => { | |
| let fixedCosts = 0; | |
| input.employees.forEach( (element) => { | |
| fixedCosts += (element.required ? element.salary : 0); | |
| }); | |
| input.otherExpenses.forEach( (element) => { | |
| fixedCosts += (element.required ? element.cost : 0); | |
| }) | |
| let spreadFixedCosts = fixedCosts/input.totalMonths; | |
| let totalCosts = []; | |
| let totalCustomers = []; | |
| let annualRevenue = 0; | |
| let annualCosts = 0; | |
| let annualProfit = 0; | |
| let annualCustomerAcquisitionCost = 0; | |
| let annualProductionCost = 0; | |
| for(let j = 1; j <= input.totalMonths; j++){ | |
| let multiplier = 0; | |
| for (let i = 0; i < j; i++) { | |
| multiplier += Math.pow(input.persistence,i); | |
| } | |
| // console.log(`multiplier after ${j} th month`, multiplier); | |
| totalCustomers[j-1] = Math.floor(input.newCustomers*Math.pow((1+input.customerGrowth),j-1)*multiplier); | |
| let monthlyCustomerAcquisitionCost = (input.newCustomers*Math.pow((1+input.customerGrowth),j-1)*input.customerAcquisition); | |
| let monthlyProductionCost = input.anyAdditionalPurchase*(totalCustomers[j-1]*input.unitCost*input.units); | |
| totalCosts[j-1] = Math.round(monthlyCustomerAcquisitionCost + spreadFixedCosts + monthlyProductionCost); | |
| annualCustomerAcquisitionCost += monthlyCustomerAcquisitionCost; | |
| annualProductionCost += monthlyProductionCost; | |
| console.log(`customer acquisition cost for ${j} th month : `, monthlyCustomerAcquisitionCost); | |
| console.log(`production cost for ${j} th month : `, monthlyProductionCost); | |
| } | |
| annualRevenue = arrSum(totalRevenue); | |
| annualRevenue = annualRevenue.toFixed(2); | |
| annualCosts = arrSum(totalCosts); | |
| annualCosts = annualCosts.toFixed(2); | |
| annualProfit = annualRevenue-annualCosts; | |
| annualProfit = annualProfit.toFixed(2); | |
| console.log("Total Annual Revenue", annualRevenue); | |
| console.log("Monthwise customers : " , totalCustomers) | |
| console.log("Monthwise costs : ", totalCosts) | |
| console.log("Annual Production Cost : ", annualProductionCost); | |
| console.log("Annual Customer Acquistion Cost : ", annualCustomerAcquisitionCost); | |
| console.log("Total Annual Cost : ", annualCosts); | |
| if(annualProfit > 0){ | |
| console.log("Total Annual Profit : ", annualProfit) | |
| console.log("Profit to Revenue Ratio" , Math.round(100*(annualProfit/annualRevenue).toFixed(2)), '%'); | |
| } | |
| else { | |
| console.log("Total Annual Loss : ", -1 * annualProfit) | |
| console.log("Loss to Revenue Ratio" , Math.round(-1*100*(annualProfit/annualRevenue).toFixed(2)), '%'); | |
| } | |
| } | |
| (function(){ | |
| revenueCalculator(testJSON); | |
| console.log("*************************************************"); | |
| costCalculator(testJSON); | |
| })(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module.exports = { | |
| "newCustomers" : 1000, | |
| "customerGrowth" : 10, | |
| "subscriptionService" : 1, | |
| "subscriptionPrice" : 30, | |
| "unitPrice" : 40, | |
| "units" : 50, | |
| "totalMarketSize" : 1, | |
| "totalMonths" : 12, | |
| "customerAcquisition" : 508, | |
| "anyAdditionalPurchase" : 1, // according to current bot logic, this is to be 1 in only one case : subscription type model and additional purchases present. in any other case it is 0. ~~~~~!!!!! Confirm from Titash, if non-subs -> this should be 1. Now we make it zero. | |
| "unitCost" : 81, | |
| "persistence" : 40, | |
| "employees" : [ | |
| { | |
| "position" : "CEO", | |
| "required" : 1, | |
| "salary" : 75000 | |
| }, | |
| { | |
| "position" : "software developer", | |
| "required" : 1, | |
| "salary" : 100000 | |
| }, | |
| { | |
| "position" : "product manager", | |
| "required" : 0, | |
| "salary" : 107000 | |
| }, | |
| { | |
| "position" : "data scientist", | |
| "required" : 0, | |
| "salary" : 101000 | |
| }, | |
| { | |
| "position" : "sales and marketing director", | |
| "required" : 0, | |
| "salary" : 97000 | |
| } | |
| ], | |
| "otherExpenses" : [ | |
| { | |
| "type" : "rent", | |
| "required" : 1, | |
| "cost" : 33000 | |
| }, | |
| { | |
| "type" : "advertising and marketing", | |
| "required" : 0, | |
| "cost" : 2500 | |
| }, | |
| { | |
| "type" : "website", | |
| "required" : 0, | |
| "cost" : 480 | |
| }, | |
| { | |
| "type" : "computer and office supplies", | |
| "required" : 0, | |
| "cost" : 7500 | |
| }, | |
| { | |
| "type" : "insurance", | |
| "required" : 0, | |
| "cost" : 1200 | |
| } | |
| ] | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment