-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathhtml-query-printer-improved.php
143 lines (119 loc) · 4.26 KB
/
html-query-printer-improved.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
<?php
/**
* DruidFamiliar HTML TimeBoundary Printer Example
*
* Point your browser at this through a web server and you should see nicely formatted time boundary data. :)
*/
use DruidFamiliar\ExampleGroupByQueries\ReferralsByCompanyGroupByQueryParameters;
use DruidFamiliar\ExampleGroupByQueries\ReferralsByCompanyGroupByResponseHandler;
use DruidFamiliar\ExampleResponseObjects\ExampleReferralByCompanyResponseObject;
use DruidFamiliar\Response\TimeBoundaryResponse;
require_once('../vendor/autoload.php');
$examplesDir = dirname(__FILE__);
$examplesConfig = require_once($examplesDir . '/_examples-config.php');
$druidHost = $examplesConfig['druid-host'];
$druidPort = $examplesConfig['druid-port'];
$druidDataSource = $examplesConfig['druid-dataSource'];
date_default_timezone_set('America/Denver');
$c = new \DruidFamiliar\QueryExecutor\DruidNodeDruidQueryExecutor($druidHost, $druidPort);
$q = new \DruidFamiliar\QueryGenerator\TimeBoundaryDruidQueryGenerator($druidDataSource);
$p = new \DruidFamiliar\QueryParameters\TimeBoundaryQueryParameters($druidDataSource);
/**
* @var TimeBoundaryResponse $r
*/
$r = $c->executeQuery($q, $p, new DruidFamiliar\ResponseHandler\TimeBoundaryResponseHandler());
$q2 = new \DruidFamiliar\ExampleGroupByQueries\ReferralsByCompanyGroupByQueryGenerator();
$p2 = new ReferralsByCompanyGroupByQueryParameters( $druidDataSource, '2006-01-01T00:00', '2015-01-01T00' );
/**
* @var ExampleReferralByCompanyResponseObject $r2
*/
$r2 = $c->executeQuery($q2, $p2, new ReferralsByCompanyGroupByResponseHandler());
$startTime = new DateTime( $r->minTime );
$endTime = new DateTime( $r->maxTime );
$formattedStartTime = $startTime->format("F m, Y h:i:s A");
$formattedEndTime = $endTime->format("F m, Y h:i:s A");
$groupByBodyRows = '';
foreach ( $r2 as $index => $val)
{
/**
* @var \DruidFamiliar\ExampleResponseObjects\ExampleReferralByCompanyResponseObject $exampleReferralByCompanyResponseObject
*/
$exampleReferralByCompanyResponseObject = $val;
$timestamp = $exampleReferralByCompanyResponseObject->getTimestamp();
$companyId = $exampleReferralByCompanyResponseObject->getCompanyId();
$facilityId = $exampleReferralByCompanyResponseObject->getFacilityId();
$referrals = $exampleReferralByCompanyResponseObject->getReferrals();
$groupByBodyRows .= <<<TABLEROW
<tr>
<td>$timestamp</td>
<td>$companyId</td>
<td>$facilityId</td>
<td>$referrals</td>
</tr>
TABLEROW;
}
echo <<<HTML_BODY
<!doctype html>
<html>
<head>
<style>
.basic-table--table {
border-collapse: collapse;
width: 100%;
}
.basic-table--table,
.basic-table--table th,
.basic-table--table td {
border: 1px solid #C36182;
}
.basic-table--table th {
background-color: #C36182;
color: white;
padding: .5em 1em;
}
.basic-table--table td {
padding: .25em 1em;
}
.basic-table--table th:first-child,
.basic-table--table td:first-child {
text-align: right;
}
</style>
</head>
<body>
<h1>TimeBoundary data for DataSource "<b>$druidDataSource</b>": </h1>
<table class="basic-table--table">
<thead>
<tr>
<th>DataSource</th>
<th>Start</th>
<th>End</th>
</tr>
</thead>
<tbody>
<tr>
<td>$druidDataSource</td>
<td>$formattedStartTime</td>
<td>$formattedEndTime</td>
</tr>
</tbody>
</table>
<div>
<h1>Raw Group By Query Results</h1>
<table class="basic-table--table">
<thead>
<tr>
<th>timestamp</th>
<th>companyId</th>
<th>facilityId</th>
<th>referrals</th>
</tr>
</thead>
<tbody>
$groupByBodyRows
</tbody>
</table>
</div>
</body>
</html>
HTML_BODY;