/[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.2 - (hide annotations) (download)
Tue Apr 29 14:30:55 2003 UTC (11 years, 5 months ago) by mksoft
Branch: MAIN
Changes since 1.1: +4 -57 lines
switched code generation to smarty templates

1 mksoft 1.1 <?php
2     /**
3     * Gentoo stats
4 mksoft 1.2 * Written by Meir Kriheli <mksoft@gentoo.org>
5 mksoft 1.1 * Based on gentoo-stats by Maik Schreiber <blizzy@gentoo.org>
6     *
7 mksoft 1.2 * $Id: stats.inc.php,v 1.1 2003/04/29 13:13:00 mksoft Exp $
8 mksoft 1.1 *
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 = 14;
21     $max_accepted_cpu_mhz = 4000;
22    
23     /********** End of config section **********/
24    
25     require_once('DB.php');
26     require_once('Smarty.class.php');
27    
28     // get the db connection
29     $db = & DB::connect("mysql://$db_user:$db_pass@$db_server/$db_name");
30 mksoft 1.2
31 mksoft 1.1 $smarty = & new Smarty;
32 mksoft 1.2 $smarty->assign('active_days',$active_days);
33 mksoft 1.1
34    
35     function getTotalUsers() {
36     global $db;
37    
38     $sql = "SELECT COUNT(*) FROM t_users WHERE (u_last_update IS NOT NULL) " .
39     " AND (u_last_update >= '2002-01-01 00:00:00')";
40     $totalUsers = $db->getOne($sql);
41    
42     if (!DB::isError($totalUsers)) {
43     return $totalUsers;
44     }
45     else {
46     return false;
47     }
48     }
49    
50     function getActiveUsers() {
51     global $db,$active_days;
52    
53     $sql= "SELECT count(*) FROM t_users WHERE (u_last_update IS NOT NULL) " .
54     "AND (TO_DAYS(NOW()) - TO_DAYS(u_last_update) <= $active_days)";
55    
56     $totalUsers = $db->getOne($sql);
57    
58     if (!DB::isError($totalUsers)) {
59     return $totalUsers;
60     }
61     else {
62     return false;
63     }
64     }
65    
66     function getLastSystemUpdate() {
67     global $db,$active_days;
68    
69     $sql= "SELECT MAX(u_last_update) FROM t_users WHERE " .
70     "(u_last_update IS NOT NULL)";
71    
72     $last_update = $db->getOne($sql);
73    
74     if (!DB::isError($last_update)) {
75     return $last_update;
76     }
77     else {
78     return false;
79     }
80     }
81    
82     function getTotalCPUs() {
83     global $db,$active_days;
84    
85     $sql= "SELECT count(*) FROM t_users u, t_users2cpus c WHERE " .
86     "(u.u_id = c.u_id) AND (u_last_update IS NOT NULL) " .
87     "AND (TO_DAYS(NOW()) - TO_DAYS(u_last_update) <= $active_days)";
88    
89     $totalCPUs = $db->getOne($sql);
90    
91     if (!DB::isError($totalCPUs)) {
92     return $totalCPUs;
93     }
94     else {
95     return false;
96     }
97     }
98    
99     function getCPUStats() {
100     global $db,$active_days,$max_accepted_cpu_mhz;
101    
102     $max_mhz = $max_accepted_cpu_mhz * 10000;
103    
104     $sql= "SELECT MAX(c.c_mhz), MIN(c.c_mhz), avg(c.c_mhz) FROM t_users u, t_users2cpus c WHERE " .
105     "(u.u_id = c.u_id) AND (u_last_update IS NOT NULL) " .
106     "AND (TO_DAYS(NOW()) - TO_DAYS(u_last_update) <= $active_days) " .
107     "AND (c_mhz IS NOT NULL) AND (c_mhz < $max_mhz)";
108     $CPUStats = $db->getRow($sql);
109    
110     if (!DB::isError($CPUStats)) {
111     return $CPUStats;
112     }
113     else {
114     return false;
115     }
116     }
117     ?>

  ViewVC Help
Powered by ViewVC 1.1.20