Skip to content

Instantly share code, notes, and snippets.

@VirtuosiMedia
Created April 6, 2016 21:54
Show Gist options
  • Save VirtuosiMedia/7a6cd8c97cbe14b13b78948029721b13 to your computer and use it in GitHub Desktop.
Save VirtuosiMedia/7a6cd8c97cbe14b13b78948029721b13 to your computer and use it in GitHub Desktop.
/**
* 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