Last active
February 18, 2022 06:30
-
-
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.
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
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); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This no longer works. You can use mine (admittedly it is not as elegant).