<?php

header('Access-Control-Allow-Origin: *');
include_once 'common.php';
include 'database.php';
$d = getIntParam("days", 1, 5 * 365, 28);
$h = 1;
if ($d > 400) {
    $h = 48;
} elseif ($d > 200) {
    $h = 24;
} elseif ($d > 100) {
    $h = 12;
} elseif ($d > 67) {
    $h = 6;
} elseif ($d > 50) {
    $h = 4;
} elseif ($d > 33) {
    $h = 3;
} elseif ($d > 17) {
    $h = 2;
}
$sql = "select from_unixtime((3600*{$h})*ceil(unix_timestamp(DateHour)/(3600*{$h}))) DateHour, sum(TweetsProcessed - TweetsDiscarded) as Tweets\n  from HourStatistics where DateHour >= utc_timestamp() - interval {$d} day group by 1";
$conn = get_mysql_connection();
$conn->query("SET SESSION TRANSACTION ISOLATION LEVEL READ UNCOMMITTED");
$result = $conn->query($sql);
$conn->query("SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ");
$data = array();
while ($row = $result->fetch_object()) {
    $d = array();
    $d["date_hour"] = $row->DateHour;
Example #2
0
            $f->attributeID = intval($tmp[0]);
            $f->labelIDs = array_map("intval", explode(",", $tmp[1]));
            $filters[] = $f;
        }
        return $filters;
    }
    return null;
}
$tweets = array();
try {
    include 'database.php';
    $conn = get_mysql_connection();
    $mintime = getTimeParam("mintime");
    $maxtime = getTimeParam("maxtime");
    $textFilter = getSafeTextParam("text", $conn);
    $fetchOngoingStories = getIntParam("ongoing", 0, 1, 1);
    $topicFilter = parseTopicFilter("topics");
    $where = '';
    $having = '';
    $join = '';
    if (!$fetchOngoingStories && $mintime != null) {
        $where .= " and Story.StartTime >= '{$mintime}' ";
    }
    if (!$fetchOngoingStories && $maxtime != null) {
        $where .= " and Story.StartTime <= '{$maxtime}' ";
    }
    if ($textFilter != null) {
        $textFilter = preg_replace("/ *, */", ",", $textFilter);
        $words = stemMany(preg_split("/,| |;/", $textFilter, -1, PREG_SPLIT_NO_EMPTY));
        $textFilter = "'" . implode("','", $words) . "'";
        $where .= " and Keyword in ({$textFilter}) ";
<?php

header('Access-Control-Allow-Origin: *');
include_once 'common.php';
$tweets = array();
try {
    include 'database.php';
    $conn = get_mysql_connection();
    $id = intval($_REQUEST['id']);
    $mintime = getTimeParam("mintime");
    $maxtime = getTimeParam("maxtime");
    $textfilter = getSafeTextParam("text", $conn);
    $topicfilter = getIntParam("label_id", 0, PHP_INT_MAX, null);
    $where = '';
    $join = '';
    if ($textfilter != null) {
        $where .= " and Text like '%{$textfilter}%'";
    }
    if ($topicfilter != null) {
        $where .= " and LabelID=" . $topicfilter;
        $join .= " join TweetAidrAttributeTag taat on taat.TweetID=t.TweetID";
    }
    $having = '';
    if ($maxtime != null && $mintime != null) {
        $having = "having FirstSeen between '{$mintime}' and '{$maxtime}'";
    }
    $sql = "select X.TweetID, TwitterUser.UserID, RealName, ScreenName, ProfileImageUrl, CreatedAt, UserCount, Text from (\n        select\n            min(t.TweetID) as TweetID, min(t.CreatedAt) as FirstSeen, count(distinct t.UserID) as UserCount, log(1+count(distinct t.UserID))*pow(max(t.Novelty),2) as OrderByWeight, s.TweetCount\n        from Tweet t\n            join TweetCluster tc on tc.TweetClusterID=t.TweetClusterID\n            join Story s on s.StoryID=tc.StoryID\n            join TwitterUser tu on tu.UserID=t.UserID\n            {$join}\n        where s.StoryID={$id} and not tu.IsBlacklisted {$where}\n        group by t.TextHash\n        {$having}\n        order by OrderByWeight desc limit 20\n    ) X\n    natural join Tweet\n    natural join TwitterUser\n    order by OrderByWeight desc";
    $conn->query("SET SESSION TRANSACTION ISOLATION LEVEL READ UNCOMMITTED");
    $result = $conn->query($sql);
    $conn->query("SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ");
    while ($row = $result->fetch_object()) {