Newer
Older
<?php
/**
* Class FakeWebsiteAnalyticsSeeder
* Inserts Fake Analytics in the database
*
* @copyright 2020 Podlibre
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
* @link https://castopod.org/
*/
namespace App\Database\Seeds;

Yassine Doghri
committed
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
use App\Models\PodcastModel;
use App\Models\EpisodeModel;
use CodeIgniter\Database\Seeder;
class FakeWebsiteAnalyticsSeeder extends Seeder
{
protected $keywords = [
'all the smoke podcast',
'apple podcast',
'bad friends podcast',
'best podcast',
'best podcasts',
'best podcasts 2020',
'blood ties',
'call her daddy',
'call her daddy podcast',
'call her daddy podcast controversy',
'call her daddy podcast drama',
'counter clock podcast',
'counterclock podcast',
'crime junkie podcast',
'crime podcast',
'down the hill podcast',
'gerry callahan podcast',
'google podcast',
'history podcast',
'joe rogan',
'joe rogan podcast',
'lana rhoades and logan paul podcast',
'last podcast on the left',
'michael moore podcast',
'michelle obama podcast',
'missing in alaska podcast',
'murder podcast',
'nice white parents podcast',
'nick cannon podcast',
'npr podcast',
'office ladies podcast',
'podcast app',
'podcasts',
'rogan podcast',
'rudy giuliani podcast',
'savage podcast',
'serial podcast',
'smartless podcast',
'ted cruz podcast',
'the daily',
'the daily podcast',
'the last podcast on the left',
'the new abnormal podcast',
'tiger king podcast',
'trey gowdy podcast',
'true crime podcast',
'what is a podcast',
'what is podcast',
'wind of change podcast',
'your own backyard podcast',
];
protected $domains = [
'360.cn ',
'adobe.com ',
'aliexpress.com ',
'alipay.com ',
'amazon.co.jp ',
'amazon.com ',
'amazon.in ',
'apple.com ',
'baidu.com ',
'bing.com ',
'bongacams.com ',
'chaturbate.com ',
'china.com.cn ',
'csdn.net ',
'ebay.com ',
'facebook.com ',
'google.co.in ',
'google.com ',
'google.com.hk ',
'instagram.com ',
'jd.com ',
'live.com ',
'livejasmin.com ',
'microsoft.com ',
'microsoftonline.com ',
'myshopify.com ',
'naver.com ',
'netflix.com ',
'office.com ',
'okezone.com ',
'panda.tv ',
'qq.com ',
'reddit.com ',
'sina.com.cn ',
'sohu.com ',
'taobao.com ',
'tianya.cn ',
'tmall.com ',
'tribunnews.com ',
'twitch.tv ',
'twitter.com ',
'vk.com ',
'weibo.com ',
'wikipedia.org ',
'xinhuanet.com ',
'yahoo.co.jp ',
'yahoo.com ',
'youtube.com ',
'zhanqi.tv ',
'zoom.us ',
];
protected $browsers = [
'Android Browser',
'Avast Secure Browser',
'BlackBerry Browser',
'Chrome',
'Chrome Mobile',
'Chrome Mobile iOS',
'Chrome Webview',
'Chromium',
'Ecosia',
'Fennec',
'Firebird',
'Firefox',
'Firefox Mobile',
'Firefox Mobile iOS',
'Galeon',
'GNOME Web',
'Headless Chrome',
'Huawei Browser',
'IE Mobile',
'Inconnu',
'Internet Explorer',
'Kindle Browser',
'Konqueror',
'Maxthon',
'Meizu Browser',
'Microsoft Edge',
'MIUI Browser',
'Mobile Safari',
'Mobile Silk',
'OmniWeb',
'Openwave Mobile Browser',
'Opera',
'Opera Mini',
'Opera Mobile',
'Opera Next',
'Palm Blazer',
'Puffin',
'QupZilla',
'Safari',
'Samsung Browser',
'UC Browser',
'WOSBrowser',
];
public function run()
{
$podcast = (new PodcastModel())->first();
if ($podcast) {
$firstEpisode = (new EpisodeModel())
->selectMin('published_at')
->first();
for (
$date = strtotime($firstEpisode->published_at);
$date < strtotime('now');
$date = strtotime(date('Y-m-d', $date) . ' +1 day')
) {
$website_by_browser = [];
$website_by_entry_page = [];
$website_by_referer = [];
$episodes = (new EpisodeModel())
->where([
'podcast_id' => $podcast->id,
'DATE(published_at) <=' => date('Y-m-d', $date),
])
->findAll();
foreach ($episodes as $episode) {
$age = floor(

Yassine Doghri
committed
($date - strtotime($episode->published_at)) / 86400,
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
);
$proba1 = floor(exp(3 - $age / 40)) + 1;
for (
$num_line = 0;
$num_line < rand(1, $proba1);
$num_line++
) {
$proba2 = floor(exp(6 - $age / 20)) + 10;
$domain =
$this->domains[rand(0, count($this->domains) - 1)];
$keyword =
$this->keywords[
rand(0, count($this->keywords) - 1)
];
$browser =
$this->browsers[
rand(0, count($this->browsers) - 1)
];
$hits = rand(0, $proba2);
$website_by_browser[] = [
'podcast_id' => $podcast->id,
'date' => date('Y-m-d', $date),
'browser' => $browser,
'hits' => $hits,
];
$website_by_entry_page[] = [
'podcast_id' => $podcast->id,
'date' => date('Y-m-d', $date),
'entry_page_url' => $episode->link,
'hits' => $hits,
];
$website_by_referer[] = [
'podcast_id' => $podcast->id,
'date' => date('Y-m-d', $date),
'referer_url' =>
'http://' . $domain . '/?q=' . $keyword,
'domain' => $domain,
'keywords' => $keyword,
'hits' => $hits,
];
}
}
$this->db
->table('analytics_website_by_browser')
->ignore(true)
->insertBatch($website_by_browser);
$this->db
->table('analytics_website_by_entry_page')
->ignore(true)
->insertBatch($website_by_entry_page);
$this->db
->table('analytics_website_by_referer')
->ignore(true)
->insertBatch($website_by_referer);
}
} else {

Yassine Doghri
committed
echo "COULD NOT POPULATE DATABASE:\n\tCreate a podcast with episodes first.\n";