/[H9]/trunk/tntnet/dynamic/temperaturegraph.ecpp
ViewVC logotype

Contents of /trunk/tntnet/dynamic/temperaturegraph.ecpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 126 - (show annotations) (download)
Sun Dec 2 20:26:43 2007 UTC (16 years, 5 months ago) by torben
File size: 2095 byte(s)
Silenced compiler warnings

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

  ViewVC Help
Powered by ViewVC 1.1.20