Dynamic website gauge image?

Community Forums/General Help/Dynamic website gauge image?

Yahfree(Posted 2010) [#1]
Hey! I'm working on a website project right now. My client wants a "temperature gauge" to represent how hot an item he's selling is. He wants it to be a image--think basic vector art--that will change based on a value I feed it(A float or integer). I'm thinking of a thermometer that fills up and gets progressively redder- or bluer depending on how hot the item is. The image--or the browser-- will display the temperature number next to or on it. The temperature will be calculated on the fly from a number grabbed from the database(number of comments, reviews, etc)

What should I use to accomplish this? Surely it can be done in some javascript, but what about browser issues if they have it disabled? Is there a way to generate something this complicated with php without major speed issues?


CASO(Posted 2010) [#2]
A javascript solution is significantly more elegant than a php (image) one. I do not see why you would need to factor for javascript disabled when you are exactly aware of who the client is.

However, if you are totally against using javascript for some reason...you could use php to merely inject the necessary end code (css/image src) upon load.

Note: If using images, point to pre-generated images if possible (image generation is slow and puts a load on a webserver).


Yahfree(Posted 2010) [#3]
I have no idea where to start though. How would I grab a number out of a mysql table, then use it somehow to produce this gauge?


xlsior(Posted 2010) [#4]
amazon gives you a sales rank under each item, e.g. "#148,267 in Books"

You may want to consider a small number of variations, e.g. just 5 or 10 steps, and have pre-made graphics for these states.

You'd need to keep track of the number of sales / sales rank, compare the rank with the total number of items for sale, and if it's in the top 10% you have your "hot" image, if it's in the bottom 10% have your "cold" image, and use the in-bewteeen values accordingly.

You'll have to make some decisions on how often you want to determine ranks: over the life of the website, or just over the past -x- days/weeks/months?
This is significant, or you may have an item that sold like crazy 6 years ago show up as "hot", even if you haven't sold a single one for the past 5 years.

Anyway, you'd probably need an automated process that periodically tallies the popularity of the various products, rank them, and store the results in a database table. Depending on your hosting providers abilities, you could possible do this as a scheduled SQL stored procedure, or a scheduled (cron job) that calls a PHP/ASP/whatever page that runs the necessary database queries and updates.

It'd probably be too slow to do it real-time for each query, unless you have just a small number of products)

If you have a salesrank in the DB, you can query this value at the same time that you display the products, and can do a determination of how "hot" the product is (and what image it deserves) at the same time on the serversize, in PHP/ASP/Whatever.


Yahfree(Posted 2010) [#5]
That's a good idea. I have the temperature value(or rather, i can calculate it from the number of whatever from the database) and then I can use a switch statement in php to decide which image to display for different temperature ranges.