|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Chay22\RecSelMeter; |
|
4
|
|
|
|
|
5
|
|
|
use Chay22\RecSelMeter\Parser; |
|
6
|
|
|
use Chay22\RecSelMeter\Config; |
|
7
|
|
|
|
|
8
|
|
|
class RecSelMeter |
|
9
|
|
|
{ |
|
10
|
|
|
/** |
|
11
|
|
|
* Data of current store |
|
12
|
|
|
* |
|
13
|
|
|
* @var array $store |
|
14
|
|
|
*/ |
|
15
|
|
|
protected $store; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* Set of configuration |
|
19
|
|
|
* |
|
20
|
|
|
* @var object $config |
|
21
|
|
|
*/ |
|
22
|
|
|
protected $config; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Score of current store |
|
26
|
|
|
* |
|
27
|
|
|
* @var int $score |
|
28
|
|
|
*/ |
|
29
|
|
|
protected $score = 0; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @param string $url URL of the store |
|
33
|
|
|
*/ |
|
34
|
1 |
|
function __construct($url) |
|
|
|
|
|
|
35
|
|
|
{ |
|
36
|
1 |
|
$store = new Parser($url); |
|
37
|
1 |
|
$this->store = $store->fetch(); |
|
38
|
|
|
|
|
39
|
1 |
|
$this->config = new Config; |
|
40
|
1 |
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* Return object of Config |
|
44
|
|
|
* |
|
45
|
|
|
* @return object |
|
46
|
|
|
*/ |
|
47
|
|
|
public function config() |
|
48
|
|
|
{ |
|
49
|
|
|
return $this->config; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* Return score of current store |
|
54
|
|
|
* |
|
55
|
|
|
* @return int |
|
56
|
|
|
*/ |
|
57
|
1 |
|
public function calculate() |
|
58
|
|
|
{ |
|
59
|
1 |
|
$this->sold(); |
|
60
|
1 |
|
$this->rank(); |
|
61
|
1 |
|
$this->feedback(); |
|
62
|
1 |
|
$this->storeActive(); |
|
63
|
1 |
|
$this->cod(); |
|
64
|
1 |
|
$this->accountAge(); |
|
65
|
1 |
|
$this->imageCount(); |
|
66
|
|
|
|
|
67
|
1 |
|
return $this->score; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* Calculate amount of item of store sold |
|
72
|
|
|
* |
|
73
|
|
|
* @return void |
|
74
|
|
|
*/ |
|
75
|
1 |
|
protected function sold() |
|
76
|
|
|
{ |
|
77
|
1 |
|
foreach ($this->config->data()['sold'] as $key => $value) { |
|
78
|
1 |
|
if ($this->store['sold'] >= $key) { |
|
79
|
1 |
|
$this->score += $value; |
|
80
|
1 |
|
} |
|
81
|
1 |
|
} |
|
82
|
1 |
|
} |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* Add the score point based of seller rank |
|
86
|
|
|
* |
|
87
|
|
|
* @return void |
|
88
|
|
|
*/ |
|
89
|
1 |
|
protected function rank() |
|
90
|
|
|
{ |
|
91
|
1 |
|
foreach ($this->config->data()['rank'] as $key => $value) { |
|
92
|
1 |
|
if (stripos($this->store['rank'], $key) !== false) { |
|
93
|
1 |
|
$this->score += $value; |
|
94
|
1 |
|
} |
|
95
|
1 |
|
} |
|
96
|
1 |
|
} |
|
97
|
|
|
|
|
98
|
|
|
/** |
|
99
|
|
|
* Add the score point based of amount of seller feedback |
|
100
|
|
|
* and its feedback percent |
|
101
|
|
|
* |
|
102
|
|
|
* @return void |
|
103
|
|
|
*/ |
|
104
|
1 |
|
protected function feedback() |
|
105
|
|
|
{ |
|
106
|
1 |
|
if ($this->store['feedback_percent'] == 0) { |
|
107
|
1 |
|
return; |
|
108
|
|
|
} |
|
109
|
|
|
$feedback = $this->store['feedback'] * $this->config->data()['feedback']; |
|
110
|
|
|
$feedbackPercent = ($this->store['feedback_percent'] / $this->config->data()['feedbackPercent']); |
|
111
|
|
|
$score = round($feedback / $feedbackPercent); |
|
112
|
|
|
$this->score += $score; |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
/** |
|
116
|
|
|
* Add score point based of time from store published time |
|
117
|
|
|
* and latest bump (sundul) attempt |
|
118
|
|
|
* |
|
119
|
|
|
* @return void |
|
120
|
|
|
*/ |
|
121
|
1 |
|
protected function storeActive() |
|
122
|
|
|
{ |
|
123
|
1 |
|
$storePublished = new \DateTime($this->store['published_at']); |
|
124
|
1 |
|
$storeBumped = new \DateTime($this->store['last_bump']); |
|
125
|
1 |
|
$interval = $storePublished->diff($storeBumped); |
|
126
|
1 |
|
$interval = $interval->days; |
|
127
|
|
|
|
|
128
|
1 |
|
foreach ($this->config->data()['storeActive'] as $key => $value) { |
|
129
|
1 |
|
if ($interval <= $key) { |
|
130
|
|
|
$this->score += $value; |
|
131
|
|
|
} |
|
132
|
1 |
|
} |
|
133
|
1 |
|
} |
|
134
|
|
|
|
|
135
|
|
|
/** |
|
136
|
|
|
* Add a score based of seller provides COD or no |
|
137
|
|
|
* |
|
138
|
|
|
* @return void |
|
139
|
|
|
*/ |
|
140
|
1 |
|
protected function cod() |
|
141
|
|
|
{ |
|
142
|
1 |
|
if ($this->store['cod'] !== false) { |
|
143
|
|
|
$this->score += $this->config->data()['cod']; |
|
144
|
|
|
} |
|
145
|
1 |
|
} |
|
146
|
|
|
|
|
147
|
|
|
/** |
|
148
|
|
|
* Add a score based of seller account age |
|
149
|
|
|
* |
|
150
|
|
|
* @return void |
|
151
|
|
|
*/ |
|
152
|
1 |
|
protected function accountAge() |
|
153
|
|
|
{ |
|
154
|
1 |
|
$joinDate = new \DateTime($this->store['join_date']); |
|
155
|
1 |
|
$currentDate = new \DateTime(); |
|
156
|
1 |
|
$interval = $joinDate->diff($currentDate); |
|
157
|
1 |
|
$interval = $interval->y; |
|
158
|
1 |
|
$this->score += ($interval * $this->config->data()['accountAge']); |
|
159
|
1 |
|
} |
|
160
|
|
|
|
|
161
|
|
|
/** |
|
162
|
|
|
* Add a score based of amount of image seller provides |
|
163
|
|
|
* |
|
164
|
|
|
* @return void |
|
165
|
|
|
*/ |
|
166
|
1 |
|
protected function imageCount() |
|
167
|
|
|
{ |
|
168
|
1 |
|
$this->score += $this->store['image_count'] * $this->config->data()['imageCount']; |
|
169
|
1 |
|
} |
|
170
|
|
|
} |
|
171
|
|
|
|
Adding explicit visibility (
private,protected, orpublic) is generally recommend to communicate to other developers how, and from where this method is intended to be used.