iTMS Promotion Calculator

Discussion in 'Current Events' started by slughead, Jul 2, 2004.

  1. slughead macrumors 68040


    Apr 28, 2004
    Apple was kind enough to put their counter into javascript so we can all take a look at the current numbers for the store.

    Since Apple is giving away stuff to each 100,000*nth song buyer, and to the 100,000,000 song buyer, I figured I should make a simple linear projection based on the sales of the past few hours, that has a larger base of numbers every 5 minutes.

    Here is the link to the promotion:

    Here is the link to my projection program:

    If you'd like to make your own, or see how this program works, or tweak/correct my half-assed hurried language, here's the program:

    <META HTTP-EQUIV="refresh" content="300;URL=Javascript:document.count.submit()">
    <script src="" language="JavaScript" type="text/javascript"></script> 
    <font face="arial" size="3">
    This page will refresh every 5 minutes, which is when the apple counter refreshes.<Br>
    Refreshing early is not recommended.<Br>
    This uses linear functions, which are not accounting for time of day, trends, or anything like that.<Br>
    Hit this button if you don't see any numbers, otherwise don't.<br>
    The numbers will be most accurate right after the refresh.
    echo '<form method="post" action="'.$_SERVER['PHP_SELF'].'" name="count">
    <script type="text/javascript" language="javascript">
    document.write(\'<input name="counter" type="hidden" value="\' + count() + \'">\');
    <input type="hidden" name="time" value="'.time().'">
    <input type="submit" value="Get Current Amount">
            saveDB("apple.counter",array(array(time(), $_POST['counter'])));
    list($mintime, $minval) = explode("¶¶",file_get_contents("apple.counter"));
    $countdiff = $_POST['counter'] - $minval;
    $timediff = time() - $mintime;
    $num = (int)($_POST['counter'] / 100000);
    $num *= 100000;
    $num += 100000;
    $next100k = $num - $_POST['counter'];
    $to100m = 100000000 - $_POST['counter'];
    $hourstonext100k = (int)($next100k / ($countdiff / (($timediff/60)/60)));
    $hoursto100m = (int)($to100m / ($countdiff / (($timediff/60)/60)));
    $rminstonext100k = ((int)($next100k / ($countdiff / ($timediff/60)))) - ($hourstonext100k * 60);
    $rminsto100m =  ((int)($to100m / ($countdiff / ($timediff/60)))) - ($hoursto100m * 60);
    echo '
    increase/minute: ' . number_format((int)($countdiff / ($timediff/60))).
    increase/hour: ' . number_format((int)($countdiff / (($timediff/60)/60))).
    <b>Time to next 100k ('.number_format($num).'): '.$hourstonext100k.' Hours, '
    .$rminstonext100k.' Minutes</b><br>
    <b>Time to 100m: '.$hoursto100m.' Hours, '.$rminsto100m.' Minutes</b><br>
    Amount at '.date("m/d/y g:i a",$mintime).': '.number_format($minval).'<br>
    Amount at last refresh ('.date("m/d/y g:i a",$_POST['time']).'): ' . number_format($_POST['counter']);
    function saveDB($filename,$dBase)
        $go = TRUE;
        $colsTot = $j;
        $savedata = "";
        for($j=0;$j < count($dBase); $j++)
            if($j != 0 && file_exists($filename))
                $savedata .= "??";
            for($k=0;$k < $colsTot;$k++)
                    $savedata .= $dBase[$j][$k];
                    $savedata .= "¶¶" . $dBase[$j][$k];
        fputs($fp,stripslashes($savedata));		// save log file
    Some of the code was borrowed from one of my other programs, here's how to setup your own:
    1. copy the above code and paste it into anyfile.php
    2. visit the page in your web browser
    3. wait 5 minutes
    4. the past and present numbers should be different now, so it's good to use

    This creates a file "apple.counter" to store the original number, so please put this into a directory it has permissions to add to (chmod -R 777 should do the trick).
  2. slughead thread starter macrumors 68040


    Apr 28, 2004
  3. backspinner macrumors 6502a

    Apr 29, 2002
    well, as you already know, I did... ;)
  4. garybUK Guest


    Jun 3, 2002
    Id like apple to produce some real raw stats, would be interesting to see how many songs each country is buying and when etc.. (obviously without disclosing customer information) data protection act and all that.

Share This Page