Skip to content

Commit a0decd0

Browse files
author
Arron Woods
committed
Tweeks on the day
1 parent 487afdc commit a0decd0

2 files changed

Lines changed: 74 additions & 2 deletions

File tree

bin/eventAttendees.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020

2121
$data = array();
2222

23-
$friday = strtotime('2013-02-21');
24-
$saturday = strtotime('2013-02-22');
23+
$friday = strtotime('2014-02-21');
24+
$saturday = strtotime('2014-02-22');
2525

2626
//$checkIns = array(
2727
// strtotime('2013-02-21 07:00'),

bin/tweetCountHour.php

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<?php
2+
3+
chdir(__DIR__ . '/../');
4+
5+
require('vendor/autoload.php');
6+
$config = require('config/local.php');
7+
8+
// The OAuth credentials you received when registering your app at Twitter
9+
define("TWITTER_CONSUMER_KEY", $config['twitter']['key']);
10+
define("TWITTER_CONSUMER_SECRET", $config['twitter']['secret']);
11+
12+
// The OAuth data for the twitter account
13+
define("OAUTH_TOKEN", $config['twitter']['token']);
14+
define("OAUTH_SECRET", $config['twitter']['token_secret']);
15+
16+
$rangeStart = strtotime('2014-02-21 06:00');
17+
$rangeEnd = strtotime('2014-02-23');
18+
$rangeStep = 3600;
19+
$ranges = array_fill_keys(range($rangeStart, $rangeEnd, $rangeStep), null);
20+
21+
echo 'Processing ' . count($ranges) . ' ranges' . PHP_EOL;
22+
$mongo = new \MongoClient();
23+
$collection = $mongo->selectCollection($config['mongo']['database'], $config['mongo']['collection']);
24+
25+
26+
$cb = new ChartBlocks\Client(array(
27+
'token' => $config['chartblocks']['token'],
28+
'secret' => $config['chartblocks']['secret'],
29+
));
30+
31+
$set = $cb->getRepository('dataSet')->findById($config['chartblocks']['tweetHourSetId']);
32+
$counts = array();
33+
34+
foreach ($ranges as $start => $count) {
35+
$getCount = function($track, $collection, $start, $step) {
36+
$count = $collection->count(array(
37+
'created_at' => array(
38+
'$gte' => new \MongoDate($start),
39+
'$lt' => new \MongoDate($start + $step)
40+
),
41+
'entities.hashtags.text' => array('$in' => $track),
42+
));
43+
44+
if ($count == 0 && $start > time()) {
45+
$count = null;
46+
}
47+
48+
return $count;
49+
};
50+
51+
$sochiCount = $getCount($config['twitter']['tracks']['sochi'], $collection, $start, $rangeStep);
52+
$phpCount = $getCount($config['twitter']['tracks']['php'], $collection, $start, $rangeStep);
53+
54+
$counts[date('c', $start)] = array(
55+
'sochi' => $sochiCount,
56+
'php' => $phpCount,
57+
);
58+
}
59+
60+
$r = 2;
61+
$rowSet = new \ChartBlocks\DataSet\RowSetDynamic($set);
62+
foreach ($counts as $date => $count) {
63+
$row = new \ChartBlocks\DataSet\Row($set, array('row' => $r));
64+
$row->setCell(1, $date);
65+
$row->setCell(2, $count['sochi']);
66+
$row->setCell(3, $count['php']);
67+
68+
$rowSet->addRow($row);
69+
$r++;
70+
}
71+
72+
$rowSet->save();

0 commit comments

Comments
 (0)