Esempio n. 1
0
def generate_recommendations(request):
    minsup = int(request.GET.get('minsup', 2))
    minconf = int(request.GET.get('minconf', .3))
    gamma = int(request.GET.get('gamma', .8))

    # Mine recommendations
    recommendations, names = recommend(
            minsup=minsup,
            minconf=minconf,
            gamma=gamma
    )

    # Add recommendations to database
    Recommendation.objects.all().delete()
    for recommendation in recommendations:
        model = Recommendation(
            antecedent_hash = hash(recommendation['antecedent']),
            confidence = recommendation['confidence'],
            support = recommendation['support'],
            milestone = recommendation['milestone'],
            m_name = names[recommendation['milestone']][0],
            name = names[recommendation['consequent']][0],
            consequent = recommendation['consequent'],
            description = names[recommendation['consequent']][1])
        model.save()

    event = LogEvent(type='G', user='******', data=json.dumps(recommendations))
    event.save()
    return HttpResponse(pformat(recommendations))
Esempio n. 2
0
def test():
    try:

        req = flask.request.get_json(silent=True, force=True)
        userid = req.get("userid")
	print int(userid)
	result=rm.recommend(int(userid))
	print "after rfecommend calling"	
        print result 

        logging.info('test started')

        res={
            "message":result
        }
        res = json.dumps(res, indent=4)
        r = flask.make_response(res)
        r.headers['Content-Type'] = 'application/json'
        return r
    except Exception as err:
        logging.info('test failed: %s', err)
        res={"message":"error"}
        res = json.dumps(res, indent=4)
        r = flask.make_response(res)
        r.headers['Content-Type'] = 'application/json'
        return r
Esempio n. 3
0
def recomendacao(update, context):
    update.message.reply_text(
        'Estou calculando algumas boa recomendações para você. Isso pode levar alguns minutos. Eu aviso quando terminar! 😉'
    )

    recomendacoes = recommend(update.message.from_user.id, N=5)

    text = 'Terminei! Aqui estão alguma recomendações de filmes para você!\n'

    index = 1
    msg_sent = False

    for recomendacao in recomendacoes:
        if not msg_sent:
            update.message.reply_text(text)
            msg_sent = True

        movie_id = recomendacao[0]
        poster = get_movie_poster(movie_id)
        title = f'{index} - {get_movie_title(movie_id)}'

        context.bot.send_photo(chat_id=update.message.chat_id,
                               photo=poster,
                               caption=title)
        index += 1
def predict():
    title = request.form.get('title')
    if title not in recommendation.final_rating['title'].unique():
        response = ['Book not found']
    else:
        response = recommendation.recommend(title)

    return render_template('index.html', response=response)
Esempio n. 5
0
def recommendmovie():
    db = connect_db()
    c = db.cursor()

    if request.method == 'POST':
        userName = guid['username']
        recommendation_list['recommendmovie'] = recommendation.recommend(
            userName)
        data = request.get_json()
        movie_title = movie_detail_res['movie']['title']
        genre = c.execute('SELECT * FROM MOVIE WHERE TITLE = ?',
                          (movie_title, )).fetchall()[0][3]
        director = c.execute('SELECT * FROM MOVIE WHERE TITLE = ?',
                             (movie_title, )).fetchall()[0][1]
        genre_list = genre.split(', ')
        director_list = director.split(', ')
        same_genre_list, same_genre_dic, final_result_genre = recommendation.recommendByGenre(
            genre_list, userName, movie_title)
        same_director_list, same_director_dic, final_result_director = recommendation.recommendByDirector(
            director_list, userName, movie_title)
        if data['choice'] == 'g':
            recommendation_list['recommendmovie'] = final_result_genre
            choice['c'] = 'g'
        elif data['choice'] == 'd':
            recommendation_list['recommendmovie'] = final_result_director
            choice['c'] = 'd'
        elif data['choice'] == 'dg':
            choice['c'] = 'dg'
            recommendation_list[
                'recommendmovie'] = recommendation.recommendByGenreAndDirector(
                    same_genre_list, same_genre_dic, same_director_list,
                    same_director_dic)
        else:
            choice['c'] = 'no'

        return "-"

    else:
        if choice['c'] == '':
            userName = guid['username']
            return jsonify(
                {'recommendmovie': recommendation.recommend(userName)})
        return jsonify(recommendation_list)
Esempio n. 6
0
def dashboard():
    access = flask.session['auth_token']['access_token']
    cal.main(access)
    s, e = cal.create_calendar_matrix()

    twitterInfo = twitter.getCalendar('jalfrazi_')
    userInfo = google_auth.get_user_info()
    userId = userInfo['id']

    gmailInfo = gmail.getLastSent(access, userId)

    recommendations = recommendation.recommend()

    return render_template('dashboard.html',
                           slots=s,
                           events=e,
                           twitterInfo=twitterInfo[::-1],
                           gmailInfo=gmailInfo[::-1],
                           user_info=userInfo,
                           recommendations=recommendations)
Esempio n. 7
0
def main():
    dic = {}
    normalization = []
    bunsho_file = sys.argv[1]
    data, book_list = make_jp_data(bunsho_file)
    for i in range(len(data)):
        tfidf, word_list_i = calc_tfidf(data[i], data)
        word_for_normalization, list_for_normalization = make_normalization_data(
            data)
        normalization.append(
            normalize(word_list_i, tfidf, word_for_normalization,
                      list_for_normalization))

    print("\n\n===============similarity===============")
    similarity = calc_cosine_similarity(normalization)
    print(similarity)

    print("\n\n===============recommendation================")
    recommendation = recommend(similarity, book_list)
    if len(recommendation) == 0:
        print("There are no recommendation in the data.")
    else:
        for i, v in enumerate(recommendation.values()):
            print(i + 1, v)
Esempio n. 8
0
import recommendation

recommendation = recommendation.Recommendation()
recommendation.recommend("Spriggan")
Esempio n. 9
0
def practical():
    rec = recommendation.recommend()
    return render_template('practical.html', rec1=rec)
Esempio n. 10
0
#main.py 코드

import recommendation as myRecommend

print("***********영화 추천 프로그램**************")
while True:
    userID = int(input("로그인(-1 to end program): "))
    if userID == -1:
        break
    print()

    rec = myRecommend.recommend(userID)

    while True:
        movieTitle = str(input("영화 제목 : "))
        if movieTitle == "":
            print("-----------------")
            break
        score = float(input(movieTitle + "의 평점 :"))
        rec.add(movieTitle, score)
        print()

    recommended = rec.prediction(10)

    print("< (user", userID, ")님께 추천 드리는 영화 목록 >")
    for movie in recommended:
        print(movie)

    print("\n")
Esempio n. 11
0
def index(request):
    if request.method == 'GET':
        name = request.GET['name']
        k = request.GET['k']

        return HttpResponse(JsonResponse(recommend(name, int(k))))