| [ Index ] |
|
Code source de Dolibarr 2.0.1 |
1 <?PHP 2 /* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org> 3 * 4 * This program is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation; either version 2 of the License, or 7 * (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program; if not, write to the Free Software 16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 * 18 * $Id: graph-line.php,v 1.4 2005/10/18 14:03:06 eldy Exp $ 19 * $Source: /cvsroot/dolibarr/dolibarr/scripts/energie/graph-line.php,v $ 20 * 21 */ 22 23 require_once ("../../htdocs/master.inc.php"); 24 25 require_once(DOL_DOCUMENT_ROOT."/energie/EnergieCompteur.class.php"); 26 require_once(DOL_DOCUMENT_ROOT."/energie/EnergieGroupe.class.php"); 27 28 include_once(JPGRAPH_DIR."jpgraph.php"); 29 include_once(JPGRAPH_DIR."jpgraph_line.php"); 30 31 $error = 0; 32 33 $labels = array(); 34 $datas = array(); 35 36 $sql_c = "SELECT rowid"; 37 $sql_c .= " FROM ".MAIN_DB_PREFIX."energie_compteur"; 38 39 $resql_c = $db->query($sql_c); 40 41 $user = New User($db); 42 43 if ($resql_c) 44 { 45 $num_c = $db->num_rows($resql_c); 46 $i_c = 0; 47 48 if ($num_c > 0) 49 { 50 while ($i_c < $num_c) 51 { 52 $obj_c = $db->fetch_object($resql_c); 53 54 $compteur = New EnergieCompteur($db, $user); 55 $compteur->fetch($obj_c->rowid); 56 57 $compteur_id = $obj_c->rowid; 58 59 $sql = "SELECT ".$db->pdate("date_releve")." as date_releve, valeur"; 60 $sql .= " FROM ".MAIN_DB_PREFIX."energie_compteur_releve"; 61 $sql .= " WHERE fk_compteur = ".$obj_c->rowid; 62 $sql .= " ORDER BY date_releve ASC"; 63 64 $resql = $db->query($sql); 65 66 if ($resql) 67 { 68 $num = $db->num_rows($resql); 69 $i = 0; 70 71 if ($num > 0) 72 { 73 $obj = $db->fetch_object($resql); 74 75 //print strftime("%Y-%m-%d", $obj->date_releve) . "\t\t".$obj->valeur."\n"; 76 77 $previous_date = $obj->date_releve; 78 $previous_value = $obj->valeur; 79 80 $i++; 81 } 82 83 $datas = array(); 84 $k = 0; 85 86 while ($i < $num) 87 { 88 $obj = $db->fetch_object($resql); 89 90 $delta = (($obj->date_releve - $previous_date) / 86400 ); 91 92 if ($delta > 1) 93 { 94 for ($j = 1 ; $j < $delta ; $j++) 95 { 96 $value = $previous_value + ((($obj->valeur - $previous_value) / $delta) * $j); 97 98 $datas[$k][0] = $value; 99 $datas[$k][1] = ($previous_date + (86400 * $j)); 100 $k++; 101 102 //print strftime("%Y-%m-%d", ($previous_date + (86400 * $j))) . "\t$j\t".$value."\n"; 103 } 104 } 105 106 //print strftime("%Y-%m-%d", $obj->date_releve) . "\t\t".$obj->valeur."\n"; 107 108 $datas[$k][0] = $obj->valeur; 109 $datas[$k][1] = $obj->date_releve; 110 $k++; 111 112 $previous_date = $obj->date_releve; 113 $previous_value = $obj->valeur; 114 $i++; 115 } 116 117 // Graph 118 $maxa = 0; 119 120 $xdatas = array(); 121 $xlabels = array(); 122 123 for ($i = 1 ; $i < sizeof($datas) ; $i++) 124 { 125 $xa = ($datas[$i][0] - $datas[($i-1)][0]); 126 127 $maxa = max($maxa, $xa); 128 129 $gdatas[$i-1] = $xa; 130 $glabels[$i-1] = strftime("%d%m",$datas[$i][1]); 131 132 $xdatas[$glabels[$i-1]] = $gdatas[$i-1]; 133 } 134 135 $year = strftime("%Y", time()); 136 $xyear = $year; 137 $day = mktime(0,0,0,1,1,$year); 138 139 $xydatas = array(); 140 $xylabels = array(); 141 $i=0; 142 while ($xyear == $year) 143 { 144 $xydatas[$i] = $xdatas[strftime("%d%m",$day)]; 145 $xylabels[$i] = ''; 146 147 $i++; 148 $day += 86400; 149 $xyear = strftime("%Y",$day); 150 } 151 152 if (sizeof($xydatas) > 2) 153 { 154 $width = 750; 155 $height = 300; 156 $graph = new Graph($width, $height,"auto"); 157 $graph->SetScale("textlin"); 158 159 $graph->yaxis->scale->SetGrace(2); 160 $graph->SetFrame(1); 161 $graph->img->SetMargin(40,20,20,35); 162 163 $b2plot = new LinePlot($xydatas); 164 165 $b2plot->SetColor("blue"); 166 167 $graph->title->Set("Consommation journalière"); 168 169 $graph->xaxis->Hide(); 170 171 $graph->Add($b2plot); 172 $graph->img->SetImgFormat("png"); 173 174 $file= DOL_DATA_ROOT."/energie/graph/all.".$obj_c->rowid.".png"; 175 176 $graph->Stroke($file); 177 178 $width = 300; 179 $height = 90; 180 $graph = new Graph($width, $height,"auto"); 181 $graph->SetScale("textlin"); 182 183 $graph->yaxis->scale->SetGrace(2); 184 $graph->SetFrame(1); 185 $graph->img->SetMargin(30,10,10,10); 186 187 $b2plot = new LinePlot($xydatas); 188 189 $b2plot->SetColor("blue"); 190 191 $graph->xaxis->Hide(); 192 193 $graph->Add($b2plot); 194 $graph->img->SetImgFormat("png"); 195 196 $file= DOL_DATA_ROOT."/energie/graph/small-all.".$obj_c->rowid.".png"; 197 198 $graph->Stroke($file); 199 200 } 201 else 202 { 203 //print "No graph ".sizeof($xydatas)."\n"; 204 } 205 } 206 else 207 { 208 dolibarr_syslog("Erreur SQL"); 209 dolibarr_syslog("$sql"); 210 } 211 $i_c++; 212 } 213 } 214 } 215 else 216 { 217 dolibarr_syslog("Erreur SQL"); 218 dolibarr_syslog($db->error($resql_c)); 219 } 220 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
| Généré le : Mon Nov 26 12:29:37 2007 | par Balluche grâce à PHPXref 0.7 |
|