PageRenderTime 44ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/branches/SM-1_4_10/locales/support/smstats/history-functions.php

#
PHP | 311 lines | 195 code | 69 blank | 47 comment | 23 complexity | a321c9f47fb91c65d64ca2f2a46fa67a MD5 | raw file
Possible License(s): AGPL-1.0, GPL-2.0
  1. <?php
  2. ////////////////////////////////////////////////////////////////////////////
  3. // $Id: history-functions.php 8819 2005-02-08 11:35:07Z tokul $
  4. //
  5. // Description: common functions for GUI messages history statistics
  6. //
  7. ////////////////////////////////////////////////////////////////////////////
  8. /**************************************************************************/
  9. //
  10. // formating a date returned by MySQL
  11. //
  12. function pretty_date($date="1970-01-01") {
  13. $year=substr($date,0,4);
  14. $month=substr($date,5,2);
  15. $day=substr($date,8,2);
  16. return date("d M Y",mktime(0,0,0,$month,$day,$year));
  17. }
  18. /**************************************************************************/
  19. //
  20. // initialize graphs classes
  21. //
  22. function init_graphs() {
  23. global $rundate;
  24. // Create the graphs
  25. $tdate1 = new Text();
  26. $tdate1->SetFont(FF_ARIAL,FS_NORMAL,8);
  27. $tdate1->SetColor("#000000");
  28. $tdate1->Set("generated at: $rundate");
  29. $tdate1->SetBox("#ffffff","#8b898b","#aaaaaa",0,0);
  30. $tdate1->SetPos(280,220);
  31. $tdate2 = new Text();
  32. $tdate2->SetFont(FF_ARIAL,FS_NORMAL,8);
  33. $tdate2->SetColor("#000000");
  34. $tdate2->Set("generated at: $rundate");
  35. $tdate2->SetBox("#ffffff","#8b898b","#aaaaaa",0,0);
  36. $tdate2->SetPos(560,420);
  37. // ** ------------- **
  38. $graph1 = new Graph(470,250,"auto");
  39. $graph1->SetScale("textlin");
  40. $graph1->SetShadow();
  41. $graph1->SetBox();
  42. $graph1->img->SetMargin(60,30,30,80);
  43. $graph1->SetMarginColor('#ececec');
  44. $graph1->title->SetFont(FF_ARIAL,FS_BOLD,12);
  45. $graph1->AddText($tdate1);
  46. // --------------
  47. $graph1->ygrid->Show(true,true);
  48. $graph1->yaxis->title->SetFont(FF_ARIAL,FS_BOLD,10);
  49. $graph1->yaxis->title->SetAngle(90);
  50. $graph1->yaxis->SetTitleMargin(40);
  51. $graph1->yaxis->title->Text("Translated Messages","high");
  52. $graph1->yaxis->SetFont(FF_ARIAL,FS_NORMAL,8);
  53. $graph1->yaxis->SetLabelAngle(0);
  54. $graph1->yaxis->SetPos('min');
  55. // -------------
  56. $graph1->xgrid->Show(false,false);
  57. $graph1->xaxis->title->SetFont(FF_ARIAL,FS_BOLD,10);
  58. $graph1->xaxis->title->SetAngle(0);
  59. $graph1->xaxis->title->Text("Days");
  60. $graph1->xaxis->SetFont(FF_ARIAL,FS_NORMAL,8);
  61. $graph1->xaxis->SetLabelAngle(30);
  62. $graph1->xaxis->SetTextLabelInterval(10);
  63. $graph1->xaxis->SetPos('min');
  64. $sline = new PlotLine(HORIZONTAL,0,"black",1);
  65. $graph1->Add($sline);
  66. // ** ------------- **
  67. $graph2 = new Graph(750,450,"auto");
  68. $graph2->SetScale("textlin");
  69. $graph2->SetShadow();
  70. $graph2->SetBox();
  71. $graph2->img->SetMargin(60,30,30,80);
  72. $graph2->SetMarginColor('#ececec');
  73. $graph2->title->SetFont(FF_ARIAL,FS_BOLD,12);
  74. $graph2->AddText($tdate2);
  75. // --------------
  76. $graph2->ygrid->Show(true,true);
  77. $graph2->yaxis->title->SetFont(FF_ARIAL,FS_BOLD,10);
  78. $graph2->yaxis->title->SetAngle(90);
  79. $graph2->yaxis->SetTitleMargin(40);
  80. $graph2->yaxis->title->Text("Translated Messages","high");
  81. $graph2->yaxis->SetFont(FF_ARIAL,FS_NORMAL,8);
  82. $graph2->yaxis->SetLabelAngle(0);
  83. $graph2->yaxis->SetPos('min');
  84. // -------------
  85. $graph2->xgrid->Show(true,false);
  86. $graph2->xaxis->title->SetFont(FF_ARIAL,FS_BOLD,10);
  87. $graph2->xaxis->title->SetAngle(0);
  88. $graph2->xaxis->title->Text("Days");
  89. $graph2->xaxis->SetFont(FF_ARIAL,FS_NORMAL,8);
  90. $graph2->xaxis->SetLabelAngle(30);
  91. $graph2->xaxis->SetTextLabelInterval(10);
  92. $graph2->xaxis->SetPos('min');
  93. $sline = new PlotLine(HORIZONTAL,0,"black",1);
  94. $graph2->Add($sline);
  95. return array($graph1,$graph2);
  96. }
  97. //
  98. // initialize graphs classes
  99. //
  100. function destroy_graphs($list) {
  101. foreach($list as $item) {
  102. if (isset($item)) {
  103. unset($item);
  104. }
  105. }
  106. }
  107. //
  108. // make history graph by revision for essential files(level 0)
  109. //
  110. function make_historybyrev($outfile1="",$outfile2="") {
  111. global $dbh, $rev, $m_teams;
  112. debug(10,"making history graph by CVS branch");
  113. $results=@mysql_query("SELECT sdate, SUM(translated) AS translated, SUM(total) AS total " .
  114. " FROM essential WHERE rev='$rev' AND team<>'templates' " .
  115. " GROUP BY sdate ORDER BY sdate LIMIT 0,60"
  116. ,$dbh);
  117. if (!$results) {
  118. send_err("SQL error: historybyrev rev=$rev; team<>templates");
  119. exit();
  120. }
  121. $points_x=array();
  122. $points_y=array();
  123. $my_y=-1;
  124. while ($row=@mysql_fetch_array($results)) {
  125. array_push($points_x,pretty_date($row['sdate']));
  126. if ($my_y==-1) {
  127. $my_y=$row['translated'];
  128. } else {
  129. if ($my_y==-1) $my_y=0;
  130. array_push($points_y,$row['translated']-$my_y);
  131. $my_y=$row['translated'];
  132. }
  133. }
  134. list($graph1,$graph2)=init_graphs();
  135. $lineplot=new LinePlot($points_y);
  136. $lineplot->SetColor('blueviolet');
  137. $lineplot->SetStepStyle();
  138. $graph1->xaxis->SetTickLabels($points_x);
  139. $graph1->Add($lineplot);
  140. $graph1->title->Set("Essential files history for $rev branch");
  141. $graph1->Stroke($outfile1);
  142. $graph2->xaxis->SetTickLabels($points_x);
  143. $graph2->Add($lineplot);
  144. $graph2->title->Set("Essential files history for $rev branch");
  145. $graph2->Stroke($outfile2);
  146. destroy_graphs(array($graph1,$graph2));
  147. }
  148. /**************************************************************************/
  149. //
  150. // make history graph by team for essential files (level 1)
  151. //
  152. function make_historybyteam($teamcode="") {
  153. global $dbh, $rev, $outdir, $m_teams;
  154. $results=@mysql_query("SELECT sdate, SUM(translated) AS translated, SUM(total) AS total " .
  155. " FROM essential WHERE rev='$rev' AND team='$teamcode' " .
  156. " GROUP BY sdate ORDER BY sdate LIMIT 0,60"
  157. ,$dbh);
  158. if (!$results) {
  159. send_err("SQL error: historybyrev rev=$rev; teamcode=$teamcode");
  160. exit();
  161. }
  162. $points_x=array();
  163. $points_y=array();
  164. $my_y=-1;
  165. while ($row=@mysql_fetch_array($results)) {
  166. $points_x[]=pretty_date($row['sdate']);
  167. if ($my_y==-1) {
  168. $my_y=$row['translated'];
  169. } else {
  170. if ($my_y==-1) $my_y=0;
  171. $points_y[]=$row['translated']-$my_y;
  172. $my_y=$row['translated'];
  173. }
  174. }
  175. if (count($points_y)<1) return;
  176. $teamname=$m_teams[$teamcode];
  177. list($graph1,$graph2)=init_graphs();
  178. $lineplot=new LinePlot($points_y);
  179. $lineplot->SetColor('blueviolet');
  180. $lineplot->SetStepStyle();
  181. $graph1->xaxis->SetTickLabels($points_x);
  182. $graph1->Add($lineplot);
  183. $graph1->title->Set("Essential files history for $teamname team");
  184. $graph1->Stroke("$outdir/$rev/$teamcode/essential.png");
  185. $graph2->xaxis->SetTickLabels($points_x);
  186. $graph2->Add($lineplot);
  187. $graph2->title->Set("Essential files history for $teamname team");
  188. $graph2->Stroke("$outdir/$rev/$teamcode/essential-big.png");
  189. destroy_graphs(array($graph1,$graph2));
  190. }
  191. /**************************************************************************/
  192. //
  193. // send email for success operation
  194. //
  195. function send_ok($message="") {
  196. global $rev, $adminemail, $prog;
  197. mail($adminemail,"OK $prog ($rev)","$message\n");
  198. }
  199. //
  200. // send email for failed operation
  201. //
  202. function send_err($message="") {
  203. global $rev, $adminemail, $prog;
  204. mail($adminemail,"ERROR $prog ($rev)","$message\n");
  205. }
  206. //
  207. // display debug message to STDOUT according with debug level
  208. //
  209. function debug($level=0,$message="") {
  210. global $debug;
  211. if ($level <= $debug) {
  212. echo $message ."\n";
  213. }
  214. }
  215. //
  216. // open connection to MySQL server for named database
  217. //
  218. function initdb($host,$user,$pass,$db) {
  219. if ($conn_handler = @mysql_connect($host,$user,$pass)) {
  220. if (@mysql_select_db($db,$conn_handler)) {
  221. return $conn_handler;
  222. } else {
  223. send_err("Cannot select '$db' database!");
  224. exit();
  225. }
  226. } else {
  227. send_err("Cannot connect to SQL server!");
  228. exit();
  229. }
  230. }
  231. //
  232. // close database connection
  233. //
  234. function closedb($conn_handler) {
  235. if (@mysql_close($conn_handler)) {
  236. return ;
  237. } else {
  238. send_err("Cannot close SQL server connection!");
  239. exit();
  240. }
  241. }
  242. ?>