예제 #1
0
function queryManagerCreateBinFromExistingTables($binname, $querybin_id, $type, $queries = array())
{
    $dbh = pdo_connect();
    // select start and end of dataset
    $sql = "SELECT min(created_at) AS min, max(created_at) AS max FROM " . $binname . "_tweets";
    $rec = $dbh->prepare($sql);
    if (!$rec->execute() || !$rec->rowCount()) {
        die("could not find " . $binname . "_tweets" . PHP_EOL);
    }
    $res = $rec->fetch();
    $starttime = $res['min'];
    $endtime = $res['max'];
    // create bin in query manager
    if ($querybin_id === false) {
        $querybin_id = queryManagerCreateBin($binname, $type, $starttime, $endtime, 0);
    }
    // retrieve users from timeline capture
    if (($type == 'timeline' || $type == "import timeline") && empty($queries)) {
        $rec = $dbh->prepare("SELECT DISTINCT(from_user_id) FROM " . $binname . "_tweets");
        if ($rec->execute() && $rec->rowCount() > 0) {
            $queries = $rec->fetchAll(PDO::FETCH_COLUMN);
        }
    }
    if ($type == 'track' || $type == 'search' || $type == "import ytk" || $type == "import track") {
        // insert phrases
        queryManagerInsertPhrases($querybin_id, $queries, $starttime, $endtime);
    } elseif ($type == 'follow' || $type == 'timeline' || $type == 'import timeline') {
        // insert users
        queryManagerInsertUsers($querybin_id, $queries, $starttime, $endtime);
    }
}
예제 #2
0
function binsToDb($stuff, $type)
{
    $dbh = pdo_connect();
    foreach ($stuff as $binname => $queries) {
        $binname = trim($binname);
        $rec2 = $dbh->prepare("SELECT id FROM tcat_query_bins WHERE querybin = '{$binname}'");
        if ($rec2->execute() && $rec2->rowCount() > 0) {
            // check whether the table has already been imported
            print "{$binname} already exists in the query manager, skipping it's import" . PHP_EOL;
            continue;
        }
        // select start and end of dataset
        $sql = "SELECT min(created_at) AS min, max(created_at) AS max FROM " . $binname . "_tweets";
        $rec = $dbh->prepare($sql);
        if (!$rec->execute() || !$rec->rowCount()) {
            die("could not find " . $binname . "_tweets" . PHP_EOL);
        }
        $res = $rec->fetch();
        $starttime = $res['min'];
        $endtime = $res['max'];
        $active = 0;
        if (strtotime($endtime) > strtotime(strftime("%Y-%m-%d 00:00:00", date('U')))) {
            // see whether it is still active
            $endtime = "0000:00:00 00:00:00";
            $active = 1;
        }
        $querybin_id = queryManagerCreateBin($binname, $type, $starttime, $endtime, $active);
        $queries = explode(",", $queries);
        // insert phrases
        if ($type == 'track') {
            queryManagerInsertPhrases($querybin_id, $queries, $starttime, $endtime);
        }
        // insert users
        if ($type == 'follow') {
            queryManagerInsertUsers($querybin_id, $queries, $starttime, $endtime);
        }
    }
    $dbh = false;
}