Skip to content

Instantly share code, notes, and snippets.

@danomoseley
Last active February 18, 2022 06:30
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save danomoseley/5889331 to your computer and use it in GitHub Desktop.
Save danomoseley/5889331 to your computer and use it in GitHub Desktop.
Find an average sold price of an eBay search.Do a search for a product, check the "Sold listings" option under "Show only" in the left navigation.Run this script by pasting it into the console tab of the chrome developer tools.
function Stats(arr) {
var self = this;
var theArray = arr || [];
//http://en.wikipedia.org/wiki/Mean#Arithmetic_mean_.28AM.29
self.getArithmeticMean = function() {
var sum = 0, length = theArray.length;
for(var i=0;i<length;i++) {
sum += theArray[i];
}
return sum/length;
}
//http://en.wikipedia.org/wiki/Standard_deviation
self.getStandardDeviation = function() {
var arithmeticMean = this.getArithmeticMean();
var sum = 0, length = theArray.length;
for(var i=0;i<length;i++) {
sum += Math.pow(theArray[i]-arithmeticMean, 2);
}
return Math.pow(sum/length, 0.5);
}
self.setArray = function(arr) {
theArray = arr;
return self;
}
self.getArray = function() {
return theArray;
}
return self;
}
var listings = {};
var soldPrices = [];
$('.bidsold').each(function(k,v)
{
if ($(this).find('.sboffer').length > 0) {
return;
}
var listingId = $(v).closest('li').attr('listingid');
var price = parseFloat($(v).html().trim().replace('$','').replace(',',''));
listings[listingId] = {
'price': price,
'total': price
};
soldPrices.push(price);
});
//console.log(listings);
//console.log(soldPrices);
var stat = Stats(soldPrices);
var mean = stat.getArithmeticMean().toFixed(2);
var stdDev = stat.getStandardDeviation().toFixed(2);
var message = 'Mean: $' + mean + '\n';
message += 'Standard Deviation: $' + stdDev + '\n';
var goodDeal = 0.5;
message += 'Mean minus ' + goodDeal*100 + '% standard deviation (good deal): $' + (mean - (stdDev*goodDeal)).toFixed(2) + '\n';
message += 'Mean minus one standard deviation (great deal): $' + (mean - stdDev).toFixed(2);
alert(message);
@deltabravozulu
Copy link

deltabravozulu commented Feb 18, 2022

This no longer works. You can use mine (admittedly it is not as elegant).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment