1 | <?php |
||||
2 | // This file is part of BOINC. |
||||
3 | // http://boinc.berkeley.edu |
||||
4 | // Copyright (C) 2008 University of California |
||||
5 | // |
||||
6 | // BOINC is free software; you can redistribute it and/or modify it |
||||
7 | // under the terms of the GNU Lesser General Public License |
||||
8 | // as published by the Free Software Foundation, |
||||
9 | // either version 3 of the License, or (at your option) any later version. |
||||
10 | // |
||||
11 | // BOINC is distributed in the hope that it will be useful, |
||||
12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
||||
14 | // See the GNU Lesser General Public License for more details. |
||||
15 | // |
||||
16 | // You should have received a copy of the GNU Lesser General Public License |
||||
17 | // along with BOINC. If not, see <http://www.gnu.org/licenses/>. |
||||
18 | |||||
19 | // DEPRECATED - WON'T WORK. |
||||
20 | // result.claimed_credit is not used any more |
||||
21 | |||||
22 | // Award credit to users/hosts/teams for WU which have been |
||||
23 | // cancelled or have otherwise failed (error_mask != 0). |
||||
24 | // Credit granted is credit claimed, with a hardwired limit of 300 units. |
||||
25 | // To enable this script change 1 to 0 in the testquery() function. |
||||
26 | // The script can be run multiple times without doing any harm. |
||||
27 | // It only grants credit to results which do not (yet) have any |
||||
28 | // granted credits. So it can be run multiple times. |
||||
29 | |||||
30 | |||||
31 | $cli_only = true; |
||||
32 | require_once("../inc/util_ops.inc"); |
||||
33 | require_once("../inc/credit.inc"); |
||||
34 | |||||
35 | set_time_limit(0); |
||||
36 | |||||
37 | db_init(); |
||||
38 | |||||
39 | // set variable to 0 to 'do it for real' |
||||
40 | |||||
41 | function testquery($argstring) { |
||||
42 | if (0) { |
||||
43 | echo "WOULD DO: $argstring\n"; |
||||
44 | } |
||||
45 | else { |
||||
46 | _mysql_query($argstring); |
||||
47 | } |
||||
48 | return; |
||||
0 ignored issues
–
show
Coding Style
introduced
by
![]() |
|||||
49 | } |
||||
50 | |||||
51 | function grant_credits_for_wu($wuid) { |
||||
52 | $max_credit=300; |
||||
53 | $ndone = 0; |
||||
54 | $query_r = _mysql_query("select * from result where granted_credit=0 and claimed_credit>0 and workunitid=$wuid"); |
||||
55 | |||||
56 | while ($result = _mysql_fetch_object($query_r)) { |
||||
57 | echo "STARTING RESULT $result->id [Credit $result->claimed_credit] ..."; |
||||
58 | $ndone++; |
||||
59 | |||||
60 | $hostid = $result->hostid; |
||||
61 | $query_h = _mysql_query("select * from host where id=$hostid"); |
||||
62 | $host = _mysql_fetch_object($query_h); |
||||
63 | |||||
64 | $userid = $result->userid; |
||||
65 | $query_u = _mysql_query("select * from user where id=$userid"); |
||||
66 | $user = _mysql_fetch_object($query_u); |
||||
67 | |||||
68 | $credit = $result->claimed_credit; |
||||
69 | if ($credit>$max_credit) { |
||||
70 | $credit=$max_credit; |
||||
71 | echo " WARNING: USER $user->name ($userid) CLAIMED $result->claimed_credit CREDITS (getting $credit)!"; |
||||
72 | } |
||||
73 | $user->total_credit += $credit; |
||||
74 | update_average(time(0), $result->sent_time, $credit, $user->expavg_credit, $user->expavg_time); |
||||
0 ignored issues
–
show
The call to
time() has too many arguments starting with 0 .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue. If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above. ![]() |
|||||
75 | |||||
76 | $host->total_credit += $credit; |
||||
77 | update_average(time(0), $result->sent_time, $credit, $host->expavg_credit, $host->expavg_time); |
||||
78 | |||||
79 | $turnaround = $result->received_time - $result->sent_time; |
||||
80 | if ($host->avg_turnaround > 0) |
||||
81 | $host->avg_turnaround = 0.7*$host->avg_turnaround + 0.3*$turnaround; |
||||
82 | else |
||||
83 | $host->avg_turnaround = $turnaround; |
||||
84 | |||||
85 | testquery("update result set granted_credit=$credit where id=$result->id"); |
||||
86 | |||||
87 | testquery("update user set total_credit=$user->total_credit, expavg_credit=$user->expavg_credit, expavg_time=$user->expavg_time where id=$userid"); |
||||
88 | |||||
89 | testquery("update host set total_credit=$host->total_credit, expavg_credit=$host->expavg_credit, expavg_time=$host->expavg_time, avg_turnaround=$host->avg_turnaround where id=$hostid"); |
||||
90 | |||||
91 | $teamid = $user->teamid; |
||||
92 | if ($teamid) { |
||||
93 | $query_t = _mysql_query("select * from team where id=$teamid"); |
||||
94 | $team = _mysql_fetch_object($query_t); |
||||
95 | $team->total_credit += $credit; |
||||
96 | update_average(time(0), $result->sent_time, $credit, $team->expavg_credit, $team->expavg_time); |
||||
97 | testquery("update team set total_credit=$team->total_credit, expavg_credit=$team->expavg_credit, expavg_time=$team->expavg_time where id=$teamid"); |
||||
98 | _mysql_free_result($query_t); |
||||
99 | } |
||||
100 | _mysql_free_result($query_h); |
||||
101 | _mysql_free_result($query_u); |
||||
102 | echo " DONE\n"; |
||||
103 | } |
||||
104 | _mysql_free_result($query_r); |
||||
105 | return $ndone; |
||||
106 | } |
||||
107 | |||||
108 | function grant_credits_for_cancelled() { |
||||
109 | $ngranted=0; |
||||
110 | $query_w = _mysql_query("select * from workunit where error_mask!=0"); |
||||
111 | while (($workunit = _mysql_fetch_object($query_w))) { |
||||
112 | // echo "Starting WU $workunit->id\n"; |
||||
113 | $ngranted += grant_credits_for_wu($workunit->id); |
||||
114 | // NEED TO SET assimilate_state=READY for WU!! |
||||
115 | } |
||||
116 | _mysql_free_result($query_w); |
||||
117 | |||||
118 | echo "\nGranted credits to $ngranted results\n"; |
||||
119 | } |
||||
120 | |||||
121 | grant_credits_for_cancelled(); |
||||
122 | |||||
123 | ?> |
||||
124 |