1 |
torben |
118 |
<%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 |
|
|
|
21 |
|
|
GD::Image image; |
22 |
|
|
image.CreateTrueColor( GD::Size(600,350)); |
23 |
|
|
|
24 |
|
|
GD::TrueColor green(45,95,0); |
25 |
|
|
GD::TrueColor text(200,200,200); |
26 |
|
|
GD::TrueColor red(255,0,0); |
27 |
|
|
|
28 |
|
|
|
29 |
|
|
image.String(gdFontSmall, 250,5, "Temperature graph", text.Int()); |
30 |
|
|
|
31 |
|
|
for (int i=0; i<11; ++i) |
32 |
|
|
{ |
33 |
|
|
std::stringstream marker; |
34 |
|
|
marker << (100- (i*10)); |
35 |
|
|
int y = (i*30) + 25; |
36 |
|
|
image.Line( 30, y, 590, y, green.Int()); |
37 |
|
|
|
38 |
|
|
image.String(gdFontSmall, 5, y-7, marker.str().c_str(), text.Int()); |
39 |
|
|
|
40 |
|
|
} |
41 |
|
|
///////////////////////////////////////////////// |
42 |
|
|
|
43 |
|
|
|
44 |
|
|
tntdb::Connection conn = tntdb::connect(dburl); |
45 |
|
|
|
46 |
|
|
std::stringstream query; |
47 |
|
|
query << "SELECT temperature FROM ( "; |
48 |
|
|
query << " SELECT messagenr,temperature FROM logtable "; |
49 |
|
|
query << " WHERE installationnr = " << id << " "; |
50 |
|
|
query << " ORDER BY messagenr DESC LIMIT 20 "; |
51 |
|
|
query << ") query "; |
52 |
|
|
query << "ORDER BY messagenr ASC"; |
53 |
|
|
|
54 |
|
|
tntdb::Result res = conn.select(query.str()); |
55 |
|
|
|
56 |
|
|
GD::Point previous; |
57 |
|
|
for (int i=0; i<res.size(); ++i) |
58 |
|
|
{ |
59 |
|
|
int current = res[i].getInt(0); |
60 |
|
|
int x = (i*28) + 40; |
61 |
|
|
int y = ((100-current) * 3) + 25; |
62 |
|
|
|
63 |
|
|
//image.FilledArc( GD::Point(x,y), GD::Size(3,3), 0, 360, red.Int(), gdPie); |
64 |
|
|
image.FilledRectangle( GD::Point(x-1,y-1), GD::Point(x+1,y+1), red.Int() ); |
65 |
|
|
|
66 |
|
|
if (i>0) |
67 |
|
|
{ |
68 |
|
|
image.Line( GD::Point(x,y), previous, red.Int()); |
69 |
|
|
} |
70 |
|
|
|
71 |
|
|
previous = GD::Point(x,y); |
72 |
|
|
|
73 |
|
|
} |
74 |
|
|
|
75 |
|
|
////////////////////////////////////////////////// |
76 |
|
|
// echo the image to the browser... |
77 |
|
|
reply.setContentType("image/png"); |
78 |
|
|
int size; |
79 |
|
|
unsigned char* ptr = (unsigned char*) image.Png(&size); |
80 |
|
|
|
81 |
|
|
for (int i=0; i<size; ++i) |
82 |
|
|
reply.out() << ptr[i]; |
83 |
|
|
|
84 |
|
|
gdFree(ptr); |
85 |
|
|
|
86 |
|
|
}> |