Created
April 6, 2016 21:54
-
-
Save VirtuosiMedia/7a6cd8c97cbe14b13b78948029721b13 to your computer and use it in GitHub Desktop.
This file contains 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
/** | |
* Gets the average sales price for a good from all entities that are selling it. | |
* @param {int} holdingId The holding id. | |
* @param {string} good The good id. | |
* @return {numeric} The average sales price for the good. | |
*/ | |
getAverageGoodSalesPrice: function(holdingId, good){ | |
var numSellers = 1; | |
var totalPrice = this.getGoodBasePrice(good); | |
jg.data.holdings.each(function(holding){ | |
if (holding.data.id !== holdingId){ //Prevent local price manipulation | |
var sales = holding.data.economic.trade.sales; | |
if (sales.hasKey(good)){ | |
totalPrice += sales[good].price; | |
numSellers++; | |
} | |
} | |
}); | |
var averagePrice = totalPrice/numSellers; | |
return averagePrice; | |
}, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment