-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdumper.php
More file actions
executable file
·34 lines (33 loc) · 1.09 KB
/
dumper.php
File metadata and controls
executable file
·34 lines (33 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/usr/bin/env php
<?php
// Prepare Redis
$r = new Redis();
$r->connect('localhost',6379);
// Prepare Mongo
$connecton = new MongoClient();
$db = $connecton->bigbrother;
$online = $db->online;
$now = new DateTime();
$keys = $r->keys('*');
$users = [];
foreach($keys as $key) { // Iterate User
$timemarks = $r->hGetAll($key);
$count = count($timemarks);
if ($count % 2 != 0) {
end($timemarks); $last_key = key($timemarks);reset($timemarks);
$last_state = $timemarks[$last_key];
$timemarks[$now->getTimestamp()] = 1 - $last_state;
}
$timemarks_keys = array_keys($timemarks);
for ($i=0;$i<=$count-2;$i++) { // Iterate Timeline
$mark_one = $timemarks_keys[$i];
$mark_two = $timemarks_keys[$i+1];
$result = $online->insert(['user_id' => (int)$key,
'start' => new MongoDate($mark_one),
'end' => new MongoDate($mark_two),
'status' => (int)$timemarks[$mark_one],
'duration' => $mark_two - $mark_one
]);
}
}
$r->flushAll();