-
Notifications
You must be signed in to change notification settings - Fork 7
/
su_keyword_stats.php
110 lines (96 loc) · 3 KB
/
su_keyword_stats.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
<?php
// This file is part of BOINC.
// http://boinc.berkeley.edu
// Copyright (C) 2018 University of California
//
// BOINC is free software; you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License
// as published by the Free Software Foundation,
// either version 3 of the License, or (at your option) any later version.
//
// BOINC is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
// See the GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with BOINC. If not, see <http://www.gnu.org/licenses/>.
// show yes/no stats for keywords
require_once("../inc/util.inc");
require_once("../inc/su.inc");
$nusers = 0;
function keyword_setup() {
global $job_keywords;
foreach ($job_keywords as $id=>$k) {
$job_keywords[$id]->children = array();
}
foreach ($job_keywords as $id=>$k) {
if (!$k->parent) continue;
$job_keywords[$k->parent]->children[] = $id;
}
}
function show_keyword($id) {
global $job_keywords, $nusers;
$k = $job_keywords[$id];
$spaces = "";
for ($i=0; $i<$k->level; $i++) {
$spaces .= " ";
}
row_array(array(
$spaces.$k->name,
show_pct_bar("#00ff00", 200, ((double)$k->nyes)/$nusers, 2),
show_pct_bar("#ff0000", 200, ((double)$k->nno)/$nusers, 2)
));
foreach ($k->children as $i) {
show_keyword($i);
}
}
function show_keywords($category) {
global $job_keywords;
row_heading_array(array("Keyword", "Yes", "No"), array("width=40%", "width=30%", "width=30%"));
foreach ($job_keywords as $id=>$k) {
if ($k->category != $category) continue;
if ($k->parent) continue;
show_keyword($id);
}
}
function main() {
global $job_keywords, $nusers;
keyword_setup();
$t = time()-7*86400;
// get list of IDs of active users
//
$user_ids = BoincDB::get()->enum_fields("su_accounting_user", "StdClass", "distinct(user_id)", "create_time > $t", "");
$nusers = count($user_ids);
// turn it into a map
//
$u = array();
foreach ($user_ids as $i) {
$u[$i->user_id] = true;
}
// get counts of yes/no for each keyword
//
foreach ($job_keywords as $id=>$k) {
$k->nyes = 0;
$k->nno = 0;
}
$user_kws = SUUserKeyword::enum();
foreach ($user_kws as $ukw) {
if (!array_key_exists($ukw->user_id, $u)) continue;
if ($ukw->yesno > 0) {
$job_keywords[$ukw->keyword_id]->nyes += 1;
} else {
$job_keywords[$ukw->keyword_id]->nno += 1;
}
}
page_head("Keyword statistics");
start_table("table-striped");
row_heading("Science Area");
show_keywords(KW_CATEGORY_SCIENCE);
row_heading("Location");
show_keywords(KW_CATEGORY_LOC);
end_table();
page_tail();
}
main();
?>