Go Back   CodingForums.com > :: Client side development > General web building

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-24-2012, 03:25 AM   PM User | #1
skill3d
New Coder

 
Join Date: Oct 2011
Posts: 25
Thanks: 5
Thanked 1 Time in 1 Post
skill3d is an unknown quantity at this point
Exclamation How do you make an automatic price averager? (Read)

I'm having a bit of an issue, in the real world there's an economy of goods and prices, an ever changing one, The average price on a jar of honey may be $3 today but in 4 days it could be $3.25, everything changes constantly, is there a way where i could do something like this with tables? I want to be able to let users put in what the think a good price for the item would be and it takes the other prices and averages them automatically and displays the price. For example,

I have listed an apple, the starting value of the apple is $3
User 1 thinks the apple is worth around $4
($4 + $3)x .5 = $3.50 (Average cost of an Apple)
This price is now displayed to the community, that the average price of an apple is $3.50, now say another user comes around,
User 2 thinks the apple is somewhere around $2.75
($4 + $3 + $2.75) x .5 = $4.87
Now, the average price of an apple that would be displayed to the community is $4.87, is there something like this that i could use on my website? Whether it is open source or not doesn't matter, something that will check the MySQL databases for previous data and average out the information/prices/data to give an end average price between the submitted prices?

I've been having quite some trouble with this issue, i'm looking to create a price guide for online items in a gaming community, is there an easy way to do this?
skill3d is offline   Reply With Quote
Old 02-24-2012, 01:01 PM   PM User | #2
mlseim
Master Coder

 
mlseim's Avatar
 
Join Date: Jun 2003
Location: Cottage Grove, Minnesota
Posts: 9,046
Thanks: 8
Thanked 1,029 Times in 1,020 Posts
mlseim has a spectacular aura aboutmlseim has a spectacular aura aboutmlseim has a spectacular aura about
Because you don't know how many items there will be, or how many values
are placed on those items, I would think you would have one table in your MySQL
database that stores all of them. Each time someone gives a value to an apple,
it would insert a new line. There could be 50 rows for apples, 30 rows for oranges,
and 100 rows for bananas. You query for a particular item, you know how many
rows it found, and you SUM the values ... now you can determine the average.

If you also add a column with a timestamp, you could query the table for an item
within a certain amount of time (days, months, years). You may want to know the
average price for the apples only during the past month.

That's my take on it anyhow.


.
mlseim is offline   Reply With Quote
Users who have thanked mlseim for this post:
skill3d (02-24-2012)
Old 02-24-2012, 01:25 PM   PM User | #3
Lerura
Regular Coder

 
Lerura's Avatar
 
Join Date: Aug 2005
Location: Denmark
Posts: 869
Thanks: 0
Thanked 112 Times in 111 Posts
Lerura will become famous soon enough
in your example that average goes up after the third entry even if the new entry was lower than the previous average.

You can't just divide the sum by 2 each time a new entry has come in.
Then if the next 97 entries all are $3.50 then you would have average of

(4 + 3 + 2 + 97x3.50)*.5 = 174,63.

You only need to store the number of entries along with the count of entries.

After the first 2 entries .
you will have

EntrySum = 7;
EntryCount = 2;

And then for each new entry:

EntrySum += NewEntry;
EntryCount++;

After the 3 third it would be:

EntrySum = 9.75;
EntryCount = 3;

And then the average would be EntrySum(9.75) / EntryCount(3) = 3.25.

You could for the statistics also store the highest and the lowest entry.

And use:
EntryMax = Max(EntryMax, NewEntry)
EntryMin = Min(EntryMin, NewEntry)
to set the new value

But if you also want to know the what entry was entered most times, then you will need to store each and every entry seperately.
Lerura is offline   Reply With Quote
Users who have thanked Lerura for this post:
skill3d (02-24-2012)
Old 02-24-2012, 02:33 PM   PM User | #4
skill3d
New Coder

 
Join Date: Oct 2011
Posts: 25
Thanks: 5
Thanked 1 Time in 1 Post
skill3d is an unknown quantity at this point
Thank you both very much, hopefully with your replies and some other information on coding this, i'll be able to get it done with-in the next couple days. Your information was very useful. Thanked, -Skill3d
skill3d is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:02 AM.


Advertisement
Log in to turn off these ads.