/[gentoo-src]/gentoo-stats/stats.inc.php
Gentoo

Contents of /gentoo-stats/stats.inc.php

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (show annotations) (download)
Tue Apr 29 13:13:00 2003 UTC (11 years, 3 months ago) by mksoft
Branch: MAIN
initial import of gentoo-stats

1 <?php
2 /**
3 * Gentoo stats
4 * Written by Meir Kriheli <mksoft.gentoo.org>
5 * Based on gentoo-stats by Maik Schreiber <blizzy@gentoo.org>
6 *
7 * $Id$
8 *
9 * vim: set tabstop=4 shiftwidth=4:
10 */
11
12 /********** Config section *****************/
13
14 $db_server = 'localhost';
15 $db_name = 'gentoo';
16 $db_user = 'genstats';
17 $db_pass = 'a45fgt34';
18
19 $menu = array(
20 'index.php' => 'Home' ,
21 'general.php' => 'General',
22 'profiles.php' => 'Profiles',
23 'cpus.php' => 'CPUs',
24 'cards.php' => 'Expansion Cards',
25 'package_hi.php' => 'Package Highlights',
26 'package_cat.php' => 'Package Categories'
27 );
28
29 // numbers of days considering the user is active
30 $active_days = 14;
31 $max_accepted_cpu_mhz = 4000;
32
33 define('GRID_STR',"\t<tr><td class=\"%s\" style=\"text-align:right;\">%s</td><td class=\"%s\">%s</td></tr>\n");
34 define('GRID_SPACER',"<tr><td clospan=\"2\"></td></tr>\n");
35 define('TOTAL_SYSTEMS','Total # of monitored systems');
36 define('UPDATED_SYSTEMS',"Systems updated during last $active_days days");
37 define('LAST_UPDATED','Last update from a system');
38 define('TOTAL_CPUS','Total # of monitored CPUs');
39 define('AVG_CPUS','Average # of CPUs per system');
40 define('AVG_MHZ','Average speed of CPUs');
41 define('MIN_MHZ','Minimum speed of CPU');
42 define('MAX_MHZ','Maximum speed of CPU');
43
44 /********** End of config section **********/
45
46 require_once('DB.php');
47 require_once('Smarty.class.php');
48
49 // get the db connection
50 $db = & DB::connect("mysql://$db_user:$db_pass@$db_server/$db_name");
51 $smarty = & new Smarty;
52
53 function showHeader() {
54 ?>
55 <html>
56 <head>
57 <title>Gentoo stats</title>
58 <link rel="stylesheet" href="stats.css" type="text/css">
59 </head>
60 <body>
61 <table width="100%" cellspacing="0" cellspacing="3">
62 <tr><td class="header">Gentoo stats</td></tr>
63 <tr>
64 <td class="menu">
65 <?php
66 reset($GLOBALS['menu']);
67 $first = true;
68 while ( list($url,$caption) = each($GLOBALS['menu']) ) {
69 if ($first) $first=false;
70 else echo " | ";
71 echo "<a href=\"$url\" class=\"menulink\">$caption</a>";
72 }
73 ?>
74 </td>
75 </tr>
76 </table>
77 <div class="content">
78 <?php
79 }
80
81 function showFooter() {
82 ?>
83 </div>
84 </body></html>
85 <?php
86 }
87
88 function getTotalUsers() {
89 global $db;
90
91 $sql = "SELECT COUNT(*) FROM t_users WHERE (u_last_update IS NOT NULL) " .
92 " AND (u_last_update >= '2002-01-01 00:00:00')";
93 $totalUsers = $db->getOne($sql);
94
95 if (!DB::isError($totalUsers)) {
96 return $totalUsers;
97 }
98 else {
99 return false;
100 }
101 }
102
103 function getActiveUsers() {
104 global $db,$active_days;
105
106 $sql= "SELECT count(*) FROM t_users WHERE (u_last_update IS NOT NULL) " .
107 "AND (TO_DAYS(NOW()) - TO_DAYS(u_last_update) <= $active_days)";
108
109 $totalUsers = $db->getOne($sql);
110
111 if (!DB::isError($totalUsers)) {
112 return $totalUsers;
113 }
114 else {
115 return false;
116 }
117 }
118
119 function getLastSystemUpdate() {
120 global $db,$active_days;
121
122 $sql= "SELECT MAX(u_last_update) FROM t_users WHERE " .
123 "(u_last_update IS NOT NULL)";
124
125 $last_update = $db->getOne($sql);
126
127 if (!DB::isError($last_update)) {
128 return $last_update;
129 }
130 else {
131 return false;
132 }
133 }
134
135 function getTotalCPUs() {
136 global $db,$active_days;
137
138 $sql= "SELECT count(*) FROM t_users u, t_users2cpus c WHERE " .
139 "(u.u_id = c.u_id) AND (u_last_update IS NOT NULL) " .
140 "AND (TO_DAYS(NOW()) - TO_DAYS(u_last_update) <= $active_days)";
141
142 $totalCPUs = $db->getOne($sql);
143
144 if (!DB::isError($totalCPUs)) {
145 return $totalCPUs;
146 }
147 else {
148 return false;
149 }
150 }
151
152 function getCPUStats() {
153 global $db,$active_days,$max_accepted_cpu_mhz;
154
155 $max_mhz = $max_accepted_cpu_mhz * 10000;
156
157 $sql= "SELECT MAX(c.c_mhz), MIN(c.c_mhz), avg(c.c_mhz) FROM t_users u, t_users2cpus c WHERE " .
158 "(u.u_id = c.u_id) AND (u_last_update IS NOT NULL) " .
159 "AND (TO_DAYS(NOW()) - TO_DAYS(u_last_update) <= $active_days) " .
160 "AND (c_mhz IS NOT NULL) AND (c_mhz < $max_mhz)";
161 $CPUStats = $db->getRow($sql);
162
163 if (!DB::isError($CPUStats)) {
164 return $CPUStats;
165 }
166 else {
167 return false;
168 }
169 }
170 ?>

  ViewVC Help
Powered by ViewVC 1.1.20