metrobalderas
metrobalderas

Reputation: 5240

Formula for popularity by day?

I've got an app that's basically a calendar, the users can enter events for each day. Now I have to find the best way to show the calendar for a full month while highlighting the busiest days.

Obviously the color is the choice here, but I'm wondering how you guys would do it. I have brainstormed the following:

However, I'm not sure this would be the best way to solve this. Both are linear and the first could mess the things quite a bit if our average is about 20 and the maximum had 100 events, just two colors will be showing up.

I'm no statician, but I think this problem could be solved with percentiles and quartiles, but I'm not really sure how to implement it.

Thanks.

Upvotes: 3

Views: 167

Answers (2)

meze
meze

Reputation: 15087

I would suggest an algorithm for a logarthmic distribution which is often used for building tag clouds. Tags are your days, counts of tags are the number of events for a day.

A good implementation for PHP and Python (not checked it properly yet) seems to be this one. Here's an example:

$tags = array(
    array('tag'   => 1,
          'count' => 10),
    array('tag'   => 2,
          'count' => 30),
    array('tag'   => 3,
          'count' => 5),
    array('tag'   => 4,
          'count' => 5));
$colours = array('green', 'yellow', 'red');
foreach(tagcloud($tags, 0, count($colours) - 1, 0) as $d) {
  echo  '<div style="background-color:' . $colours[floor($d['size'])] . '">Day: '.$d['tag'].' Events: '.$d['count'].'</div>';
}

Upvotes: 1

dfb
dfb

Reputation: 13289

A few ideas:

  1. Ensure an even distribution of colors: Order the N events/day and assign an equal number of days to each color
  2. Map the N events/day to a value in a continuous color range instead of using discrete buckets. For example, 0 to max(events) to an RGB value.
  3. Find a non-linear distribution - e.g., normal, exponential, etc. The formula you're looking for is the CDF (see http://en.wikipedia.org/wiki/Cumulative_distribution_function) which can be used to convert the number of events/day to a percentile.

Upvotes: 0

Related Questions