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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 120 - (hide annotations) (download)
Sun Dec 2 08:49:18 2007 UTC (16 years, 6 months ago) by torben
File size: 1998 byte(s)
Switched from black to white color scheme

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

  ViewVC Help
Powered by ViewVC 1.1.20