/[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.4 - (show annotations) (download)
Fri May 9 10:01:08 2003 UTC (11 years, 5 months ago) by mksoft
Branch: MAIN
CVS Tags: HEAD
Changes since 1.3: +2 -2 lines
intital cards page/template

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: stats.inc.php,v 1.3 2003/04/29 16:26:14 mksoft Exp $
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 // numbers of days considering the user is active
20 $active_days = 140;
21 $max_accepted_cpu_mhz = 4000;
22 $bar_width = 250;
23
24 /********** End of config section **********/
25
26 require_once('DB.php');
27 require_once('Smarty.class.php');
28
29 // get the db connection
30 $db = & DB::connect("mysql://$db_user:$db_pass@$db_server/$db_name");
31
32 $smarty = & new Smarty;
33 $smarty->assign('active_days',$active_days);
34
35
36 function getTotalUsers() {
37 global $db;
38
39 $sql = "SELECT COUNT(*) FROM t_users WHERE (u_last_update IS NOT NULL) " .
40 " AND (u_last_update >= '2002-01-01 00:00:00')";
41 $totalUsers = $db->getOne($sql);
42
43 if (!DB::isError($totalUsers)) {
44 return $totalUsers;
45 }
46 else {
47 return false;
48 }
49 }
50
51 function getActiveUsers() {
52 global $db,$active_days;
53
54 $sql= "SELECT count(*) FROM t_users WHERE (u_last_update IS NOT NULL) " .
55 "AND (TO_DAYS(NOW()) - TO_DAYS(u_last_update) <= $active_days)";
56
57 $totalUsers = $db->getOne($sql);
58
59 if (!DB::isError($totalUsers)) {
60 return $totalUsers;
61 }
62 else {
63 return false;
64 }
65 }
66
67 function getLastSystemUpdate() {
68 global $db,$active_days;
69
70 $sql= "SELECT MAX(u_last_update) FROM t_users WHERE " .
71 "(u_last_update IS NOT NULL)";
72
73 $last_update = $db->getOne($sql);
74
75 if (!DB::isError($last_update)) {
76 return $last_update;
77 }
78 else {
79 return false;
80 }
81 }
82
83 function getTotalCPUs() {
84 global $db,$active_days;
85
86 $sql= "SELECT count(*) FROM t_users u, t_users2cpus c WHERE " .
87 "(u.u_id = c.u_id) AND (u_last_update IS NOT NULL) " .
88 "AND (TO_DAYS(NOW()) - TO_DAYS(u_last_update) <= $active_days)";
89
90 $totalCPUs = $db->getOne($sql);
91
92 if (!DB::isError($totalCPUs)) {
93 return $totalCPUs;
94 }
95 else {
96 return false;
97 }
98 }
99
100 function getCPUStats() {
101 global $db,$active_days,$max_accepted_cpu_mhz;
102
103 $max_mhz = $max_accepted_cpu_mhz * 10000;
104
105 $sql= "SELECT MAX(c.c_mhz), MIN(c.c_mhz), avg(c.c_mhz) FROM t_users u, t_users2cpus c WHERE " .
106 "(u.u_id = c.u_id) AND (u_last_update IS NOT NULL) " .
107 "AND (TO_DAYS(NOW()) - TO_DAYS(u_last_update) <= $active_days) " .
108 "AND (c_mhz IS NOT NULL) AND (c_mhz < $max_mhz)";
109 $CPUStats = $db->getRow($sql);
110
111 if (!DB::isError($CPUStats)) {
112 return $CPUStats;
113 }
114 else {
115 return false;
116 }
117 }
118
119 function getKnownProfilesCount() {
120 global $db,$active_days;
121
122 $sql= "SELECT count(*) FROM t_users WHERE (pr_id IS NOT NULL) AND (u_last_update IS NOT NULL) " .
123 "AND (TO_DAYS(NOW()) - TO_DAYS(u_last_update) <= $active_days)";
124
125 $totalUsers = $db->getOne($sql);
126
127 if (!DB::isError($totalUsers)) {
128 return $totalUsers;
129 }
130 else {
131 return false;
132 }
133 }
134
135 ?>

  ViewVC Help
Powered by ViewVC 1.1.20