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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 122 - (hide annotations) (download)
Sun Dec 2 16:56:14 2007 UTC (16 years, 6 months ago) by torben
File size: 2086 byte(s)
* Finished critical list
* Moved <ul> style from customerlist to stylesheet
* Added image alt-tags to installationdetails
* Safer login via prepeared statements



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 torben 122 image.CreateTrueColor( GD::Size(600,360));
23 torben 118
24 torben 120 //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 torben 118
29 torben 120 //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 torben 118
35 torben 120
36 torben 118 image.String(gdFontSmall, 250,5, "Temperature graph", text.Int());
37 torben 122 image.String(gdFontSmall, 200,18, "Latest 20 samples, in degrees Celcius", text.Int());
38 torben 118
39     for (int i=0; i<11; ++i)
40     {
41     std::stringstream marker;
42     marker << (100- (i*10));
43 torben 122 int y = (i*30) + 40;
44 torben 120 image.Line( 30, y, 590, y, decoration.Int());
45 torben 118
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 (int i=0; i<res.size(); ++i)
66     {
67     int current = res[i].getInt(0);
68 torben 122 int x = (i*28) + 45;
69     int y = ((100-current) * 3) + 40;
70 torben 118
71 torben 120 //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 torben 118
74     if (i>0)
75     {
76 torben 120 image.Line( GD::Point(x,y), previous, line.Int());
77 torben 118 }
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