1 |
<%pre> |
2 |
#include <tntdb/connect.h> |
3 |
#include <tntdb/connection.h> |
4 |
#include <tntdb/result.h> |
5 |
#include <tntdb/row.h> |
6 |
|
7 |
|
8 |
#include "gd-cpp/gdpp.h" |
9 |
#include <gdfonts.h> |
10 |
#include <sstream> |
11 |
|
12 |
</%pre> |
13 |
<%config> |
14 |
dburl; |
15 |
</%config> |
16 |
<%args> |
17 |
int id; |
18 |
</%args> |
19 |
<{ |
20 |
reply.setHeader("Cache-Control", "no-cache, must-revalidate"); // Http/1.1 |
21 |
reply.setHeader("Expires", "Mon, 26 Jul 1997 05:00:00 GMT"); //date in the past |
22 |
|
23 |
GD::Image image; |
24 |
image.Create( GD::Size(600,360)); |
25 |
|
26 |
//Black color scheme |
27 |
//GD::TrueColor decoration(45,95,0); |
28 |
//GD::TrueColor text(200,200,200); |
29 |
//GD::TrueColor line(255,0,0); |
30 |
|
31 |
//White color scheme |
32 |
int white = image.ColorAllocate(255,255,255); |
33 |
int decoration = image.ColorAllocate(60,60,60); |
34 |
int text = image.ColorAllocate(0,0,0); |
35 |
int line = image.ColorAllocate(255,0,0); |
36 |
|
37 |
image.Fill( GD::Point(1,1), white ); |
38 |
|
39 |
image.String(gdFontSmall, 250,5, "Temperature graph", text); |
40 |
image.String(gdFontSmall, 200,18, "Latest 20 samples, in degrees Celcius", text); |
41 |
|
42 |
for (int i=0; i<11; ++i) |
43 |
{ |
44 |
std::stringstream marker; |
45 |
marker << (100- (i*10)); |
46 |
int y = (i*30) + 40; |
47 |
image.Line( 30, y, 590, y, decoration); |
48 |
|
49 |
image.String(gdFontSmall, 5, y-7, marker.str().c_str(), text); |
50 |
|
51 |
} |
52 |
///////////////////////////////////////////////// |
53 |
|
54 |
|
55 |
tntdb::Connection conn = tntdb::connectCached(dburl); |
56 |
|
57 |
std::stringstream query; |
58 |
query << "SELECT temperature FROM ( "; |
59 |
query << " SELECT messagenr,temperature FROM logtable "; |
60 |
query << " WHERE installationnr = " << id << " "; |
61 |
query << " ORDER BY messagenr DESC LIMIT 20 "; |
62 |
query << ") query "; |
63 |
query << "ORDER BY messagenr ASC"; |
64 |
|
65 |
tntdb::Result res = conn.select(query.str()); |
66 |
|
67 |
GD::Point previous; |
68 |
for (unsigned int i=0; i<res.size(); ++i) |
69 |
{ |
70 |
int current = res[i].getInt(0); |
71 |
int x = (i*28) + 45; |
72 |
int y = ((100-current) * 3) + 40; |
73 |
|
74 |
//image.FilledArc( GD::Point(x,y), GD::Size(3,3), 0, 360, line.Int(), gdPie); |
75 |
image.FilledRectangle( GD::Point(x-1,y-1), GD::Point(x+1,y+1), line ); |
76 |
|
77 |
if (i>0) |
78 |
{ |
79 |
image.Line( GD::Point(x,y), previous, line); |
80 |
} |
81 |
|
82 |
previous = GD::Point(x,y); |
83 |
|
84 |
} |
85 |
|
86 |
////////////////////////////////////////////////// |
87 |
// echo the image to the browser... |
88 |
reply.setContentType("image/png"); |
89 |
int size; |
90 |
unsigned char* ptr = (unsigned char*) image.Png(&size,1); |
91 |
|
92 |
for (int i=0; i<size; ++i) |
93 |
reply.out() << ptr[i]; |
94 |
|
95 |
gdFree(ptr); |
96 |
|
97 |
}> |