1
|
<?php
|
2
|
|
3
|
function process_traffic_matrix($parser, $traffic, $trafficOneDay, $idDateTable, $idRecordTimeTable, $idRecordTable, $idRecordOneDayTable, &$insertDate, &$insertRTT, &$insertRT, &$insertOneDay, $date) {
|
4
|
$times = array();
|
5
|
|
6
|
// Rekonstrukce casovych intervalu.
|
7
|
for ($i = 0; $i < $parser->HOW_MANY_INTERVALS; $i++) {
|
8
|
$times[$i] = array();
|
9
|
$times[$i][0] = new DateTime($date);
|
10
|
$times[$i][1] = new DateTime($date);
|
11
|
|
12
|
$fromSec = (int) (($i * $parser->intervalMilli) / 1000);
|
13
|
$toSec = (int) (($i + 1) * $parser->intervalMilli / 1000);
|
14
|
|
15
|
$fromHours = (int) ($fromSec / 3600);
|
16
|
$fromMinutes = (int) (($fromSec - $fromHours * 3600) / 60);
|
17
|
$fromSeconds = (int) ($fromSec - $fromHours * 3600 - $fromMinutes * 60);
|
18
|
|
19
|
$toHours = (int) ($toSec / 3600);
|
20
|
$toMinutes = (int) (($toSec - $toHours * 3600) / 60);
|
21
|
$toSeconds = (int) ($toSec - $toHours * 3600 - $toMinutes * 60);
|
22
|
|
23
|
$times[$i][0]->setTime($fromHours, $fromMinutes, $fromSeconds);
|
24
|
$times[$i][1]->setTime($toHours, $toMinutes, $toSeconds);
|
25
|
}
|
26
|
|
27
|
// Priprava dat pro naplneni tabulek zaznam a zaznam_cas.
|
28
|
foreach ($traffic as $device => $timeIntervals) {
|
29
|
for ($t = 0; $t < $parser->HOW_MANY_INTERVALS; $t++) {
|
30
|
if ($timeIntervals[$t] != NULL) {
|
31
|
for ($d = 0; $d < 2; $d++) {
|
32
|
$dataExists = FALSE;
|
33
|
|
34
|
for ($v = 0; $v < 11; $v++) {
|
35
|
$count_ = $timeIntervals[$t][$d][$v][0] + $timeIntervals[$t][$d][$v][2];
|
36
|
if ($count_ > 0) {
|
37
|
$dataExists = TRUE;
|
38
|
$speed_ = -1.0;
|
39
|
|
40
|
if ($timeIntervals[$t][$d][$v][0] > 0) {
|
41
|
$speed_ = $timeIntervals[$t][$d][$v][1] / (double) $timeIntervals[$t][$d][$v][0];
|
42
|
}
|
43
|
|
44
|
$insertRT[] = "('".$idRecordTable++."', '$count_', '$speed_', '$v', '$idRecordTimeTable')";
|
45
|
}
|
46
|
}
|
47
|
|
48
|
if ($dataExists) {
|
49
|
$insertRTT[] = "('".$idRecordTimeTable++."', '".($d + 1)."', '$device', '".($idDateTable + $t)."')";
|
50
|
}
|
51
|
}
|
52
|
}
|
53
|
}
|
54
|
}
|
55
|
|
56
|
// Priprava dat pro naplneni tabulky datum. Budou vlozeny veskere casove intervaly. Je nemozne, aby neexistovalo alespon jedno zarizeni,
|
57
|
// ktere v dany casovy interval detekuje alespon jeden dopravni prostredek. I kdyby takova situace nastala, dane intervaly take mohou
|
58
|
// slouzit pro pouziti ve statistikach.
|
59
|
for ($i = 0; $i < $parser->HOW_MANY_INTERVALS; $i++) {
|
60
|
$insertDate[] = "('".$idDateTable++."', '".$times[$i][0]->format("Y-m-d H:i:s")."', '".$times[$i][1]->format("Y-m-d H:i:s")."')";
|
61
|
}
|
62
|
|
63
|
// Priprava dat pro naplneni tabulky zaznam_prum_den.
|
64
|
foreach ($trafficOneDay as $device => $direction) {
|
65
|
for ($d = 0; $d < 2; $d++) {
|
66
|
for ($v = 0; $v < 11; $v++) {
|
67
|
$count_ = $direction[$d][$v][0] + $direction[$d][$v][2];
|
68
|
if ($count_ > 0) {
|
69
|
$speed_ = -1.0;
|
70
|
if ($direction[$d][$v][0] > 0) {
|
71
|
$speed_ = $direction[$d][$v][1] / (double) $direction[$d][$v][0];
|
72
|
}
|
73
|
$insertOneDay[] = "('".$idRecordOneDayTable++."', '$count_', '$speed_', '".($d + 1)."', '$device', '$v', '$idDateTable')";
|
74
|
}
|
75
|
}
|
76
|
}
|
77
|
}
|
78
|
|
79
|
// Priprava posledniho zaznamu ke vlozeni do tabulky datum (cely den - vzdy bude alespon jeden udaj).
|
80
|
$timeFrom = new DateTime($date);
|
81
|
$timeFrom->setTime(0, 0, 0);
|
82
|
$timeTo = new DateTime($date);
|
83
|
$timeTo->setTime(0, 0, 0);
|
84
|
$timeTo->modify("+1 day");
|
85
|
$insertDate[] = "('$idDateTable', '".$timeFrom->format("Y-m-d H:i:s")."', '".$timeTo->format("Y-m-d H:i:s")."')";
|
86
|
|
87
|
}
|
88
|
|
89
|
?>
|