Example #1
0
$earliest = strtotime("-48 hours");
$latest = time();
$early_ts = date("Y-m-d H:i:s", $earliest);
$late_ts = date("Y-m-d H:i:s", $latest);
$hints = array();
$addrs = array();
$to = array();
$db = new PDO("sqlite:{$DB_PATH}") or die;
$sql = sprintf("\n  SELECT from_, to_\n  FROM addr\n  WHERE latest >= DATETIME(%s,'LOCALTIME')\n  -- AND earliest <= DATETIME(%s,'LOCALTIME')\n  AND from_ NOT LIKE 'htype=%%'\n  AND to_ NOT LIKE 'htype=%%'\n  UNION\n  -- any MAC addresses that haven't got any other addresses associated\n  -- with them, but do have a hint or two\n  SELECT DISTINCT addr, addr\n  FROM hint\n  WHERE addrtype = 'M'\n  AND addr NOT LIKE 'htype=%%'\n  AND latest >= DATETIME(%s,'LOCALTIME')\n  AND earliest <= DATETIME(%s,'LOCALTIME')", $db->quote($early_ts), $db->quote($late_ts), $db->quote($early_ts), $db->quote($late_ts));
echo "{$sql}\n";
$stmt = $db->query($sql) or die(print_r($db->errorInfo(), 1));
$res = $stmt->setFetchMode(PDO::FETCH_ASSOC);
$rows = $stmt->fetchAll();
$res = null;
$stmt = null;
$addrs = array();
foreach ($rows as $row) {
    $addrs[$row['from_']][$row['to_']] = $row;
}
$rows = null;
#echo "orig: "; var_dump($addrs);
#printf("original %d\n", count($addrs));
#echo "before addrs=".print_r($addrs,1);
#exit;
$addrs = conglomerate($addrs);
echo "after addrs=" . print_r($addrs, 1);
#exit;
create_hosts($db, $early_ts, $late_ts, $addrs);
?>

Example #2
0
function test_conglom2()
{
    $x = array("a" => array("b" => 0), "c" => array("b" => 1));
    $expected = array("a" => array("b" => array(0, 1)));
    echo "before2: " . print_r($x, 1);
    $x = conglomerate($x);
    echo "after2: " . print_r($x, 1);
    assert($x === $expected);
}