def test_fun(func):
    with open(DATA_FILE) as reader:
        js = json.load(reader)
    i, j = 0, 0
    for filename, ans in js.items():
        ml = movies.MovieList(md.read_movies(filename))
        recom = func(ml, ans['hours'])
        if (recom.total_rating - ans['rating']) > -0.1:
            print(i, ' passed ', j, 'failed', '\r', end="")
            i += 1
        else:
            j += 1
            print(filename, '\t', recom.total_rating, ans['rating'])
            print(recom)
            print(ans['movies'])
    print(i, " of ", len(js), " passed, (", j, " failed)")
def make_data():
    hours = 10
    data = {}
    for i in range(310):
        filename = "data/rand/rand{index}.csv".format(index=i)
        mlist = movies.MovieList(md.read_movies(filename))
        recom = movies.filtered_combinations(mlist, hours)
        print(filename)
        data[filename] = {
            'rating': recom.total_rating,
            'time': recom.time,
            'movies': [m.name for m in recom.movies.values()],
            'hours': hours,
        }
        with open(DATA_FILE, 'w') as writer:
            json.dump(data, writer)
Exemple #3
0
    logging.info("Restarting saved poll.")
    logging.debug("Using data %s", pollData)
    currentPoll = Polls.Poll(suggestion = pollData, isActive = True)
else:
    #Instantiate poll, without passing it data
    logging.info("Creating fresh poll")
    currentPoll = Polls.Poll()

if os.path.exists(movieFile):
    #Code to read file and save it as "movieList"
    logging.debug("Found file '%s'", movieFile)
    movieData = storage.load(movieFile)
    #Instantiate poll, passing it data and updating the isActive flag because we know a poll was already started. Poor bot probably died.
    logging.info("Loading saved movie list.")
    logging.debug("Using data %s", movieData)
    movieList = movies.MovieList(movieData)
else:
    movieList = movies.MovieList()

bot = commands.Bot(command_prefix='!')

@bot.event
async def on_ready():
    for guild in bot.guilds:
        if guild.name == GUILD:
            break

    logging.info("Connected to discord guild %s.", guild.name)
    logging.debug(f'{bot.user.name} is connected to the following guild: \n\n'
            f'{guild.name}(id: {guild.id})')
Exemple #4
0
        m = movies.Movie(row.Name, row.rating, row.time_min)
        movie_list.append(m)
    return movie_list


if __name__ == '__main__':
    print("reading files")
    # random_data(100)
    t1 = time.time()
    # mlist= movies.MovieList(read_movies())
    hours = 10
    if False:
        for i in range(10):
            fn = "data/rand/rand{index}.csv".format(index=i)
            print(fn)
            mlist = movies.MovieList(read_movies(fn))
            recomm = movies.filtered_combinations(mlist, hours)
            # recomm2= movies.bruteforce(mlist,hours)
            print(recomm)
            # print("A:%.2f, B:%.2f\t\t%s"%(recomm.total_rating,recomm2.total_rating,"" if (recomm.total_rating<=recomm2.total_rating) else '**'))

    mlist = movies.MovieList(read_movies("data/rand/rand0.csv"))
    # mlist= movies.MovieList(read_movies())
    print("total movies: ", mlist.total_count)
    # print(mlist)
    if True:
        print("time", time.time() - t1)
        print("recommendations: weighted")
        t1 = time.time()
        recomm = movies.weighted_recommendations(mlist, hours)
        print("time", time.time() - t1)