-
-
Save btwatts/ac1e761e3631cf54fb675afd2e315f09 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 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 = []; | |
jQuery('.s-item').each(function(k,v) | |
{ | |
var iPrice = jQuery(this).find('.s-item__price'); | |
if (iPrice.length == 0) { | |
return; | |
} | |
var myPrice = iPrice.html(); | |
myPrice = jQuery('<div>').html(myPrice).text(); | |
var price = parseFloat(myPrice.trim().replace('$','').replace(',','')); | |
//console.log(price); | |
if (typeof v == 'undefined') { | |
alert('v is undefined'); | |
} | |
var listingId = jQuery(v).closest('li').attr('listingid'); | |
// 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