source: code/Website/script_elec.php@ 7887

Last change on this file since 7887 was 7887, checked in by dennisw, 15 years ago
File size: 3.8 KB
Line 
1<?php
2set_time_limit(0);
3include_once 'php-ofc-library/open-flash-chart.php';
4include_once 'cfg/mysql.php';
5connectdb();
6
7$roomresult = mysql_query("
8 SELECT name
9 FROM `save_energy`.`rooms`
10 ORDER BY name ASC;
11 ");
12while($row = mysql_fetch_array($roomresult))
13{
14 $roomarray[] = ($row['name']);
15}
16
17foreach($roomarray as $room)
18{
19 $description = array();
20 $colorcode=0;
21 $data = array();
22
23 //-- X AXIS RESULTS--\\
24
25 $result_x = mysql_query("
26 SELECT TIME(`tuples`.start) AS xaxis
27 FROM (`save_energy`.`tuples`)
28 JOIN `save_energy`.`sensors` ON (`tuples`.sensorID=`sensors`.sensorID)
29 JOIN `save_energy`.`rooms` ON (`sensors`.roomID=`rooms`.roomID)
30 WHERE `sensors`.name LIKE '%usage'
31 AND DATE(`tuples`.start) = CURRENT_DATE() - INTERVAL 47 DAY
32 AND `rooms`.name='$room'
33 GROUP BY `tuples`.start ASC
34 ");
35
36 while($row = mysql_fetch_array($result_x))
37 {
38 $xaxis[] = ($row['xaxis']);
39 }
40
41
42 //-- DESCRIPTION RESULTS--\\
43
44 $result = mysql_query("
45 SELECT DISTINCT `sensors`.description as description
46 FROM (`save_energy`.`sensors`)
47 JOIN `save_energy`.`tuples` ON (`sensors`.sensorID=`tuples`.sensorID)
48 JOIN `save_energy`.`rooms` ON (`sensors`.roomID=`rooms`.roomID)
49 WHERE `sensors`.name LIKE '%usage'
50 AND DATE(`tuples`.start) = CURRENT_DATE() - INTERVAL 47 DAY
51 AND `rooms`.name='$room'
52 ORDER BY `sensors`.description ASC
53 ");
54
55 while($row = mysql_fetch_array($result))
56 {
57 $description[] = ($row['description']);
58 }
59
60
61
62 $chart = new open_flash_chart();
63 $line_default_dot = new dot();
64 $line_default_dot->size(4)->halo_size(2)->colour('#000000');
65
66 foreach($description as $value)
67 {
68 $colorcode++;
69 if($colorcode==1) {$color = '#f7921c';}
70 if($colorcode==2) {$color = '#bf7115';}
71 if($colorcode==3) {$color = '#6c3d06';}
72 if($colorcode==4) {$color = '#2d1d0a';}
73 if($colorcode==5) {$color = '#2d1d0a';}
74 if($colorcode==6) {$color = '#2d1d0a';}
75 $name=$value;
76
77 $result1 = mysql_query("
78 SELECT value*1000 AS value
79 FROM (`save_energy`.`tuples`)
80 JOIN `save_energy`.`sensors` ON (`tuples`.sensorID=`sensors`.sensorID)
81 JOIN `save_energy`.`rooms` ON (`sensors`.roomID=`rooms`.roomID)
82 WHERE DATE(`tuples`.start) = CURRENT_DATE() - INTERVAL 47 DAY
83 AND `sensors`.name LIKE '%usage'
84 AND `rooms`.name='$room'
85 AND `sensors`.description='$name'
86 ORDER BY `tuples`.start ASC
87 ");
88
89 while($row = mysql_fetch_array($result1))
90 {
91 $data[] = intval($row['value']);
92 }
93
94 $value = new line();
95 $value->set_default_dot_style($line_default_dot);
96 $value->set_values( $data );
97 $value->set_width( 2 );
98 $value->set_colour($color);
99 $value->set_key($name, 14);
100
101 $chart->add_element( $value );
102 unset($data);
103 }
104
105 //-- Y AXIS --\\
106
107 $y = new y_axis();
108 $y->set_range( 0, 300, 30 );
109 $y->set_colour('#000000');
110 $y->set_grid_colour('#D8D8D8');
111
112
113 //-- X AXIS --\\
114
115 $x = new x_axis();
116 $x->offset(false)->steps(1);
117 $x->colour('#000000')->grid_colour('#D8D8D8');
118
119 $x_labels = new x_axis_labels();
120 $x_labels->set_steps( 3 );
121 $x_labels->set_colour( '#000000' );
122 $x_labels->set_labels( $xaxis );
123 $x->set_labels( $x_labels );
124
125
126 //-- CHART --\\
127
128 $title = new title('Electriciteitverbruik in kamer '.$room.' in Wh (Watt per uur)');
129 $chart->set_title( $title );
130 $chart->set_x_axis( $x );
131 $chart->set_y_axis( $y );
132 $chart->set_bg_colour( '#FFFFFF' );
133
134
135 //-- WRITE TO FILE --\\
136
137 echo $chart->toPrettyString();
138 $chartwrite = $chart->toPrettyString();
139
140 $fh = fopen("graphs/elec_".$room.".txt", 'w') or die("can't open file");
141 fwrite($fh, $chartwrite);
142 fclose($fh);
143 unset($xaxis);
144}
145
146?>
Note: See TracBrowser for help on using the repository browser.