Contar y filtrar por IP y Timestamp visitas almacenadas en una DB [Solucionado]

Como ya relaté en otro hilo, tengo un Proyecto de CMS que no utiliza un Motor de Base de datos para los contenidos. Pero ahora tengo un subproyecto especial que, pro escalabilidad, almacena los datos en una DB.

Al grano, quiero contar las visitas de las páginas.
Hay varios métodos para contar las visitas de una página determinada. En este caso almacenarlas en una base de datos. Recuperar esos datos y contar las filas, evidentemente es sencillo, pero a la hora de filtrar por IP y Timestamp, la cosa se pone fea...

Tengo en consideración dos campos, `ip` y `timestamp`. Ahi debo filtrar las visitas, PERO, los accesos que se hayan hecho en la última hoa y NO considerar las visitas que se hicieron dentro de 3600 segundos tras el último registro.

<?php
$sql
= "SELECT `ip`,`timestamp` FROM `reads` WHERE `section` ='$section'";
$result = mysql_query($sql);
$rows = mysql_fetch_assoc($result);

var_dump($rows);
?>

Array(3){
[0]=>
string(9) "127.0.0.1"
string(8) "00000000"
[1]=>
string(9) "127.0.0.1"
string(8) "00000000"
[2]=>
string(9) "127.0.0.1"
string(8) "00000000"
}

Hasta ahi todo bien. Puedo usar simplemente contar las visitas absolutas. Si quiero filtar por IP:

<?php
foreach($rows as $row){
 
$ip = $row['ip'];
 
$rows_filtered[][$ip] = strtotime($row['timestamp']);
}
var_dump($rows_filtered);
?>

En resumen, lo que quiero es considerar las visitas de una sola IP, sin considerar las visitas siguientes dentro de una hora. Estoy buscando formas, pero quisiera que algún programador más experimentado (no sólo en PHP) me diera algunas pistas sobre como obtener finalmente esos datos.

Mientras seguiré buscando e investigando.

Era tan fácil ¬¬

Es que en ese entonces estaba tan cansado y ebrio tras tantas fiestas pero ahora más lúcido descubrí como:

<?php
function get_points($author,$book = null,$already_checked = false){

    global $db, $user_admin;
   
   
// Avoid to perform the checks if them already has been done.
   
if($already_checked === true){

        // Get the IF form the Author, or check if exist.
       
$author = get_id_by_user($author);
        if(empty(
$author)) return false;
   
       
settype($author,'int');

        // Check if Book exist, and if is String, get their ID.
       
if(!empty($book)){
            if(
is_numeric($book)) $sql_check = "SELECT `id` FROM `book_books` WHERE `id` = $book AND `author` = $author LIMIT 1";
            elseif(
is_string($book)) $sql_check = "SELECT `id` FROM `book_books` WHERE `name` = '".mysql_real_escape_string($book)."' AND `author` = $author LIMIT 1";
            else return
false;
           
$result_check = $db->sql_query($sql_check);
           
$rows_check = $db->sql_fetchrow($result_check);
            if(!empty(
$rows_check)) $book = $rows_check['id'];
            else return
false;
       
           
settype($book,'int');
        }
    }
   
   
   
   
// Query for Absolute read and Filter.

    // First, We perform the SQL Query, ordering by IP and Timepstamp
    if(!empty($book)) $sql_reads = "SELECT `ip`,`timestamp`,`author` FROM `book_reads` WHERE `author` = $author AND `book` = $book ORDER BY `timestamp` DESC";
    else
$sql_reads = "SELECT `ip`,`timestamp`,`author` FROM `book_reads` WHERE `author` = $author ORDER BY `timestamp` DESC";
   
$result_reads = $db->sql_query($sql_reads);
   
$row_reads = $db->sql_fetchrowset($result_reads);

    // Check if the result is not empty. If them, return 0 and break here.
   
if(empty($row_reads)) return 0;

    // First, get the Rows and set an Array with IP and Num incrermental as Key (see bellow)
   
foreach($row_reads as $row){

        // Get the variablles from Row
       
$ip = $row['ip'];
       
$timestamp = strtotime($row['timestamp']);
       
       
// If current IP is different than the Last IP, rewind the Num Key to 0
        // (first time to itearte, Num Key is 0 by default, because Last IP is null).
       
if($ip != $last_ip) $num = 0;
       
       
// Don't consider the reads from Owner or Admin
        //if($author != $row['author'] || !$user_admin) $row_reads_largestring[$ip] .= strtotime($row['timestamp']).';'; // First method, CSV String
       
if($author != $row['author'] || !$user_admin) $row_reads_filtered[$ip][$num] = $timestamp; // New method, Array with IP and Num as Keys
       
$num++; // Increment Num Key
       
$last_ip = $ip; // Set Last IP to compare to the next
   
}
   
   
//if(empty($row_reads_largestring)) return false; // Deprecated
   
if(empty($row_reads_filtered)) return false;

    // Unset unused array
   
unset($row_reads);

/* Deprecated

    // The code that I used before:

    // Here I'll re-merge the String delimited using explode() effectivelly get Arrays
    // with the Key and multiple values (the Timestamps). Unfortunadely, the last
    // value will be NULL, and this should be corrected later, in third foreach.
    foreach($row_reads_largestring as $key=>$value){
        $ip = $key;
        if(!empty($value)) $row_reads_filtered[$ip] = explode(";",$value);
    }
   
    // Unset unused array
    unset($row_reads_largestring);
*/   

    // And finally, with the Multidimensional Array give above, now I can filter and count!
    // The hardest, is create a name for Variables and write proper comments xD
    foreach($row_reads_filtered as $row){
        foreach(
$row as $row_filter){
           
// Increment Points ONLY if the same IP loads the page upon 1 hour.
           
if((($last_timestamp - $row_filter) > 3600)) $num++;
           
$last_timestamp = $row_filter;
        }
    }
   
   
// Unset unused array
   
unset($row_reads_filtered);
   
   
// :: Query for Comments
   
    // Set the SQL Query
   
if(!empty($book)) $sql_comments = "SELECT `user`,`note` FROM `book_comments` WHERE `author` = $author AND `book` = $book AND `moderated` = 1 ORDER BY `timestamp` DESC";
    else
$sql_comments = "SELECT `note`,`user` FROM `book_comments` WHERE `author` = $author AND `moderated` = 1 ORDER BY `timestamp` DESC";
   
$result_comments = $db->sql_query($sql_comments);
   
$row_comments = $db->sql_fetchrowset($result_comments);
   
   
// Add the Note of Comments to the Points to get the final result (default: 2).
   
foreach($row_comments as $row){
       
// Don't count comments from the same Author or Admin.
       
if($row['user'] != $author || !$user_admin) $num = $num + $row['note'];
    }

    // Unset unused array
   
unset($row_comments);   

    // Return the value
   
return $num;
}
?>

Todo lo tengo documentado en inglés.