-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparser.php
70 lines (61 loc) · 1.99 KB
/
parser.php
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
class parser
{
private $_db;
function __construct()
{
$this->_db = new SQLite3('checkin.sqlite', SQLITE3_OPEN_READONLY);
if(!$this->_db)
{
die($error);
}
}
function parseData()
{
$query = $this->_db->query("SELECT ID, action, timestamp FROM event");
while($results[] = $query->fetchArray(SQLITE3_ASSOC));
$data = [];
for($i = 1; $i < 8; $i++)
{
for($j = 0; $j < 24; $j++)
{
$data[$i][$j] = 0;
}
}
$i = 0;
while($results[$i])
{
if(($results[$i]['action'] == 'check-in') && ($results[$i+1]['action'] == 'check-out'))
{
// do something
$checkin = new DateTime('@'.$results[$i]['timestamp']);
$checkout = new DateTime('@'.$results[$i+1]['timestamp']);
if(($checkout->format('d') - $checkin->format('d')) == 0)
{
for($j = $checkin->format('G'); $j <= $checkout->format('G'); $j++)
{
$data[$checkin->format('N')][$j]++;
}
}
else
{
for($j = $checkin->format('G'); $j <= 23; $j++)
{
$data[$checkin->format('N')][$j]++;
}
for($j = 0; $j <= $checkout->format('G'); $j++)
{
$data[$checkout->format('N')][$j]++;
}
}
$i = $i+2;
}
else
{
$i++;
}
}
return $data;
}
}
?>