-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathprocessDb.php
More file actions
90 lines (70 loc) · 1.93 KB
/
Copy pathprocessDb.php
File metadata and controls
90 lines (70 loc) · 1.93 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
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<?php
include 'DB.php';
include 'LHD.php';
include 'Distance.php';
ini_set('max_execution_time', 5*60);
$start = microtime(true);
$db = new DB();
$dbWrite = new DB();
LHD::initMonitor($db->getNbDataPoints());
$q = $db->getAllDataPoints();
$dbWrite->resetSummaries();
$i = 0;
$lastdate = null;
$last = null;
$items = 0;
$summary = new Summary();
while ($r = $q->fetch(PDO::FETCH_OBJ)) {
// set accuracy if missing
if (!property_exists($r, 'accuracy')) $r->accuracy = 0;
$date = explode(' ', $r->pointdate)[0];
// if doesn't have a from, use current ts
if (!$summary->from) {
$summary->from = $r->timestampMs;
}
//var_dump($r->pointdate);
if ($summary->ref['latitude'] == 0) $summary->ref = array('latitude' => $r->latitude, 'longitude' => $r->longitude, 'accuracy' => $r->accuracy, 'lastMotion' => 0);
// we need a reference point
if ($last) {
// try adding the distance and retrieve a changed state
$stateChanged = $summary->addDistance($last, $r);
if ($stateChanged) {
$summary->day = $lastdate;
$summary->to = $last->timestampMs;
$nowMoving = !$summary->moving;
// Save summary
//var_dump($summary);
$dbWrite->addSummary($summary);
$items++;
// Begin new event
$summary = new Summary();
$summary->from = $last->timestampMs;
$summary->moving = $nowMoving;
$summary->ref = array('latitude' => $r->latitude, 'longitude' => $r->longitude, 'accuracy' => $r->accuracy, 'lastMotion' => 0);
//$summary->nbPoints = 1;
// if switched from static to moving, set initial distance
if ($nowMoving == true) {
$summary->setDistance($last, $r);
}
}
}
$lastdate = $date;
$last = $r;
$summary->nbPoints++;
$i++;
// Buffered writes
if ($i%1000 == 0) {
LHD::updateMonitor($i);
if ($items > 0) {
$dbWrite->commitSummaries();
}
$items = 0;
}
}
// last commit
LHD::updateMonitor($i);
if ($items > 0) {
$dbWrite->commitSummaries();
}
$end = microtime(true) - $start;
var_dump($end);