-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgrab_buitenlandse_concerten_tests.py
317 lines (293 loc) · 11.7 KB
/
grab_buitenlandse_concerten_tests.py
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
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
197
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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
import unittest
from pandas import DataFrame, isnull, Timestamp, Series, read_excel
from datetime import datetime, timedelta
class TestGrabber(unittest.TestCase):
def setUp(self):
self.grabber = Grabber()
def test_lat_lon_in_belgium(self):
antwerpen = {"latitude": 51.2603015, "longitude": 4.2176391}
berlijn = {"latitude": 52.5067614, "longitude": 13.284651}
self.assertTrue(self.grabber._concert_is_in_belgium(antwerpen))
self.assertFalse(self.grabber._concert_is_in_belgium(berlijn))
def test_convert_iso_code_to_full_name(self):
self.assertEqual(self.grabber._convert_cleaned_country_name_to_full_name("DE"), "Germany")
self.assertEqual(self.grabber._convert_cleaned_country_name_to_full_name("GB"), "United Kingdom")
self.assertEqual(self.grabber._convert_cleaned_country_name_to_full_name("VV"), None)
def test_add_podiumfestivalinfo(self):
self.grabber.current = DataFrame([{}])
self.grabber.mbab.load_list()
self.grabber.add_podiumfestivalinfo_concerts()
self.assertTrue(self.grabber.current[(self.grabber.current["artiest_mb_naam"] == "Balthazar") & (self.grabber.current["datum"] < datetime(2005, 1, 1))].empty)
def test_infer_cancellations(self):
self.grabber.df = DataFrame([
{
"event_id": "sk1",
"datum": datetime.now() + timedelta(days=6),
"last_seen_on": datetime.now() - timedelta(days=6)
}
])
self.grabber.infer_cancellations()
self.assertTrue(self.grabber.df[self.grabber.df["event_id"] == "sk1"]["cancelled"].bool())
def test_clean_names(self):
self.grabber.df = DataFrame([
{
"venue": "AB"
}
])
self.grabber._clean_names("venue", "venue_clean", "resources/venue_cleaning.xlsx")
self.assertEqual(self.grabber.df.iloc[0]["venue_clean"], "Ancienne Belgique")
def test_prefer_precise_date_for_festival(self):
self.grabber.df = DataFrame([
{
"event_id": "sk1",
"event_type": "Festival",
"datum": Timestamp(datetime.now().date() - timedelta(days=2)),
"einddatum": Timestamp(datetime.now().date() + timedelta(days=3)),
"last_seen_on": datetime.now().date(),
"source": "songkick",
"artiest_mb_id": "a",
"stad_clean": "b",
"visible": True,
"concert_id": 1
},
{
"event_id": "bit1",
"datum": Timestamp(datetime.now().date()),
"last_seen_on": datetime.now().date(),
"source": "bandsintown",
"artiest_mb_id": "a",
"stad_clean": "b",
"visible": False,
"concert_id": 2
},
{
"event_id": "setlist1",
"datum": Timestamp(datetime.now().date()),
"last_seen_on": datetime.now().date(),
"source": "setlist",
"artiest_mb_id": "a",
"stad_clean": "b",
"visible": False,
"concert_id": 2
},
{
"event_id": "setlist1",
"datum": None,
"source": "setlist",
"last_seen_on": datetime.now().date(),
"artiest_mb_id": "a",
"stad_clean": "b",
"visible": False,
"concert_id": 2
}
])
self.grabber._set_precise_date_for_festivals()
self.assertEqual(self.grabber.df.loc[0]["visible"], False)
self.assertEqual(self.grabber.df.loc[0]["concert_id"], 2)
self.assertEqual(self.grabber.df.loc[1]["visible"], True)
def test_update_field_based_on_new_leech(self):
self.grabber.df = DataFrame([
{
"event_id": "sk1",
"titel": "test1",
"artiest_mb_id": "a",
"last_seen_on": datetime.now().date() - timedelta(days=2)
},
{
"event_id": "sk1",
"titel": "test2",
"artiest_mb_id": "a",
"last_seen_on": datetime.now().date()
}
])
self.grabber._update_field_based_on_new_leech("titel")
self.assertEqual(self.grabber.df["titel"].values[0], "test2")
def test_update_last_seen_on_field(self):
self.grabber.previous = DataFrame([
{
"event_id": "sk1",
"titel": "test1",
"artiest_mb_id": "a",
"last_seen_on": datetime.now().date() - timedelta(days=2)
},
{
"event_id": "sk2",
"titel": "test2",
"artiest_mb_id": "a",
"last_seen_on": datetime.now().date() - timedelta(days=2)
},
{
"event_id": "sk3",
"titel": "test3",
"artiest_mb_id": "a",
"last_seen_on": datetime.now().date() - timedelta(days=2)
}
])
self.grabber.current = DataFrame([
{
"event_id": "sk2",
"titel": None,
"artiest_mb_id": "a",
"last_seen_on": datetime.now().date()
},
{
"event_id": "sk3",
"titel": "test3",
"artiest_mb_id": "a",
"last_seen_on": datetime.now().date()
},
{
"event_id": "sk4",
"titel": "test4",
"artiest_mb_id": "a",
"last_seen_on": datetime.now().date()
}
])
self.grabber.df = self.grabber.previous.append(self.grabber.current, ignore_index=True)
self.grabber.df.drop_duplicates(subset=["artiest_mb_id", "event_id"], keep="first", inplace=True)
self.grabber._update_last_seen_on_dates_of_previous_events_that_are_still_current()
self.assertEqual(self.grabber.df[self.grabber.df["event_id"] == "sk2"]["last_seen_on"].values[0], datetime.now().date())
def test_match_artiest_naam_to_mbid(self):
self.grabber.mbab.load_list()
self.assertIsNotNone(self.grabber._match_artist_name_to_mbid("Pornorama"))
self.assertIsNone(self.grabber._match_artist_name_to_mbid("Onbekende artiest"))
def test_make_gig_triples(self):
self.grabber.df = DataFrame([
{
"event_id": "sk1",
"datum": datetime.now().date(),
"artiest_merge_naam": "a",
"stad_clean": "b"
},
{
"event_id": "sk2",
"datum": datetime.now().date(),
"artiest_merge_naam": "a",
"stad_clean": "b"
}
])
gig_triples = self.grabber._make_gig_triples()
self.assertEqual(gig_triples, {('a', datetime.now().date(), 'b')})
def test_assign_concert_ids(self):
self.grabber.df = DataFrame([
{
"event_id": "sk1",
"datum": datetime.now().date(),
"artiest_merge_naam": "a",
"stad_clean": "b"
},
{
"event_id": "sk2",
"datum": datetime.now().date(),
"artiest_merge_naam": "a",
"stad_clean": "b"
}
])
gig_triples = {('a', datetime.now().date(), 'b')}
self.grabber._assign_concert_ids(gig_triples)
self.assertListEqual(self.grabber.df["concert_id"].tolist(), [0, 0])
def test_select_visibility(self):
self.grabber.now = datetime.now()
self.grabber.df = DataFrame([
{
"event_id": "bit1",
"source": "bandsintown",
"datum": datetime.now().date() + timedelta(days=2),
"last_seen_on": datetime.now().date() - timedelta(days=1),
"artiest_merge_naam": "a",
"stad_clean": "b",
"concert_id": 0,
"ignore": False,
"latitude": 51.2603015,
"longitude": 13.2176391
},
{
"event_id": "sk1",
"source": "songkick",
"datum": datetime.now().date() + timedelta(days=2),
"last_seen_on": datetime.now().date() - timedelta(days=7),
"artiest_merge_naam": "a",
"stad_clean": "b",
"concert_id": 0,
"ignore": False,
"latitude": 51.2603015,
"longitude": 13.2176391
}
])
self.grabber._select_visibility_per_concert()
self.assertTrue(self.grabber.df.iloc[0]["visible"])
self.assertFalse(self.grabber.df.iloc[1]["visible"])
self.grabber.now = datetime.now()
self.grabber.df = DataFrame([
{
"event_id": "bit1",
"source": "bandsintown",
"datum": datetime.now().date() + timedelta(days=2),
"last_seen_on": datetime.now().date() - timedelta(days=1),
"artiest_merge_naam": "a",
"stad_clean": "b",
"concert_id": 0,
"ignore": False,
"latitude": 51.2603015,
"longitude": 13.2176391
}
])
self.grabber._select_visibility_per_concert()
self.assertTrue(self.grabber.df.iloc[0]["visible"])
# self.grabber.df = read_excel("output/latest.xlsx")
# self.grabber._select_visibility_per_concert()
def test_fix_weird_symbols(self):
self.assertIsInstance(self.grabber._fix_weird_symbols("ü@sdf£µù)°ñ"), str)
def test_handle_ambiguous_names(self):
self.grabber.df = DataFrame([
{
"artiest_merge_naam": None,
"artiest_mb_naam": "Guy Verlinde"
}
])
self.grabber.handle_ambiguous_artists()
self.assertIsNotNone(self.grabber.df.loc[0, "artiest_merge_naam"])
def test_infer_cancellations(self):
self.grabber.df = DataFrame([
{
"datum": Timestamp(datetime.now().date() + timedelta(days=1)),
"last_seen_on": Timestamp(datetime.now().date() - timedelta(days=6))
},
{
"datum": Timestamp(datetime.now().date() + timedelta(days=1)),
"last_seen_on": Timestamp(datetime.now().date() - timedelta(days=2))
}
])
row = self.grabber.df.iloc[0]
self.assertTrue(self.grabber._is_cancellation(row))
self.grabber.infer_cancellations()
self.assertListEqual(self.grabber.df["cancelled"].tolist(), [True, False])
def test_set_source_link(self):
self.grabber.df = DataFrame([
{
"event_id": "facebook884162221625243",
"concert_id": 1,
"visible": True
},
{
"event_id": "songkick_5318473",
"concert_id": 2,
"visible": True
},
{
"event_id": "facebook_5318473",
"concert_id": 2,
"visible": False
},
{
"event_id": "beren_gieren_1",
"concert_id": 3,
"visible": True
}
])
self.grabber._set_source_outlinks_per_concert()
print(self.grabber.df)
def test_establish_source_hyperlink(self):
self.assertEqual(self.grabber._establish_source_hyperlink("facebook9871237"), ("Facebook", "https://www.facebook.com/events/9871237"))
if __name__ == '__main__':
unittest.main()