Пример #1
0
/**
 * Computes the frequency of each $input array member.
 * @param   mixed  $input        input string or array of strings to parse ($_POST vars are sent as strings)
 * @param   int    $threshold    frequencies (in percentage) under this $threshold will not be stored (default: 1%)
 * @return  array                A sorted associative array in the form '[mostFrequentItem]=>frequency,...,[lessFrequentItem]=>frequency'
 */
function array_frequency($input, $threshold = 1)
{
    // convert $input in a real PHP array
    if (!is_array($input)) {
        $input = explode(",", $input);
    }
    // count occurrences (array keys must be strings or integers)
    $unique = array_sanitize(array_count_values($input));
    // exit if there are no data
    if (!$unique) {
        return false;
    }
    // compute sum
    $sum = array_sum($unique);
    $data = array();
    // now calculate the frequency of each input element (in percentage)
    foreach ($unique as $k => $value) {
        $frequency = round(100 * $value / $sum, 2);
        // store frecuencies above given threshold
        if ($frequency > $threshold) {
            $data[$k] = $frequency;
        }
    }
    // order by frecuency
    arsort($data);
    return $data;
}
Пример #2
0
<?php

// check data first (exclude registered users)
if (empty($_POST) || isset($_COOKIE['smt-usr'])) {
    die(":(");
}
require_once '../config.php';
$values = "sess_time = '" . (double) $_POST['time'] . "',";
$values .= "vp_width  = '" . (int) $_POST['pagew'] . "',";
$values .= "vp_height = '" . (int) $_POST['pageh'] . "',";
$values .= "coords_x  = CONCAT(COALESCE(coords_x, ''), '," . $_POST['xcoords'] . "'),";
$values .= "coords_y  = CONCAT(COALESCE(coords_y, ''), '," . $_POST['ycoords'] . "'),";
$values .= "clicks    = CONCAT(COALESCE(clicks,   ''), '," . $_POST['clicks'] . "'),";
$values .= "hovered   = CONCAT(COALESCE(hovered,  ''), '," . array_sanitize($_POST['elhovered']) . "'),";
$values .= "clicked   = CONCAT(COALESCE(clicked,  ''), '," . array_sanitize($_POST['elclicked']) . "')";
db_update(TBL_PREFIX . TBL_RECORDS, $values, "id='" . $_POST['uid'] . "'");
Пример #3
0
} else {
    $did = $d['id'];
}
/* create database entry ---------------------------------------------------- */
$fields = "client_id,cache_id,domain_id,os_id,browser_id,browser_ver,user_agent,";
$fields .= "ftu,ip,scr_width,scr_height,vp_width,vp_height,";
$fields .= "sess_date,sess_time,fps,coords_x,coords_y,clicks,hovered,clicked";
$values = "'" . $_POST['client'] . "',";
$values .= "'" . $cache_id . "',";
$values .= "'" . $did . "',";
$values .= "'" . $osid . "',";
$values .= "'" . $browserid . "',";
$values .= "'" . (double) $browser->getVersion() . "',";
$values .= "'" . $browser->getUserAgent() . "',";
$values .= "'" . (int) $_POST['ftu'] . "',";
$values .= "'" . get_ip() . "',";
$values .= "'" . (int) $_POST['screenw'] . "',";
$values .= "'" . (int) $_POST['screenh'] . "',";
$values .= "'" . (int) $_POST['pagew'] . "',";
$values .= "'" . (int) $_POST['pageh'] . "',";
$values .= "NOW(),";
$values .= "'" . (double) $_POST['time'] . "',";
$values .= "'" . (int) $_POST['fps'] . "',";
$values .= "'" . $_POST['xcoords'] . "',";
$values .= "'" . $_POST['ycoords'] . "',";
$values .= "'" . $_POST['clicks'] . "',";
$values .= "'" . array_sanitize($_POST['elhovered']) . "',";
$values .= "'" . array_sanitize($_POST['elclicked']) . "'";
$uid = db_insert(TBL_PREFIX . TBL_RECORDS, $fields, $values);
// send user ID back to the record script
echo $uid;
Пример #4
0
// will group by log id
$records = db_select_all(TBL_PREFIX . TBL_RECORDS, "*", $where . " GROUP BY " . $_SESSION['groupby'] . " ORDER BY id DESC, client_id, domain_id LIMIT {$limit}");
$items = [];
// if there are no more records, display message
if (!empty($records)) {
    if (check_systemversion("php", "5.2.0")) {
        $usePrettyDate = true;
        require_once SYS_DIR . 'prettyDate.php';
    }
    foreach ($records as $i => $r) {
        // wait for very recent visits
        $timeDiff = time() - strtotime($r['sess_date']);
        $receivingData = $timeDiff > 0 && $timeDiff < 30;
        $safeToDelete = $timeDiff > 3600;
        // delete logs with no mouse data
        if ($safeToDelete && !count(array_sanitize(explode(",", $r['coords_x'])))) {
            db_delete(TBL_PREFIX . TBL_RECORDS, "id='" . $r['id'] . "' LIMIT 1");
            continue;
        }
        if (!empty($_SESSION['groupby'])) {
            $browser = null;
            $ftu = null;
            switch ($_SESSION['groupby']) {
                case 'cache_id':
                    $pageId = $r['cache_id'];
                    $pages = db_select(TBL_PREFIX . TBL_RECORDS, "count(*) as num", "cache_id='" . $pageId . "'");
                    $GROUPED = "(" . $pages['num'] . " logs)";
                    $locationId = $GROUPED;
                    $displayId = 'pid=' . $r['cache_id'];
                    $clientId = $GROUPED;
                    // check if cached page exists
Пример #5
0
<?php

// check Flash client request
if ($_POST['xhr']) {
    require '../../../../config.php';
    $xcoords = json_decode($_POST['xdata']);
    $ycoords = json_decode($_POST['ydata']);
} else {
    // transform mouse coordinates in a real PHP array
    $xcoords = explode(",", $coordsX);
    $ycoords = explode(",", $coordsY);
}
if (!count(array_sanitize($xcoords)) && !$_POST['xhr']) {
    die("<strong>Error</strong>: No mouse data.");
}
// transform arrays in a single points array
$pointArray = convert_points($xcoords, $ycoords);
// We can do as many clusters as (to the extreme) the sample points size,
// so better use the rule of thumb: k ~ sqrt(n/2)
$n = count($pointArray);
$k = ceil(sqrt($n / 2));
$km = new KMeans($pointArray, $k);
$km->initKatsavounidis();
$km->doCluster();
foreach ($km->clusters as $i => $cluster) {
    $size = count($cluster);
    // exclude singleton clusters
    if ($size < 2) {
        continue;
    }
    $clusterSize[] = $size;
Пример #6
0
$values .= "vp_width  = '" . (int) $_POST['pagew'] . "',";
$values .= "vp_height = '" . (int) $_POST['pageh'] . "',";
if (!empty($findRecord['coords_x'])) {
    $values .= "coords_x  = CONCAT(COALESCE(coords_x, ''), '," . $xcoords . "'),";
} else {
    $values .= "coords_x  = '" . $xcoords . "',";
}
if (!empty($findRecord['coords_y'])) {
    $values .= "coords_y  = CONCAT(COALESCE(coords_y, ''), '," . $ycoords . "'),";
} else {
    $values .= "coords_y  = '" . $ycoords . "',";
}
if (!empty($findRecord['clicks'])) {
    $values .= "clicks    = CONCAT(COALESCE(clicks,   ''), '," . $clicks . "'),";
} else {
    $values .= "clicks  = '" . $clicks . "',";
}
if (!empty($findRecord['hovered'])) {
    $values .= "hovered   = CONCAT(COALESCE(hovered,  ''), '," . array_sanitize($elhovered) . "'),";
} else {
    $values .= "hovered  = '" . array_sanitize($elhovered) . "',";
}
if (!empty($findRecord['clicked'])) {
    $values .= "clicked   = CONCAT(COALESCE(clicked,  ''), '," . array_sanitize($elclicked) . "'),";
} else {
    $values .= "clicked  = '" . array_sanitize($elclicked) . "',";
}
$values .= "updated_at = '" . date("Y-m-d H:i:s") . "'";
db_update(TBL_PREFIX . TBL_RECORDS, $values, "id='" . $_POST['uid'] . "'");
header('Content-Type: application/json');
echo json_encode(array('uid' => intval($_POST['uid']), 'session_id' => intval($session_id)));