PheldItunesReporter 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,27 @@
1
+ class PheldItunesTrack
2
+ attr_accessor :track_id
3
+ attr_accessor :name
4
+ attr_accessor :artist
5
+ attr_accessor :album
6
+ attr_accessor :total_time
7
+ attr_accessor :year
8
+ attr_accessor :bit_rate
9
+ attr_accessor :play_count
10
+ attr_accessor :rating
11
+ attr_accessor :date_added
12
+ attr_accessor :genre
13
+
14
+ def initialize
15
+ @track_id = nil
16
+ @name = nil
17
+ @artist = nil
18
+ @album = nil
19
+ @total_time = nil
20
+ @year = nil
21
+ @bit_rate = nil
22
+ @play_count = nil
23
+ @rating = nil
24
+ @date_added = nil
25
+ @genre = nil
26
+ end
27
+ end
@@ -0,0 +1,647 @@
1
+ #!/usr/bin/env ruby -w
2
+
3
+ require 'test/unit'
4
+ require 'lib/pheld_itunes_data_miner.rb'
5
+ require 'ostruct' # OpenStruct
6
+
7
+ ##
8
+ # Student Name: Peter Held
9
+ # Homework Week: 8
10
+ #
11
+ #
12
+
13
+ class TestPheldItunesDataMiner < Test::Unit::TestCase
14
+ def setup
15
+ @data_miner = PheldItunesDataMiner.new
16
+
17
+ @sample_library_xml_good =<<PODATA
18
+ <plist version="1.0">
19
+ <dict>
20
+ <key>Major Version</key><integer>1</integer>
21
+ <key>Minor Version</key><integer>1</integer>
22
+ <key>Application Version</key><string>7.4.1</string>
23
+ <key>Features</key><integer>1</integer>
24
+ <key>Show Content Ratings</key><true/>
25
+ <key>Music Folder</key><string>file://localhost/Users/ryan/Music/iTunes/iTunes%20Music/</string>
26
+ <key>Library Persistent ID</key><string>B7DF0B6856DA8FB2</string>
27
+ <key>Tracks</key>
28
+ <dict>
29
+ <key>510</key>
30
+ <dict>
31
+ <key>Track ID</key><integer>510</integer>
32
+ <key>Name</key><string>3 O'Clock Blues / Darlin' You Know I Love You</string>
33
+ <key>Artist</key><string>B.B. King</string>
34
+ <key>Album</key><string>Live In Cook County Jail</string>
35
+ <key>Genre</key><string>Blues</string>
36
+ <key>Kind</key><string>MPEG audio file</string>
37
+ <key>Size</key><integer>4751455</integer>
38
+ <key>Total Time</key><integer>378070</integer>
39
+ <key>Track Number</key><integer>5</integer>
40
+ <key>Track Count</key><integer>8</integer>
41
+ <key>Year</key><integer>1970</integer>
42
+ <key>Date Modified</key><date>2004-10-14T17:24:35Z</date>
43
+ <key>Date Added</key><date>2002-07-17T19:41:08Z</date>
44
+ <key>Bit Rate</key><integer>100</integer>
45
+ <key>Sample Rate</key><integer>44100</integer>
46
+ <key>Play Count</key><integer>6</integer>
47
+ <key>Play Date</key><integer>3230402051</integer>
48
+ <key>Play Date UTC</key><date>2006-05-14T04:54:11Z</date>
49
+ <key>Rating</key><integer>40</integer>
50
+ <key>Artwork Count</key><integer>1</integer>
51
+ <key>Persistent ID</key><string>3CF1F47A0CA8D007</string>
52
+ <key>Track Type</key><string>File</string>
53
+ <key>Location</key><string>file://localhost/Users/ryan/Music/iTunes/iTunes%20Music/B.B.%20King/Live%20In%20Cook%20County%20Jail/05%203%20O'Clock%20Blues%20_%20Darlin'%20You%20Know%20I%20Love%20You.mp3</string>
54
+ <key>File Folder Count</key><integer>4</integer>
55
+ <key>Library Folder Count</key><integer>1</integer>
56
+ </dict>
57
+ <key>1556</key>
58
+ <dict>
59
+ <key>Track ID</key><integer>1556</integer>
60
+ <key>Name</key><string>Höddi Hlustadi</string>
61
+ <key>Artist</key><string>Sigur Rós</string>
62
+ <key>Album</key><string>Agaetis Byrjun</string>
63
+ <key>Genre</key><string>Alternative</string>
64
+ <key>Kind</key><string>AAC audio file</string>
65
+ <key>Size</key><integer>6731476</integer>
66
+ <key>Total Time</key><integer>406347</integer>
67
+ <key>Track Number</key><integer>3</integer>
68
+ <key>Track Count</key><integer>10</integer>
69
+ <key>Year</key><integer>2000</integer>
70
+ <key>Date Modified</key><date>2006-02-26T21:32:07Z</date>
71
+ <key>Date Added</key><date>2003-05-25T00:33:52Z</date>
72
+ <key>Bit Rate</key><integer>128</integer>
73
+ <key>Sample Rate</key><integer>44100</integer>
74
+ <key>Play Count</key><integer>11</integer>
75
+ <key>Play Date</key><integer>3247549813</integer>
76
+ <key>Play Date UTC</key><date>2006-11-28T16:10:13Z</date>
77
+ <key>Rating</key><integer>60</integer>
78
+ <key>Artwork Count</key><integer>1</integer>
79
+ <key>Persistent ID</key><string>4E21CAD4BB5E4460</string>
80
+ <key>Track Type</key><string>File</string>
81
+ <key>Location</key><string>file://localhost/Users/ryan/Music/iTunes/iTunes%20Music/Sigur%20Ro%CC%81s/Agaetis%20Byrjun/03%20Ho%CC%88ddi%20Hlustadi.m4a</string>
82
+ <key>File Folder Count</key><integer>4</integer>
83
+ <key>Library Folder Count</key><integer>1</integer>
84
+ </dict>
85
+ <key>1557</key>
86
+ <dict>
87
+ <key>Track ID</key><integer>1557</integer>
88
+ <key>Name</key><string>Gotti Teiknadi</string>
89
+ <key>Artist</key><string>Sigur Rós</string>
90
+ <key>Album</key><string>Agaetis Byrjun</string>
91
+ <key>Genre</key><string>Alternative</string>
92
+ <key>Kind</key><string>AAC audio file</string>
93
+ <key>Size</key><integer>7732630</integer>
94
+ <key>Total Time</key><integer>468205</integer>
95
+ <key>Track Number</key><integer>4</integer>
96
+ <key>Track Count</key><integer>10</integer>
97
+ <key>Year</key><integer>2000</integer>
98
+ <key>Date Modified</key><date>2006-02-26T21:32:09Z</date>
99
+ <key>Date Added</key><date>2003-05-25T00:34:37Z</date>
100
+ <key>Bit Rate</key><integer>128</integer>
101
+ <key>Sample Rate</key><integer>44100</integer>
102
+ <key>Play Count</key><integer>16</integer>
103
+ <key>Play Date</key><integer>3268814604</integer>
104
+ <key>Play Date UTC</key><date>2007-08-01T19:03:24Z</date>
105
+ <key>Rating</key><integer>60</integer>
106
+ <key>Artwork Count</key><integer>1</integer>
107
+ <key>Persistent ID</key><string>4E21CAD4BB5E4461</string>
108
+ <key>Track Type</key><string>File</string>
109
+ <key>Location</key><string>file://localhost/Users/ryan/Music/iTunes/iTunes%20Music/Sigur%20Ro%CC%81s/Agaetis%20Byrjun/04%20Gotti%20Teiknadi.m4a</string>
110
+ <key>File Folder Count</key><integer>4</integer>
111
+ <key>Library Folder Count</key><integer>1</integer>
112
+ </dict>
113
+ <key>Playlists</key>
114
+ <array>
115
+ <dict>
116
+ <key>Name</key><string>Library</string>
117
+ <key>Master</key><true/>
118
+ <key>Playlist ID</key><integer>4613</integer>
119
+ <key>Playlist Persistent ID</key><string>8A6CC7AAA797303E</string>
120
+ <key>Visible</key><false/>
121
+ <key>All Items</key><true/>
122
+ <key>Playlist Items</key>
123
+ <array>
124
+ <dict>
125
+ <key>Track ID</key><integer>510</integer>
126
+ </dict>
127
+ <dict>
128
+ <key>Track ID</key><integer>1556</integer>
129
+ </dict>
130
+ </array>
131
+ </dict>
132
+ <dict>
133
+ <key>Name</key><string>Library</string>
134
+ <key>Master</key><true/>
135
+ <key>Playlist ID</key><integer>4613</integer>
136
+ <key>Playlist Persistent ID</key><string>8A6CC7AAA797303E</string>
137
+ <key>Visible</key><false/>
138
+ <key>All Items</key><true/>
139
+ <key>Playlist Items</key>
140
+ <array>
141
+ <dict>
142
+ <key>Track ID</key><integer>1556</integer>
143
+ </dict>
144
+ <dict>
145
+ <key>Track ID</key><integer>1557</integer>
146
+ </dict>
147
+ </array>
148
+ </dict>
149
+ </array>
150
+ </dict>
151
+ </plist>
152
+ PODATA
153
+
154
+ @sample_library_xml_bad =<<PODATA
155
+ <plist versio1.0">
156
+ <dict>
157
+ <key>Major Version</key><integer>1</integer>
158
+ <key>Minor Version</key><integer>1</integer>
159
+ <key>Application Version</key><string>7.4.1</string>
160
+ <key>Features</key><integer>1</integer>
161
+ <key>Show Content Ratings</key><true/>
162
+ <key>Music Folder</key><string>file://localhost/Users/ryan/Music/iTunes/iTunes%20Music/</string>
163
+ <key>Library Persistent ID</key><string>B7DF0B6856DA8FB2</string>
164
+ <key>Tracks</key>
165
+ <dict>
166
+ <key>510</key>
167
+ <dict>
168
+ <key>Track ID</key><integer>510</integer>
169
+ <key>Name</key><string>3 O'Clock Blues / Darlin' You Know I Love You</string>
170
+ <key>Artist</key><string>B.B. King</string>
171
+ <key>Album</key><string>Live In Cook County Jail</string>
172
+ <key>Genre</key><string>Blues</string>
173
+ <key>Kind</key><string>MPEG audio file</string>
174
+ <key>Size</key><integer>4751455</integer>
175
+ <key>Total Time</key><integer>378070</integer>
176
+ <k>Track Number</key><integer>5</integer>
177
+ <key>Track Count</key><integer>8</integer>
178
+ <key>Year</key><integer>1970</integer>
179
+ <key>Date Modified</key><date>2004-10-14T17:24:35Z</date>
180
+ <key>Date Added</key><date>2002-07-17T19:41:08Z</date>
181
+ ay Date UTC</key><date>2006-05-14T04:54:11Z</date>
182
+ <key>Rating</key><integer>40</integer>
183
+ <key>Artwork Count</key><integer>1</integer>
184
+ <key>Persistent ID</key><string>3CF1F47A0CA8D007</string>
185
+ <key>Track Type</key><string>File</string>
186
+ <key>Location</key><string>file://localhost/Users/ryan/Music/iTunes/iTunes%20Music/B.B.%20King/Live%20In%20Cook%20County%20Jail/05%203%20O'Clock%20Blues%20_%20Darlin'%20You%20Know%20I%20Love%20You.mp3</string>
187
+ <key>File Folder Count</key><integer>4</integer>
188
+ <key>Library Folder Count</key><integer>1</integer>
189
+ </dict>
190
+ <ky>Track ID</key><integer>1556</integer>
191
+ <key>Name</key><string>Höddi Hlustadi</string>
192
+ <key>Artist</key><string>Sigur Rós</string>
193
+ <key>Album</key><string>Agaetis Byrjun</string>
194
+ <key>Genre</key><string>Alternative</string>
195
+ <key>Kind</key><string>AAC audio file</string>
196
+ <key>Size</key><integer>6731476</integer>
197
+ <key>Total Time</key><integer>406347</integer>
198
+ <key>Track Number</key><integer>3</integer>
199
+ <key>Track Count</key><integer>10</integer>
200
+ <key>Year</key><integer>2000</integer>
201
+ <key>Date Modified</key><date>2006-02-26T21:32:07Z</date>
202
+ <key>Date Added</key><date>2003-05-25T00:33:52Z</date>
203
+ <key>Bit Rate</key><integer>128</integer>
204
+ <key>Sample Rate</key><integer>44100</integer>
205
+ <key>Play Count</key><integer>11</integer>
206
+ <key>Play Date</key><integer>3247549813</integer>
207
+ <key>Play Date UTC</key><date>2006-11-28T16:10:13Z</date>
208
+ <key>Rating</key><integer>60</integer>
209
+ <key>Artwork Count</key><integer>1</integer>
210
+ <key>Persistent ID</key><string>4E21CAD4BB5E4460</string>
211
+ <key>Track Type</key><string>File</string>
212
+ <key>Location</key><string>file://localhost/Users/ryan/Music/iTunes/iTunes%20Music/Sigur%20Ro%CC%81s/Agaetis%20Byrjun/03%20Ho%CC%88ddi%20Hlustadi.m4a</string>
213
+ <key>File Folder Count</key><integer>4</integer>
214
+ <key>Library Folder Count</key><integer>1</integer>
215
+ </dict
216
+ <key>1557</key>
217
+ <dict>
218
+ <key>Track ID</key><integer>1557</integer>
219
+ <key>Name</key><string>Gotti Teiknadi</string>
220
+ <key>Artist</key><string>Sigur Rós</string>
221
+ <key>Album</key><string>Agaetis Byrjun</string>
222
+ <key>Genre</key><string>Alternative</string>
223
+ <key>Kind</key><string>AAC audio file</string>
224
+ <key>Size</key><integer>7732630</integer>
225
+ <key>Total Time</key><integer>468205</integer>
226
+ <key>Track Number</key><integer>4</integer>
227
+ <key>Track Count</key><integer>10</integer>
228
+ <key>Year</key><integer>2000</integer>
229
+ <key>Date Modified</key><date>2006-02-26T21:32:09Z</date>
230
+ <key>Date Added</key><date>2003-05-25T00:34:37Z</date>
231
+ <key>Bit Rate</key><integer>128</integer>
232
+ <key>Sample Rate</key><integer>44100</integer>
233
+ <key>Play Count</key><integer>16</integer>
234
+ <key>Play Date</key><integer>3268814604</integer>
235
+ <key>Play Date UTC</key><date>2007-08-01T19:03:24Z</date>
236
+ <key>Rating</key><integer>60</integer>
237
+ <key>Artwork Count</key><integer>1</integer>
238
+ <key>Persistent ID</key><string>4E21CAD4BB5E4461</string>
239
+ <key>Track Type</key><string>File</string>
240
+ <key>Location</key><string>file://localhost/Users/ryan/Music/iTunes/iTunes%20Music/Sigur%20Ro%CC%81s/Agaetis%20Byrjun/04%20Gotti%20Teiknadi.m4a</string>
241
+ <key>File Folder Count</key><integer>4</integer>
242
+ <key>Library Folder Count</key><integer>1</integer>
243
+ </dict>
244
+ <key>Playlists</key>
245
+ <array>
246
+ <dict>
247
+ <key>Name</key><string>Library</string>
248
+ <key>Master</key><true/>
249
+ <key>Playlist ID</key><integer>4613</integer>
250
+ <key>Playlist Persistent ID</key><string>8A6CC7AAA797303E</string>
251
+ <key>Visible</key><false/>
252
+ <key>All Items</key><true/>
253
+ <key>Playlist Items</key>
254
+ <array>
255
+ <dict>
256
+ <key>Track ID</key><integer>510</integer>
257
+ </dict>
258
+ <dict>
259
+ <key>Track ID</key><integer>1556</integer>
260
+ </dict>
261
+ </array>
262
+ </dict>
263
+ <dict>
264
+ <key>Name</key><string>Library</string>
265
+ <key>Master</key><true/>
266
+ <key>Playlist ID</key><integer>4613</integer>
267
+ <key>Playlist Persistent ID</key><string>8A6CC7AAA797303E</string>
268
+ <key>Visible</key><false/>
269
+ <key>All Items</key><true/>
270
+ <key>Playlist Items</key>
271
+ <array>
272
+ <dict>
273
+ <key>Track ID</key><integer>1556</integer>
274
+ </dict>
275
+ <dict>
276
+ <key>Track ID</key><integer>1557</integer>
277
+ </dict>
278
+ </array>
279
+ </dict>
280
+ </array>
281
+ </dict>
282
+ </plist>
283
+ PODATA
284
+
285
+ # 6 with year=2000, 4 with year=1992, 1 with year=1970
286
+ # 4 with artist="Rollins Band", 3 with artist="Sigur Rós", 1 with artist="B.B. King", 1 with artist="Hans Zimmer &#38; Lisa Gerrard", 1 with artist="The Lyndhurst Orchestra", 1 with artist="Juno Reactor"
287
+ # 4 with album="The End Of Silence", 3 with album="Agaetis Byrjun", 2 with album="Gladiator Soundtrack", 1 with album="Live In Cook County Jail", 1 with album="Juno Reactor"
288
+ # average year = 1994
289
+
290
+ @track_good = OpenStruct.new
291
+ @track_good.track_id = 510
292
+ @track_good.name = "3 O'Clock Blues / Darlin' You Know I Love You"
293
+ @track_good.artist = "B.B. King"
294
+ @track_good.album = "Live In Cook County Jail"
295
+ @track_good.total_time = 378070
296
+ @track_good.year = 1970
297
+ @track_good.bit_rate = 100
298
+ @track_good.play_count = 6
299
+ @track_good.rating = 40
300
+ @track_good.date_added = Date.parse("Jul 17, 2002 1:41:11 PM")
301
+ @track_good.genre = "Blues"
302
+
303
+ @track_good_2 = OpenStruct.new
304
+ @track_good_2.track_id = 1556
305
+ @track_good_2.name = "Höddi Hlustadi"
306
+ @track_good_2.artist = "Sigur Rós"
307
+ @track_good_2.album = "Agaetis Byrjun"
308
+ @track_good_2.total_time = 406347
309
+ @track_good_2.year = 2000
310
+ @track_good_2.bit_rate = 128
311
+ @track_good_2.play_count = 11
312
+ @track_good_2.rating = 60
313
+ @track_good_2.date_added = Date.parse("Jul 17, 2003 1:41:11 PM")
314
+ @track_good_2.genre = "Blues"
315
+
316
+ @track_good_3 = OpenStruct.new
317
+ @track_good_3.track_id = 1557
318
+ @track_good_3.name = "Gotti Teiknadi"
319
+ @track_good_3.artist = "Sigur Rós"
320
+ @track_good_3.album = "Agaetis Byrjun"
321
+ @track_good_3.total_time = 468205
322
+ @track_good_3.year = 2000
323
+ @track_good_3.bit_rate = 128
324
+ @track_good_3.play_count = 16
325
+ @track_good_3.rating = 60
326
+ @track_good_3.date_added = Date.parse("Jul 17, 2003 1:41:11 PM")
327
+ @track_good_3.genre = "Rock"
328
+
329
+ @track_good_4 = OpenStruct.new
330
+ @track_good_4.track_id = 2445
331
+ @track_good_4.name = "Low Self Opinion"
332
+ @track_good_4.artist = "Rollins Band"
333
+ @track_good_4.album = "The End Of Silence"
334
+ @track_good_4.total_time = 324822
335
+ @track_good_4.year = 1992
336
+ @track_good_4.bit_rate = 128
337
+ @track_good_4.play_count = 4
338
+ @track_good_4.rating = 60
339
+ @track_good_4.date_added = Date.parse("Jul 17, 2004 1:41:11 PM")
340
+ @track_good_4.genre = "Rock"
341
+
342
+ @track_good_5 = OpenStruct.new
343
+ @track_good_5.track_id = 2446
344
+ @track_good_5.name = "Grip"
345
+ @track_good_5.artist = "Rollins Band"
346
+ @track_good_5.album = "The End Of Silence"
347
+ @track_good_5.total_time = 290967
348
+ @track_good_5.year = 1992
349
+ @track_good_5.bit_rate = 128
350
+ @track_good_5.play_count = 3268832190
351
+ @track_good_5.rating = 60
352
+ @track_good_5.date_added = Date.parse("Jul 17, 2004 1:41:11 PM")
353
+ @track_good_5.genre = "Rock"
354
+
355
+ @track_good_6 = OpenStruct.new
356
+ @track_good_6.track_id = 2447
357
+ @track_good_6.name = "Tearing"
358
+ @track_good_6.artist = "Rollins Band"
359
+ @track_good_6.album = "The End Of Silence"
360
+ @track_good_6.total_time = 296819
361
+ @track_good_6.year = 1992
362
+ @track_good_6.bit_rate = 128
363
+ @track_good_6.play_count = 12
364
+ @track_good_6.rating = 80
365
+ @track_good_6.date_added = Date.parse("Jul 17, 2004 1:41:11 PM")
366
+ @track_good_6.genre = "Rock"
367
+
368
+ @track_good_7 = OpenStruct.new
369
+ @track_good_7.track_id = 2448
370
+ @track_good_7.name = "You Didn't Need"
371
+ @track_good_7.artist = "Rollins Band"
372
+ @track_good_7.album = "The End Of Silence"
373
+ @track_good_7.total_time = "The End Of Silence"
374
+ @track_good_7.year = 1992
375
+ @track_good_7.bit_rate = 128
376
+ @track_good_7.play_count = 6
377
+ @track_good_7.rating = 60
378
+ @track_good_7.date_added = Date.parse("Jul 17, 2005 1:41:11 PM")
379
+ @track_good_7.genre = "Rap"
380
+
381
+ @track_good_8 = OpenStruct.new
382
+ @track_good_8.track_id = 2855
383
+ @track_good_8.name = "Progeny"
384
+ @track_good_8.artist = "Hans Zimmer &#38; Lisa Gerrard"
385
+ @track_good_8.album = "Gladiator Soundtrack"
386
+ @track_good_8.total_time = 133559
387
+ @track_good_8.year = 2000
388
+ @track_good_8.bit_rate = 128
389
+ @track_good_8.play_count = 5
390
+ @track_good_8.rating = 60
391
+ @track_good_8.date_added = Date.parse("Jul 17, 2005 1:41:11 PM")
392
+ @track_good_8.genre = "Rap"
393
+
394
+ @track_good_9 = OpenStruct.new
395
+ @track_good_9.track_id = 2856
396
+ @track_good_9.name = "The Wheat"
397
+ @track_good_9.artist = "The Lyndhurst Orchestra"
398
+ @track_good_9.album = "Gladiator Soundtrack"
399
+ @track_good_9.total_time = 63226
400
+ @track_good_9.year = 2000
401
+ @track_good_9.bit_rate = 128
402
+ @track_good_9.play_count = 4
403
+ @track_good_9.rating = 60
404
+ @track_good_9.date_added = Date.parse("Jul 17, 2005 1:41:11 PM")
405
+ @track_good_9.genre = "Rap"
406
+
407
+ @track_good_10 = OpenStruct.new
408
+ @track_good_10.track_id = 3100
409
+ @track_good_10.name = "Hule Lam"
410
+ @track_good_10.artist = "Juno Reactor"
411
+ @track_good_10.album = "Shango"
412
+ @track_good_10.total_time = 240255
413
+ @track_good_10.year = 2000
414
+ @track_good_10.bit_rate = 128
415
+ @track_good_10.play_count = 17
416
+ @track_good_10.rating = 80
417
+ @track_good_10.date_added = Date.parse("Jul 17, 2005 1:41:11 PM")
418
+ @track_good_10.genre = "Rap"
419
+
420
+ @track_good_11 = OpenStruct.new
421
+ @track_good_11.track_id = 1554
422
+ @track_good_11.name = "Asi Sysladi"
423
+ @track_good_11.artist = "Sigur Rós"
424
+ @track_good_11.album = "Agaetis Byrjun"
425
+ @track_good_11.total_time = "Agaetis Byrjun"
426
+ @track_good_11.year = 2000
427
+ @track_good_11.bit_rate = 128
428
+ @track_good_11.play_count = 6
429
+ @track_good_11.rating = 20
430
+ @track_good_11.date_added = Date.parse("Jul 17, 2005 1:41:11 PM")
431
+ @track_good_11.genre = "Rap"
432
+
433
+ @tracks_good = [ @track_good, @track_good_2, @track_good_3, @track_good_4, @track_good_5, @track_good_6, @track_good_7, @track_good_8, @track_good_9, @track_good_10, @track_good_11 ]
434
+
435
+ # 15 seconds total time
436
+ @track_good_seconds_1 = OpenStruct.new
437
+ @track_good_seconds_1.track_id = 1557
438
+ @track_good_seconds_1.name = "Gotti Teiknadi"
439
+ @track_good_seconds_1.artist = "Sigur Rós"
440
+ @track_good_seconds_1.album = "Agaetis Byrjun"
441
+ @track_good_seconds_1.total_time = 15000
442
+ @track_good_seconds_1.year = 2000
443
+ @track_good_seconds_1.bit_rate = 128
444
+ @track_good_seconds_1.play_count = 16
445
+ @track_good_seconds_1.rating = 60
446
+
447
+ # 17.035 seconds total time
448
+ @track_good_seconds_2 = OpenStruct.new
449
+ @track_good_seconds_2.track_id = 1556
450
+ @track_good_seconds_2.name = "Höddi Hlustadi"
451
+ @track_good_seconds_2.artist = "Sigur Rós"
452
+ @track_good_seconds_2.album = "Agaetis Byrjun"
453
+ @track_good_seconds_2.total_time = 17035
454
+ @track_good_seconds_2.year = 2000
455
+ @track_good_seconds_2.bit_rate = 128
456
+ @track_good_seconds_2.play_count = 11
457
+ @track_good_seconds_2.rating = 60
458
+
459
+ # 5 minutes total time
460
+ @track_good_minutes = OpenStruct.new
461
+ @track_good_minutes.track_id = 4000
462
+ @track_good_minutes.name = "Höddi Hlustadi minutes"
463
+ @track_good_minutes.artist = "Sigur Rós minutes"
464
+ @track_good_minutes.album = "Agaetis Byrjun minutes"
465
+ @track_good_minutes.total_time = 300000
466
+ @track_good_minutes.year = 2000
467
+ @track_good_minutes.bit_rate = 128
468
+ @track_good_minutes.play_count = 11
469
+ @track_good_minutes.rating = 60
470
+
471
+ # 5 hours total time
472
+ @track_good_hours = OpenStruct.new
473
+ @track_good_hours.track_id = 4001
474
+ @track_good_hours.name = "Höddi Hlustadi hours"
475
+ @track_good_hours.artist = "Sigur Rós hours"
476
+ @track_good_hours.album = "Agaetis Byrjun hours"
477
+ @track_good_hours.total_time = 18000000
478
+ @track_good_hours.year = 2000
479
+ @track_good_hours.bit_rate = 128
480
+ @track_good_hours.play_count = 11
481
+ @track_good_hours.rating = 60
482
+
483
+ # 5 days total time
484
+ @track_good_days = OpenStruct.new
485
+ @track_good_days.track_id = 4001
486
+ @track_good_days.name = "Höddi Hlustadi days"
487
+ @track_good_days.artist = "Sigur Rós days"
488
+ @track_good_days.album = "Agaetis Byrjun days"
489
+ @track_good_days.total_time = 432000000
490
+ @track_good_days.year = 2000
491
+ @track_good_days.bit_rate = 128
492
+ @track_good_days.play_count = 11
493
+ @track_good_days.rating = 60
494
+
495
+ @tracks_total_seconds = [ @track_good_seconds_1, @track_good_seconds_2 ] # 32.035 seconds total time
496
+ @tracks_total_minutes = [ @track_good_seconds_1, @track_good_seconds_2, @track_good_minutes ] # 5 minutes, 32.035 seconds total time
497
+ @tracks_total_hours = [ @track_good_seconds_1, @track_good_seconds_2, @track_good_minutes, @track_good_hours ] # 5 hours, 5 minutes, 32.035 seconds total time
498
+ @tracks_total_days = [ @track_good_seconds_1, @track_good_seconds_2, @track_good_minutes, @track_good_hours, @track_good_days ] # 5 days, 5 hours, 5 minutes, 32 second total time
499
+
500
+ @track_good_positive_correlation_1 = OpenStruct.new
501
+ @track_good_positive_correlation_1.track_id = 1554
502
+ @track_good_positive_correlation_1.name = "Asi Sysladi"
503
+ @track_good_positive_correlation_1.artist = "Sigur Rós"
504
+ @track_good_positive_correlation_1.album = "Agaetis Byrjun"
505
+ @track_good_positive_correlation_1.total_time = 300000
506
+ @track_good_positive_correlation_1.year = 2000
507
+ @track_good_positive_correlation_1.bit_rate = 256
508
+ @track_good_positive_correlation_1.play_count = 10
509
+ @track_good_positive_correlation_1.rating = 100
510
+ @track_good_positive_correlation_1.date_added = Date.parse("Jul 17, 2002 1:41:11 PM")
511
+
512
+ @track_good_positive_correlation_2 = OpenStruct.new
513
+ @track_good_positive_correlation_2.track_id = 1554
514
+ @track_good_positive_correlation_2.name = "Asi Sysladi"
515
+ @track_good_positive_correlation_2.artist = "Sigur Rós"
516
+ @track_good_positive_correlation_2.album = "Agaetis Byrjun"
517
+ @track_good_positive_correlation_2.total_time = 300000
518
+ @track_good_positive_correlation_2.year = 2000
519
+ @track_good_positive_correlation_2.bit_rate = 128
520
+ @track_good_positive_correlation_2.play_count = 5
521
+ @track_good_positive_correlation_2.rating = 50
522
+ @track_good_positive_correlation_2.date_added = Date.parse("Jul 17, 2002 1:41:11 PM")
523
+
524
+ @track_good_negative_correlation_1 = OpenStruct.new
525
+ @track_good_negative_correlation_1.track_id = 1554
526
+ @track_good_negative_correlation_1.name = "Asi Sysladi"
527
+ @track_good_negative_correlation_1.artist = "Sigur Rós"
528
+ @track_good_negative_correlation_1.album = "Agaetis Byrjun"
529
+ @track_good_negative_correlation_1.total_time = 300000
530
+ @track_good_negative_correlation_1.year = 2000
531
+ @track_good_negative_correlation_1.bit_rate = 256
532
+ @track_good_negative_correlation_1.play_count = 5
533
+ @track_good_negative_correlation_1.rating = 100
534
+ @track_good_negative_correlation_1.date_added = Date.parse("Jul 17, 2002 1:41:11 PM")
535
+
536
+ @track_good_negative_correlation_2 = OpenStruct.new
537
+ @track_good_negative_correlation_2.track_id = 1554
538
+ @track_good_negative_correlation_2.name = "Asi Sysladi"
539
+ @track_good_negative_correlation_2.artist = "Sigur Rós"
540
+ @track_good_negative_correlation_2.album = "Agaetis Byrjun"
541
+ @track_good_negative_correlation_2.total_time = 300000
542
+ @track_good_negative_correlation_2.year = 2000
543
+ @track_good_negative_correlation_2.bit_rate = 128
544
+ @track_good_negative_correlation_2.play_count = 10
545
+ @track_good_negative_correlation_2.rating = 50
546
+ @track_good_negative_correlation_2.date_added = Date.parse("Jul 17, 2002 1:41:11 PM")
547
+
548
+ @tracks_positive_correlation = [ @track_good_positive_correlation_1, @track_good_positive_correlation_2 ]
549
+ @tracks_negative_correlation = [ @track_good_negative_correlation_1, @track_good_negative_correlation_2 ]
550
+ end
551
+
552
+ def test_parse_library_good
553
+ # parse the test library (good)
554
+ tracks = @data_miner.parse_library(@sample_library_xml_good)
555
+
556
+ # verify that the data was successfully parsed
557
+ assert_equal(3, tracks.length)
558
+ assert_equal(510, tracks[0].track_id)
559
+ assert_equal(1556, tracks[1].track_id)
560
+ assert_equal(1557, tracks[2].track_id)
561
+ end
562
+
563
+ def test_parse_library_bad
564
+ tracks = @data_miner.parse_library(@sample_library_xml_bad)
565
+ assert_equal(0, tracks.length)
566
+ end
567
+
568
+
569
+ def test_get_number_of_artists
570
+ # verify that 2 artists are found
571
+ assert_equal(6, @data_miner.get_number_of_artists(@tracks_good))
572
+ end
573
+
574
+ def test_get_number_of_genres
575
+ # verify that 3 genres are found
576
+ assert_equal(3, @data_miner.get_number_of_genres(@tracks_good))
577
+ end
578
+
579
+ def test_get_number_of_albums
580
+ # verify that 2 albums are found
581
+ assert_equal(5, @data_miner.get_number_of_albums(@tracks_good))
582
+ end
583
+
584
+ def test_get_number_of_tracks
585
+ # verify that 3 tracks are found
586
+ assert_equal(11, @data_miner.get_number_of_tracks(@tracks_good))
587
+ end
588
+
589
+ def test_get_tracks_added_by_year
590
+ tracks_added_by_year = @data_miner.get_tracks_added_by_year(@tracks_good)
591
+ # puts tracks_added_by_year.
592
+
593
+ # verify that 4 years are found
594
+ assert_equal(4, tracks_added_by_year.length)
595
+
596
+ # verify that the correct #'s are found
597
+ assert_equal(2002, tracks_added_by_year[0][0])
598
+ assert_equal(1, tracks_added_by_year[0][1])
599
+ assert_equal(2003, tracks_added_by_year[1][0])
600
+ assert_equal(2, tracks_added_by_year[1][1])
601
+ assert_equal(2004, tracks_added_by_year[2][0])
602
+ assert_equal(3, tracks_added_by_year[2][1])
603
+ assert_equal(2005, tracks_added_by_year[3][0])
604
+ assert_equal(5, tracks_added_by_year[3][1])
605
+ end
606
+
607
+ def test_get_total_playtime_seconds
608
+ assert_equal([0, 0, 0, 32], @data_miner.get_total_playtime(@tracks_total_seconds))
609
+ end
610
+
611
+ def test_get_total_playtime_minutes
612
+ assert_equal([0, 0, 5, 32], @data_miner.get_total_playtime(@tracks_total_minutes))
613
+ end
614
+
615
+ def test_get_total_playtime_hours
616
+ assert_equal([0, 5, 5, 32], @data_miner.get_total_playtime(@tracks_total_hours))
617
+ end
618
+
619
+ def test_get_total_playtime_days
620
+ assert_equal([5, 5, 5, 32], @data_miner.get_total_playtime(@tracks_total_days))
621
+ end
622
+
623
+ def test_get_most_popular_artists
624
+ assert_equal([["Rollins Band", 4], ["Sigur Rós", 3]], @data_miner.get_most_popular_artists(@tracks_good, 2))
625
+ assert_equal([["Rollins Band", 4]], @data_miner.get_most_popular_artists(@tracks_good, 1))
626
+ end
627
+
628
+ def test_get_most_popular_years
629
+ assert_equal([[2000, 6], [1992, 4]], @data_miner.get_most_popular_years(@tracks_good, 2))
630
+ assert_equal([[2000, 6]], @data_miner.get_most_popular_years(@tracks_good, 1))
631
+ end
632
+
633
+ def test_get_bitrate_playcount_correlation
634
+ assert_equal(1.0, @data_miner.get_bitrate_playcount_correlation(@tracks_positive_correlation))
635
+ assert_equal(-1.0, @data_miner.get_bitrate_playcount_correlation(@tracks_negative_correlation))
636
+ end
637
+
638
+ def test_get_rating_playcount_correlation
639
+ assert_equal(1.0, @data_miner.get_rating_playcount_correlation(@tracks_positive_correlation))
640
+ assert_equal(-1.0, @data_miner.get_rating_playcount_correlation(@tracks_negative_correlation))
641
+ end
642
+
643
+ def test_guess_age
644
+ # 2008 - 1994 + 14 = 28
645
+ assert_equal(28, @data_miner.guess_age(@tracks_good))
646
+ end
647
+ end