Rank and Share

From XPUB & Lens-Based wiki
Revision as of 17:21, 10 February 2009 by Michael Murtaugh (talk | contribs) (→‎Approach to this problem)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Rank & Share

http://marketshare.hitslink.com/browser-market-share.aspx?qprid=0

This page will be discussed (& extended) in class.

Approach to this problem

Imagine you are bicycling from Rotterdam to Delft. Along the bike path are kilometer markers. Let's say the marker says 35 at the start of your trip, and 50 when you reach Delft. How far are you on your trip, in terms of percentage (0 to 100), when you reach the sign marked 44?

Well, first you would figure out how far you are from the beginning, or 44-35 = 9 km. And then you would just divide this by the total number of kilometers (or 50 - 25 = 15 km).

9/15 = 0.5999 (or about 60%)

Put in terms of variables, you could write the above as:

scaler = (current_km - start_km) / (end_km - start_km)

Where 'scaler' is a number from 0 (beginning of trip) to 1.0 (reached the end).

Translating to another scale

Once you have the scaler value, it's possible to translate to another range of value by simply reversing the process. In this case, imagine we want to draw a bar to represent our progress on the trip. We want to the bar to be at the smallest 10 pixels wide (for the start) and 200 pixels at the end.

progress_bar_width = 10 + ((200 - 10) * scaler)

or

new_value = new_start + ((new_end - new_start) * scaler))