def setUpClass(cls): #we use the test df target_files = { 'identifier_infos_path' : 'test_df/Apple Music Activity/Identifier Information.json.zip', 'library_tracks_path' : 'test_df/Apple Music Activity/Apple Music Library Tracks.json.zip', 'library_activity_path': 'test_df/Apple Music Activity/Apple Music Library Activity.json.zip', 'likes_dislikes_path' : 'test_df/Apple Music Activity/Apple Music Likes and Dislikes.csv', 'play_activity_path': 'test_df/Apple Music Activity/Apple Music Play Activity.csv' } cls.input_df = Utility.get_df_from_archive('apple_music_analyser/tests/test_df.zip', target_files) cls.parser = Parser(cls.input_df) cls.likes_dislikes_df = cls.parser.likes_dislikes_df cls.play_activity_df = cls.parser.play_activity_df cls.identifier_infos_df = cls.parser.identifier_infos_df cls.library_tracks_df = cls.parser.library_tracks_df cls.library_activity_df = cls.parser.library_activity_df #we process the df cls.process = ProcessTracks() cls.process.process_library_tracks_df(cls.library_tracks_df) cls.process.process_identifier_df(cls.identifier_infos_df) cls.process.process_play_df(cls.play_activity_df) cls.process.process_likes_dislikes_df(cls.likes_dislikes_df) #we extract the useful objects from the process instance cls.track_instance_dict = cls.process.track_instance_dict cls.artist_tracks_titles = cls.process.artist_tracks_titles cls.genres_list = cls.process.genres_list cls.items_not_matched = cls.process.items_not_matched
def test_get_df_from_archive_with_target(self): ''' We test the case where the structure inside the archive is provided as an argument. This function relies on external package (ZipFile), well covered by tests. ''' target_files = { 'identifier_infos_path': 'test_df/Apple Music Activity/Identifier Information.json.zip', 'library_tracks_path': 'test_df/Apple Music Activity/Apple Music Library Tracks.json.zip', 'library_activity_path': 'test_df/Apple Music Activity/Apple Music Library Activity.json.zip', 'likes_dislikes_path': 'test_df/Apple Music Activity/Apple Music Likes and Dislikes.csv', 'play_activity_path': 'test_df/Apple Music Activity/Apple Music Play Activity.csv' } archive_path = 'apple_music_analyser/tests/test_df.zip' result = Utility.get_df_from_archive(archive_path, target_files) self.assertTrue(isinstance(result, dict)) self.assertEqual(len(result), 5) self.assertEqual(list(result.keys()), [ 'identifier_infos_df', 'library_tracks_df', 'library_activity_df', 'likes_dislikes_df', 'play_activity_df' ]) for key in result.keys(): self.assertTrue(isinstance(result[key], pd.DataFrame))
def test_get_df_from_archive_bad_archive(self): ''' We test the case where the path is wrong This function relies on external package (ZipFile), well covered by tests. ''' archive_path = None result = Utility.get_df_from_archive(archive_path) self.assertEqual(result, {})
def setUp(self): target_files = { 'identifier_infos_path' : 'test_df/Apple Music Activity/Identifier Information.json.zip', 'library_tracks_path' : 'test_df/Apple Music Activity/Apple Music Library Tracks.json.zip', 'library_activity_path': 'test_df/Apple Music Activity/Apple Music Library Activity.json.zip', 'likes_dislikes_path' : 'test_df/Apple Music Activity/Apple Music Likes and Dislikes.csv', 'play_activity_path': 'test_df/Apple Music Activity/Apple Music Play Activity.csv' } self.input_df = Utility.get_df_from_archive('apple_music_analyser/tests/test_df.zip', target_files) self.df_visualization = VisualizationDataframe(self.input_df)
def setUp(self): target_files = { 'identifier_infos_path' : 'test_df/Apple Music Activity/Identifier Information.json.zip', 'library_tracks_path' : 'test_df/Apple Music Activity/Apple Music Library Tracks.json.zip', 'library_activity_path': 'test_df/Apple Music Activity/Apple Music Library Activity.json.zip', 'likes_dislikes_path' : 'test_df/Apple Music Activity/Apple Music Likes and Dislikes.csv', 'play_activity_path': 'test_df/Apple Music Activity/Apple Music Play Activity.csv' } self.input_df = Utility.get_df_from_archive('apple_music_analyser/tests/test_df.zip', target_files) self.parser = Parser(self.input_df) self.likes_dislikes_df = self.parser.likes_dislikes_df self.play_activity_df = self.parser.play_activity_df self.identifier_infos_df = self.parser.identifier_infos_df self.library_tracks_df = self.parser.library_tracks_df self.library_activity_df = self.parser.library_activity_df self.process = ProcessTracks() self.track_instance = Track(self.process.increment)
def test_init_Parser(self): target_files = { 'identifier_infos_path': 'test_df/Apple Music Activity/Identifier Information.json.zip', 'library_tracks_path': 'test_df/Apple Music Activity/Apple Music Library Tracks.json.zip', 'library_activity_path': 'test_df/Apple Music Activity/Apple Music Library Activity.json.zip', 'likes_dislikes_path': 'test_df/Apple Music Activity/Apple Music Likes and Dislikes.csv', 'play_activity_path': 'test_df/Apple Music Activity/Apple Music Play Activity.csv' } input_df = Utility.get_df_from_archive( 'apple_music_analyser/tests/test_df.zip', target_files) shape_input_likes_dislikes_df = input_df['likes_dislikes_df'].shape shape_input_play_activity_df = input_df['play_activity_df'].shape shape_input_identifier_infos_df = input_df['identifier_infos_df'].shape shape_input_library_tracks_df = input_df['library_tracks_df'].shape shape_input_library_activity_df = input_df['library_activity_df'].shape result = Parser(input_df) self.assertTrue(isinstance(result.likes_dislikes_df, pd.DataFrame)) self.assertEqual(result.likes_dislikes_df.shape, (shape_input_likes_dislikes_df[0], shape_input_likes_dislikes_df[1] + 2)) self.assertTrue(isinstance(result.play_activity_df, pd.DataFrame)) self.assertEqual(result.play_activity_df.shape, (shape_input_play_activity_df[0] - 1, shape_input_play_activity_df[1] - 14)) self.assertTrue(isinstance(result.identifier_infos_df, pd.DataFrame)) self.assertEqual(result.identifier_infos_df.shape, (shape_input_identifier_infos_df[0], shape_input_identifier_infos_df[1])) self.assertTrue(isinstance(result.library_tracks_df, pd.DataFrame)) self.assertEqual(result.library_tracks_df.shape, (shape_input_library_tracks_df[0], shape_input_library_tracks_df[1] - 34)) self.assertTrue(isinstance(result.library_activity_df, pd.DataFrame)) self.assertEqual(result.library_activity_df.shape, (shape_input_library_activity_df[0], shape_input_library_activity_df[1] + 8))
########################################################################################################################### # we assume you have an instance of the visualization dataframe class saved in the same folder under the name 'viz_df_instance.pkl' viz_df_instance = Utility.load_from_pickle('viz_df_instance.pkl') # SAVE A PICKLE ########################################################################################################################### # get the input file - see starter_code.py for more details path_to_archive = '../apple_music_analyser/tests/test_df.zip' target_files = { 'identifier_infos_path': 'test_df/Apple Music Activity/Identifier Information.json.zip', 'library_tracks_path': 'test_df/Apple Music Activity/Apple Music Library Tracks.json.zip', 'library_activity_path': 'test_df/Apple Music Activity/Apple Music Library Activity.json.zip', 'likes_dislikes_path': 'test_df/Apple Music Activity/Apple Music Likes and Dislikes.csv', 'play_activity_path': 'test_df/Apple Music Activity/Apple Music Play Activity.csv' } input_df = Utility.get_df_from_archive(path_to_archive, target_files) # create an instance of the visualization dataframe class viz_df_instance = VisualizationDataframe(input_df) # save the instance Utility.save_to_pickle(viz_df_instance, 'viz_df_instance.pkl')