Tutorials

Growth rate of fanlistings v2

This code snippet will calculate and display the average number of members that a fanlisting gains per day. Now updated so you can use it even if you don’t know what day your fanlisting opened!

If you want to display the average number of members your fanlisting gains per day (the “growth rate” of the fanlisting), you can copy this code into any page with a .php extension:

<?php

// Fill in the year, month, and day that your fanlisting
// opened OR fill in the year, month, and day of today.
$year = 2003;
$month = 9;
$day = 1;

// Fill in the number of members your fanlisting had on
// the day above. If your FL opened on the day above,
// leave this number as 0.
$num_members = 0;

include_once("config.php");
$q_num = mysql_query("SELECT * FROM $table WHERE apr='y'");
$n_num = mysql_num_rows($q_num)-$num_members;
$diff = ((mktime(0,0,0,$month,$day,$year)-mktime(0,0,0,date("m"),date("d"),date("Y")))/86400);
if (abs($diff) == $diff) $diff = abs(ceil($diff));
else $diff = abs(floor($diff));
if ($diff != 0) $avg = $n_num / $diff;
else $avg = 0;
?>

<p>Growth rate: <strong><?=sprintf("%1.3f", $avg)?></strong> members/day</p>

Here’s what you have to do. The first step depends on whether you know the date your fanlisting opened. If you do, use Version 1. If not, use Version 2.

Version 1 – if you know the day your fanlisting opened:
Change the $year, $month, and $day variables to represent the day your fanlisting opened. For example, if your fanlisting opened on August 18, 2003, the $year = 2003, $month = 8, and $day = 18. Do not change the $num_members variable – it should be set to 0.

Version 2 – if you don’t know the day your fanlisting opened:
Change the $year, $month, and $day variables to represent today. For example, if today is October 13, 2003, the $year = 2003, $month = 10, and $day = 13. Also, change the value of the $num_members variable to the number of members your fanlisting has at the moment.

Both versions:
Paste the code into any .php file in the same directory as your fanlisting. That’s it!

You can change the text it displays by editing the last line. At the moment it shows 3 decimal places, but you can change that to another number if you want. See this part on the last line? %1.3f Change the ’3′ there to any other positive number. 0 won’t show any decimal places (rounding up or down as necessary). For example, if you only wanted one decimal place shown, you’d change the last line to this:

<p>Growth rate: <strong><?=sprintf("%1.1f", $avg)?></strong> members/day</p>

Note that the rate really won’t mean much for the next few days, as it doesn’t take into consideration time of day (and thus, in fact, will always show 0.000 on the day you entered, and will show the exact number of members 24 hours later). After a while, it tends to settle in at the actual rate.

Comments

Error Comments are closed for this entry.