|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @property integer $uid |
|
4
|
|
|
* @property array $stats |
|
5
|
|
|
*/ |
|
6
|
|
|
class PlayerStats extends CModel |
|
7
|
|
|
{ |
|
8
|
|
|
private $uid; |
|
9
|
|
|
private $stats = [ |
|
10
|
|
|
'completed_missions'=>0, |
|
11
|
|
|
'visited_waters'=>0, |
|
12
|
|
|
'visited_counties'=>0, |
|
13
|
|
|
'owned_setitems'=>0, |
|
14
|
|
|
'setitems'=>[], |
|
15
|
|
|
'items'=>[], |
|
16
|
|
|
'baits'=>[], |
|
17
|
|
|
'sets'=>[], |
|
18
|
|
|
'counties'=>[], |
|
19
|
|
|
]; |
|
20
|
|
|
|
|
21
|
|
|
public function attributeNames() |
|
22
|
|
|
{ |
|
23
|
|
|
return []; |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
public function getUid() |
|
27
|
|
|
{ |
|
28
|
|
|
return $this->uid; |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
public function getStats() |
|
32
|
|
|
{ |
|
33
|
|
|
return $this->stats; |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
public function setUid($uid) |
|
37
|
|
|
{ |
|
38
|
|
|
$this->uid = (int)$uid; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
public function fetchStats() |
|
42
|
|
|
{ |
|
43
|
|
|
$this->fetchCompletedMissions(); |
|
44
|
|
|
$this->fetchVisitedMissions(); |
|
45
|
|
|
$this->fetchDuel(); |
|
46
|
|
|
$this->fetchCountSets(); |
|
47
|
|
|
$this->fetchItems(); |
|
48
|
|
|
$this->fetchBaits(); |
|
49
|
|
|
$this->fetchSets(); |
|
50
|
|
|
$this->fetchRank(); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
protected function fetchCompletedMissions() |
|
54
|
|
|
{ |
|
55
|
|
|
$res = Yii::app()->db->createCommand() |
|
56
|
|
|
->select('COUNT(*)') |
|
57
|
|
|
->from('users_missions') |
|
58
|
|
|
->where('uid=:uid', [':uid'=>$this->uid]) |
|
59
|
|
|
->queryScalar(); |
|
60
|
|
|
|
|
61
|
|
|
$this->stats['completed_missions'] = $res; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
protected function fetchVisitedMissions() |
|
65
|
|
|
{ |
|
66
|
|
|
$res = Yii::app()->db->createCommand() |
|
67
|
|
|
->select('v.*, w.county_id, w.title') |
|
68
|
|
|
->from('visited v') |
|
69
|
|
|
->join('waters w', 'v.water_id=w.id') |
|
70
|
|
|
->where('v.uid=:uid', [':uid'=>$this->uid]) |
|
71
|
|
|
->order('v.water_id') |
|
72
|
|
|
->queryAll(); |
|
73
|
|
|
|
|
74
|
|
|
foreach ($res as $dat) { |
|
75
|
|
|
$this->stats['routine'][$dat['water_id']] = $dat['routine']; |
|
76
|
|
|
$this->stats['visited_waters']++; |
|
77
|
|
|
if (!array_key_exists($dat['county_id'], $this->stats['counties'])) { |
|
78
|
|
|
$this->stats['visited_counties']++; |
|
79
|
|
|
} |
|
80
|
|
|
$this->stats['counties'][$dat['county_id']] = 1; |
|
81
|
|
|
} |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
protected function fetchDuel() |
|
85
|
|
|
{ |
|
86
|
|
|
$logger = new Logger; |
|
|
|
|
|
|
87
|
|
|
$logger->uid = $this->uid; |
|
|
|
|
|
|
88
|
|
|
$stat = $logger->getCounters(); |
|
|
|
|
|
|
89
|
|
|
|
|
90
|
|
|
//duels |
|
91
|
|
|
$this->stats['duel_success'] = @(int)$stat['duel_success']; |
|
92
|
|
|
$this->stats['duel_fail'] = @(int)$stat['duel_fail']; |
|
|
|
|
|
|
93
|
|
|
$this->stats['duel_rate'] = '?'; |
|
|
|
|
|
|
94
|
|
|
if ($this->stats['duel_success'] || $this->stats['duel_fail']) { |
|
95
|
|
|
$this->stats['duel_rate'] = round($this->stats['duel_success'] / (($this->stats['duel_success'] + $this->stats['duel_fail'])/100), 1); |
|
96
|
|
|
} |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
protected function fetchCountSets() |
|
100
|
|
|
{ |
|
101
|
|
|
$res = Yii::app()->db->createCommand() |
|
|
|
|
|
|
102
|
|
|
->select('item_id, item_count') |
|
103
|
|
|
->from('users_items') |
|
104
|
|
|
->where('uid=:uid AND item_id>999 AND item_count>0', [':uid'=>$this->uid]) |
|
105
|
|
|
->order('skill DESC, item_id DESC') |
|
106
|
|
|
->queryAll(); |
|
107
|
|
|
$best = 0; |
|
108
|
|
|
foreach ($res as $dat) { |
|
109
|
|
|
if ($best < 3 && $dat['item_count']) { |
|
110
|
|
|
$this->stats['setitems'][$dat['item_id']] = $dat['item_count']; |
|
111
|
|
|
$best++; |
|
112
|
|
|
} |
|
113
|
|
|
$this->stats['owned_setitems'] += $dat['item_count']; |
|
114
|
|
|
} |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
View Code Duplication |
protected function fetchItems() |
|
|
|
|
|
|
118
|
|
|
{ |
|
119
|
|
|
$res = Yii::app()->db->createCommand() |
|
120
|
|
|
->select('item_id') |
|
121
|
|
|
->from('users_items') |
|
122
|
|
|
->where('uid=:uid AND item_id < 1000', [':uid'=>$this->uid]) |
|
123
|
|
|
->order('skill DESC') |
|
124
|
|
|
->limit(3) |
|
125
|
|
|
->queryAll(); |
|
126
|
|
|
foreach ($res as $dat) { |
|
127
|
|
|
$i = new Item; |
|
|
|
|
|
|
128
|
|
|
$i->item_type = Item::TYPE_ITEM; |
|
|
|
|
|
|
129
|
|
|
$i->id = $dat['item_id']; |
|
|
|
|
|
|
130
|
|
|
$i->fetch(); |
|
131
|
|
|
$this->stats['items'][] = $i->title; |
|
|
|
|
|
|
132
|
|
|
} |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
|
View Code Duplication |
protected function fetchBaits() |
|
|
|
|
|
|
136
|
|
|
{ |
|
137
|
|
|
$res = Yii::app()->db->createCommand() |
|
138
|
|
|
->select('item_id') |
|
139
|
|
|
->from('users_baits') |
|
140
|
|
|
->where('uid=:uid', [':uid'=>$this->uid]) |
|
141
|
|
|
->order('skill DESC') |
|
142
|
|
|
->limit(3) |
|
143
|
|
|
->queryAll(); |
|
144
|
|
|
foreach ($res as $dat) { |
|
145
|
|
|
$i = new Item; |
|
|
|
|
|
|
146
|
|
|
$i->item_type = Item::TYPE_BAIT; |
|
|
|
|
|
|
147
|
|
|
$i->id = $dat['item_id']; |
|
|
|
|
|
|
148
|
|
|
$i->fetch(); |
|
149
|
|
|
$this->stats['baits'][] = $i->title; |
|
|
|
|
|
|
150
|
|
|
} |
|
151
|
|
|
} |
|
152
|
|
|
|
|
153
|
|
|
protected function fetchSets() |
|
154
|
|
|
{ |
|
155
|
|
|
foreach ($this->stats['setitems'] as $dat => $cnt) { |
|
156
|
|
|
$i = new Item; |
|
|
|
|
|
|
157
|
|
|
$i->item_type = Item::TYPE_ITEMSET; |
|
|
|
|
|
|
158
|
|
|
$i->id = (int)$dat; |
|
|
|
|
|
|
159
|
|
|
$i->fetchSet(); |
|
160
|
|
|
$this->stats['sets'][] = $i->title; |
|
|
|
|
|
|
161
|
|
|
} |
|
162
|
|
|
} |
|
163
|
|
|
|
|
164
|
|
|
protected function fetchRank() |
|
165
|
|
|
{ |
|
166
|
|
|
$redis = Yii::app()->redis->getClient(); |
|
167
|
|
|
|
|
168
|
|
|
$rank = $redis->zRevRank('board_p:'.date('Ym'), $this->uid); |
|
|
|
|
|
|
169
|
|
|
$this->stats['rankActual'] = $rank === false ? false : ++$rank; |
|
170
|
|
|
|
|
171
|
|
|
$rank = $redis->zRevRank('board_p:6month', $this->uid); |
|
|
|
|
|
|
172
|
|
|
$this->stats['rank'] = $rank === false ? false : ++$rank; |
|
173
|
|
|
} |
|
174
|
|
|
} |
|
|
|
|
|
|
175
|
|
|
|
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.
To visualize
will produce issues in the first and second line, while this second example
will produce no issues.