Пример #1
0
 def test_structure_as_row_c(self):
     dict = {
         "a": [1, 2, 3, 4],
         "b": [9, 8, 7, 6],
         "c": [11, 12, 13, 14]
     }
     assert DatasetFormer.structure_as_row(["c"], dict, 3) == [14]
Пример #2
0
def df():
    data_frame = {
        "a": [1, 2, 3, 4],
        "test_target": ['aa','bb','bb','dd'],
        "c": [11, 12, 13, 14]
    }

    ob = DatasetFormer(data_frame, 'test_target')
    # initialize final structure
    return ob
Пример #3
0
def df_popped():
    data_frame = {
        "a": [1, 2, 3, 4],
        "test_target": ['aa','bb','bb','dd'],
        "c": [11, 12, 13, 14],
        "e": [55, 66, 77, 88]
    }

    ob = DatasetFormer(data_frame, 'test_target', ["a", "e"])
    # initialize final structure
    return ob
Пример #4
0
 def test_generate_int_ids_of_items(self):
     assert DatasetFormer.generate_int_ids_of_items(["a", "c", "a"], ["a", "c"]) == [0, 1, 0]
Пример #5
0
 def test_generate_int_id_index_same_alternating(self):
     assert DatasetFormer.generate_int_id_index(["yes", "no", "no", "yes"]) == ([0, 1], ["yes", "no"])
Пример #6
0
 def test_generate_int_id_index_same_items(self):
     assert DatasetFormer.generate_int_id_index(["yes", "yes"]) == ([0], ["yes"])
Пример #7
0
 def test_generate_int_id_index(self):
     assert DatasetFormer.generate_int_id_index(["yes", "no", "maybe", "yes"]) == ([0, 1, 2], ["yes", "no", "maybe"])
Пример #8
0
def main():
    token = fetch_token()
    if token:
        sp = MLearnipy(username, auth=token)

        unsorted_playlist, all_playlists = sp.get_target_and_all_other_pls(selected_features)

        # Form a data-frame for ml analysis
        already_sorted_set = DatasetFormer(all_playlists, 'playlist_id', ['id'])
        incorrectly_sorted_set = DatasetFormer(unsorted_playlist, 'playlist_id', ['id'])

        # playlists_for_unsorted_songs contains ids for playlists to which unsorted songs have to be moved
        # elements of playlists_for_unsorted_songs are in the same order as songs in incorrectly_sorted_set
        playlists_for_unsorted_songs = predict_playlists_for_unsorted_songs(already_sorted_set, incorrectly_sorted_set)

        logger.debug("predicted list: {}".format(playlists_for_unsorted_songs))
        logger.debug("names: {}".format(already_sorted_set.target_names))
        logger.debug("ids : {}".format(already_sorted_set.targets_as_ids))

        remaped_playlist = already_sorted_set.remap_list_of_targets_to_initial_value(playlists_for_unsorted_songs)
        logger.debug("Songs remapped: {}".format(remaped_playlist))

        # returns destination playlist from their respective ids
        pl_names = sp.last_fetch_of_all_pls

        sp.print_separator(' Decluter suggestions ')

        # gets all song ids
        song_ids_list = incorrectly_sorted_set.popped_entries['id']
        raw_track_list = sp.resolve_song_names_from_id_list(song_ids_list)

        tracks = list(
            map(make_track_names, raw_track_list))

        for index,playlist in list(enumerate(remaped_playlist, start=0)):
            # todo add song names here:
            print('#{}\t{}\t->\t{}'.format(index, tracks[index], sp.find_in_list_of_tuples(pl_names, playlist, 0, 1)))

        sp.print_separator(' Chose songs you want to move ')

        for index, playlist in list(enumerate(remaped_playlist, start=0)):

            track = tracks[index]
            pl_name = sp.find_in_list_of_tuples(pl_names, playlist, 0, 1)

            print('Move:\t{}\n#{}\t{} -> {}\n'.format((raw_track_list[index][2]),index, track, pl_name))

            # asks if user want to move a song to a predicted playlist
            if user_confirms():
                print('Moving...')

                # todo: add moving here
                sp.user_playlist_add_tracks(username, playlist, [song_ids_list[index]])

                print('Do you wish to delete the song you just moved?')
                if user_confirms():
                    print('Deleting...')
                    # todo: delete songs here
                    sp.user_playlist_remove_all_occurrences_of_tracks(username, unsorted_playlist['playlist_id'][0], [song_ids_list[index]])


                else:
                    pass

            else:
                pass
            sp.print_separator('')
        sp.print_separator(' Decluterfy finished ')