-
Notifications
You must be signed in to change notification settings - Fork 0
/
barplots12.php
141 lines (118 loc) · 5.1 KB
/
barplots12.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
<?php
include ("../jpgraph/jpgraph.php");
include ("../jpgraph/jpgraph_log.php");
include ("../jpgraph/jpgraph_bar.php");
include("../config/local.php");
$arr = get_defined_vars();
$i = mysql_connect ($mysql_host,$mysql_user,$mysql_password); $e=mysql_select_db ($mysql_db_name);
$query = "set character_set_client='cp1251'"; mysql_query ($query,$i);
$query = "set character_set_results='cp1251'"; mysql_query ($query,$i);
$query = "set collation_connection='cp1251_general_ci'"; mysql_query ($query,$i);
//------------------------------------------------------------------------
$today=getdate();
if ($_GET["year"]=='') $ye=$today["year"];
else $ye=$_GET["year"];
if ($_GET["month"]=='') { $today["mon"]--; $mn=$today["mon"]; }
else { $mn=$_GET["month"]; $today["mday"]=29; }
$sum1=$sum2=0;
$x=0;
$dy=31;
if (!checkdate ($mn,31,$ye)) { $dy=30; }
if (!checkdate ($mn,30,$ye)) { $dy=29; }
if (!checkdate ($mn,29,$ye)) { $dy=28; }
if ($today["mon"]<10) $today["mon"]='0'.$today["mon"];
if ($mn<10) $mn='0'.$mn;
//$mn=$today["mon"];
$cn=0;
for ($tm=1; $tm<=$dy; $tm++)
{
$data1[$cn]=$data2[$cn]=$count=$avg=0;
if ($tm<10) $tm='0'.$tm;
$date1=$ye.$mn.$tm.'000000';
$dat[$cn]=$tm.'-'.$mn;
$query='';
if ($_GET["n1"]==1) $query = 'SELECT SUM(value) FROM data WHERE prm=11 AND source=6 AND type=2 AND date='.$date1;
if ($_GET["n1"]==2) $query = 'SELECT SUM(value) FROM data WHERE prm=11 AND source=5 AND type=2 AND date='.$date1;
if ($_GET["n1"]==3) $query = 'SELECT SUM(value) FROM data WHERE prm=2 AND flat>0 AND type=2 AND date='.$date1;
if ($_GET["n1"]==4) $query = 'SELECT SUM(value),AVG(value),COUNT(id) FROM prdata WHERE (prm=13 OR prm=11) AND value>10 AND type=2 AND date='.$date1;
//echo $query;
$e = mysql_query ($query,$i);
$ui = mysql_fetch_row ($e);
if ($ui) { $data1[$cn]=$ui[0]; $avg=$ui[1]; $count=$ui[2]; }
if ($_GET["n1"]<4) $data1[$cn]=$data1[$cn];
else $data1[$cn]=$data1[$cn]/4184;
//echo $avg.' '.$count.'<br>';
if ($_GET["n1"]==4) if ($count>0) $data1[$cn]+=(42-$count)*($avg/4184);
$sum1+=$data1[$cn];
if ($_GET["n1"]==1)
{
$query = 'SELECT value FROM data WHERE prm=12 AND source=5 AND flat=0 AND type=2 AND date='.$date1;
$e = mysql_query ($query,$i);
$ui = mysql_fetch_row ($e);
if ($ui) $qgvs[$cn]=$ui[0];
}
if ($_GET["n1"]==1) $query = 'SELECT value FROM data WHERE prm=12 AND source=6 AND flat=0 AND type=2 AND date='.$date1;
if ($_GET["n1"]==2) $query = 'SELECT value FROM data WHERE prm=12 AND source=5 AND flat=0 AND type=2 AND date='.$date1;
if ($_GET["n1"]==3) $query = 'SELECT value/1000 FROM data WHERE prm=14 AND flat=0 AND type=2 AND date='.$date1;
if ($_GET["n1"]==4) $query = 'SELECT value FROM data WHERE prm=13 AND source=2 AND flat=0 AND type=2 AND date='.$date1;
$e = mysql_query ($query,$i);
$ui = mysql_fetch_row ($e);
if ($ui) $data2[$cn]=$ui[0];
if ($_GET["n1"]==1)
if ($data2[$cn]-$qgvs[$cn]>0) $data2[$cn]=$data2[$cn]-$qgvs[$cn];
else $data2[$cn]=0;
$sum2+=$data2[$cn];
$cn++;
}
$graph = new Graph(1200,200,"auto");
$graph->SetScale("textlin");
$graph->SetShadow();
// Create the linear plot
$lineplot=new BarPlot($data1);
$lineplot2=new BarPlot($data2);
$lineplot->SetFillColor("blue");
$lineplot2->SetFillColor("red");
$graph->xaxis->SetTickLabels($dat);
$graph->yaxis->HideZeroLabel();
$graph->SetMarginColor('lavender');
//$lineplot->SetShadow();
$lineplot->value->Show();
$lineplot2->value->Show();
$lineplot->value->SetFont(FF_ARIAL,FS_NORMAL,7);
$lineplot2->value->SetFont(FF_ARIAL,FS_NORMAL,7);
if ($_GET["n1"]<4)
{
$name='Èíäèâèäóàëüíîå ïîòðåáëåíèå '.number_format($sum1,2).' ';
if ($sum2>0) $pr=number_format(($sum2-$sum1)*100/($sum2),2);
$name2='Ðàñõîä ïî êîììåð÷åñêîìó óçëó ó÷åòà '.number_format($sum2,2).' '.' ('.$pr.' %) ';
}
if ($_GET["n1"]==4)
{
if ($sum1+$sum2>0) $pr=number_format($sum1*100/($sum1+$sum2),2);
else $pr='í/ä';
if ($sum2>0) $pr2=number_format(($sum2-$sum1)*100/($sum2),2);
else $pr2=0;
$name='Òåïëîïîòðåáëåíèå òåïëà ÑÎ '.number_format($sum1,2).' ('.$pr.' %)';
$name2='Ïîòðåáëåíèå òåïëà âñåì äîìîì '.number_format($sum2,2).' '.' ('.$pr2.' %) ';
}
$graph ->legend->Pos( 0.03,0.01,"right" ,"top");
$lineplot->SetLegend($name);
$lineplot2->SetLegend($name2);
$graph->legend->SetFont(FF_ARIAL,FS_NORMAL,8);
if ($_GET["n1"]==1) $graph->title->Set("Õîëîäíàÿ âîäà, òîëüêî ïîêàçàíèÿ áåç íîðìàòèâíîãî ïîòðåáëåíèÿ (ì3)");
if ($_GET["n1"]==2) $graph->title->Set("Ãîðÿ÷àÿ âîäà, òîëüêî ïîêàçàíèÿ áåç íîðìàòèâíîãî ïîòðåáëåíèÿ (ì3)");
if ($_GET["n1"]==3) $graph->title->Set("Ýëåêòðîýíåðãèÿ (êÂò/÷)");
if ($_GET["n1"]==4) $graph->title->Set("Áàëàíñ ïî ñòîÿêàì è âõîäó (ÃÊàë)");
// Add the plot to the graph
$graph->img->SetMargin(5,10,5,23);
//----------- title --------------------
$gbplot = new GroupBarPlot (array($lineplot ,$lineplot2));
$graph->Add($gbplot);
//----------- legend -------------------
$graph->title->SetFont(FF_ARIAL,FS_BOLD);
$graph->yaxis->title->SetFont(FF_ARIAL,FS_BOLD);
$graph->xaxis->title->SetFont(FF_ARIAL,FS_BOLD);
$graph->xaxis->SetFont(FF_ARIAL,FS_NORMAL,7);
// Display the graph
$graph->Stroke();
?>