def recommend():
    redirectPage = 'recommendations.html'
    data = {}
    productid2name = {}
    userRatings= {}
    db = connect_to_db()
    cur = db.cursor(cursor_factory=psycopg2.extras.DictCursor)
    
    try:
        cur.execute(movieRatingQuery)
        results = cur.fetchall()
    except Exception as e:
        print("Error: SEARCH in 'movie_ratings table: %s" % e)
    
    for row in results:
        user = row['id']
        movie = row['movie_id']
        rating = float(row['rating'])
        if user in data:
            currentRatings = data[user]
        else:
            currentRatings = {}
        currentRatings[movie] = rating
        data[user] = currentRatings
    
    try:
        cur.execute(movieIDQuery)
        results = cur.fetchall()
    except Exception as e:
        print("Error: SEARCH in 'movie_titles' table: %s" % e)
    
    cur.close()
    db.close()
    movieLens = recommender(5, 15) #Manhattan Distance 5 Nearest Neighbors
Exemple #2
0
def coffee_table_seeker():
    image_url = str(request.form['image_url'])
    description = str(unicode(request.form['description']).encode('ascii', 'ignore'))
    price_limit = str(request.form['price_limit'])
    
    category = 'coffee_table'
    cat = 'coffee table'
    form_action = "/" + category + "_seeker#portfolio"

    if len(image_url) > 0:
        try:
            image = imread(image_url)
        except IOError:
            return render_template('input.html', cat=cat, msg='Oops! That was not a image url. ', form_action=form_action)
    else:
        image = None

    if len(price_limit) > 0:
        try:
            price_limit = int(price_limit)
        except ValueError:
            return render_template('input.html', cat=cat, msg='Oops! Please enter a number in the price limit box. ', form_action=form_action)
    else:
        price_limit = None

    final_df = recommender(image=image, text=description, category=category, pca_scaler_dict=pca_scaler_dict, 
        pca_model_dict=pca_model_dict, tfidf_dict=tfidf_dict, all_info_df_dict=all_info_df_dict,
        color=False, price_limit=price_limit)

    if final_df is None:
        return render_template('input.html', cat=cat, msg='Oops! No items found! Please increase the price limit. ', form_action=form_action)
    
    base_path = '../static/img/wayfair/' + category + '/'
    return render_template('seeker.html', cat=cat, df=final_df, base_path=base_path, form_action=form_action)
Exemple #3
0
def main():
    print("This is the demo for the recommender!")

    # because I don't have the keywords for'Office for Students with Disabilities'
    dummy_services = SERVICES
    # shall be the review csv file, use the dummy one I created for testing
    review_database = REVIEW_DATABASE
    # points to the folder containing the keywords for each service
    service_folder = SERVICE_KEYWORD_FOLDER

    print("Services are: {}".format(dummy_services))

    # init the recommender
    rr = recommender.recommender(n_service=N_SERVICE,
                                 service_list=dummy_services,
                                 n_fixed_feature=10,
                                 top_k=TOP_K,
                                 cut_off=CUTOFF,
                                 review_file=review_database,
                                 service_kw_folder=service_folder,
                                 n_keyword=7,
                                 learning_rate=0.0015)
    # randomly init weights!
    rr.init_weights()

    print("recommender model inited!")

    while (True):
        print("Key in user profile:\n")
        user_profile = dict()
        for f in U_FEATURES:
            user_profile[f] = input("\t{}: ".format(f))

        print(user_profile)

        print(
            "Preset user's goal: I want spend time talking iwth someone. I need advice."
        )
        user_goal = [['time', 0.5], ['talk', 0.5], ['friendly', 0.5],
                     ['advice', 0.5]]
        user_rating = {
            'Group Therapy': (3, 5),
            'Vent Over Tea': (5, 5),
            '7 Cups': (4, 5)
        }
        print("Preset user's rating: user_rating")

        # get the service index of top_k choices, start from 0
        choices, service_names = rr.get_recommendation(user_profile,
                                                       user_goal,
                                                       verbose=False)
        # print("returned indices (start from 0): {}".format(choices))
        choices_for_chatbot = [c + 1 for c in choices]
        print(
            "service indicies (start from 1): {}".format(choices_for_chatbot))
        print("returned names:{}".format(service_names))

        # update the weights (ML-ish learning)
        user_scores = rr.process_user_rating(user_rating)
        rr.update_weights(user_profile, user_scores, choices, verbose=False)
Exemple #4
0
def results():
    if request.method == 'POST':
        #get the data from the form 
        className = request.form.get('className', None)
        classNumber = request.form.get('classNumber', None)
        instructor = request.form.get('instructor', None).upper()
        classInput =  className.upper() + "-" + classNumber
        
        #retrive data from "server"
        result = parse.getClass(classInput, instructor, mainDictionary)
        
        #check if the input matched a class
        if not result: 
            return render_template('Error.html',
                                    results = classInput,
                                    instructor = instructor)
        else:
            final = recommender.recommender(classInput, instructor, result)
            
            return render_template('results.html',
                            title = 'Results',
                            results = final)
                        
    elif request.method == 'GET':
        return render_template('results.html')
def searchAdaptation(user, timestamp, event, idView):

    #global mutex
    #while mutex:# getSemaforo(session):
    #	pass
    #mutex = 1#setSemaforo(session)
    #atualiza o sumario
    #global sumario

    ##aqui arquivo
    sumarioFile = open("sumario.csv", "r")
    dataSumario = sumarioFile.readlines()
    sumarioAux = list()
    for i in dataSumario:
        sumarioAux.append(i[0:-1])
    sumarioFile.close()

    sumario = LoadSummarizerByUser(user, timestamp, event, idView, sumarioAux)

    sumarioAux = open("sumario.csv", "w")
    sumarioAux.close

    sumarioAux = open("sumario.csv", "a+")
    for i in sumario:
        sumarioAux.write(i + "\n")
    sumarioAux.close

    #sumarioL = sumario
    recomendationUser = analytics(user, sumario, idView)
    print "sumario"
    print sumario

    dt = datetime.now()
    strTimeDate = str(dt.day) + "/" + str(dt.month) + "/" + str(
        dt.year) + "-" + str(dt.hour) + ":" + str(dt.minute) + ":" + str(
            dt.second) + "-" + user + ";" + str(sumario) + "\n"
    logService = open("SERVICE_log.csv", "a+")
    logService.write(strTimeDate)
    logService.close()

    #print ""
    #print "recomendation"
    #print recomendation
    #print ""
    idQuestion = idView.split(":")
    feedback = []
    if recomendationUser == True:
        feedback = recommender(user, recomendation, int(idQuestion[1]),
                               int(timestamp))
    else:
        feedback = lastRecommendation(user, recomendation, int(idQuestion[1]),
                                      int(timestamp))
    mutex = 0  #releaseSemaforo
    print "feedback recomendation\n\n"
    print feedback[0]
    print ""
    return feedback
 def index(self, path=flickr_test_set_path[9]):
     print "index page, sample path with", path
     img = caffe.io.load_image(path)
     print "start predict"
     res = self.our_model.predict(img)
     res["recommended"] = recom.recommender(res)
     print res
     print "end predict"
     return json.dumps(res)
Exemple #7
0
def get_recommendations(id, n_recommendations):

    # query = str(request.args['Query'])
    # return query
    d = {}
    # d['Query'] = str(request.args['Query'])
    rec = recommender()

    d['category'] = rec.make_recommendations(id, n_recommendations)
    print(d['category'])
    return jsonify(d)
Exemple #8
0
def auto_rec_add(username, add_tracks='max', clientID = '<>', clientSecret = '<>'):
    pl_uri = raw_input('Please enter playlist URI: ')
    uri = pl_uri.split(':')[-1]
    username = username.split(':')[-1]

    test_class = recommender.recommender(username=username, clientID=clientID, clientSecret=clientSecret)
    print('Token Retrieved')
    test_class.create_user_instance()
    print('User Instance Created')
    test_class.user_get_playlist_tracks(uri)
    print('Playlist Tracks Retrieved')
    test_class.user_get_playlist_track_audio_feat()
    print('Track features Retrieved')
    test_class.user_playlist_recommend_tracks()
    print('Tracks recommended')
    test_class.user_playlist_add_tracks(playlist_id=uri, num_tracks_add=add_tracks)
Exemple #9
0
def recommend():
    redirectPage = 'recommendations.html'
    
    data = {}
    productid2name = {}
    userRatings= {}
    db = connect_to_db()
    cur = db.cursor(cursor_factory=psycopg2.extras.DictCursor)
    cur.execute(movieRatingQuery)
    results = cur.fetchall()
    
    for row in results:
        user = row['id']
        movie = row['movie_id']
        rating = float(row['rating'])
        if user in data:
            currentRatings = data[user]
        else:
            currentRatings = {}
        currentRatings[movie] = rating
        data[user] = currentRatings
    
    cur.execute(movieIDQuery)
    results = cur.fetchall()
    
    for row in results:
        movieID = row['id']
        title = row['movie_title']
        productid2name[movieID] = title
    
    cur.close()
    db.close()
    
   
    
    movieLens = recommender(5, 15) #Manhattan Distance 5 Nearest Neighbors
    movieLens.data = data
    print(movieLens.recommend(1))
    
    
    # movieLens.computeSlopeOneDeviations()
    # print("Did I get ere")
    # print(movieLens.slopeOneRecommendations(data['1']))
     

    return render_template(redirectPage)
Exemple #10
0
def recommend(test):
    print("Do I get here?")
    redirectPage = 'recommendations.html'
    data = {}
    productid2name = {}
    userRatings= {}
    db = connect_to_db()
    cur = db.cursor(cursor_factory=psycopg2.extras.DictCursor)
    
    try:
        cur.execute(movieRatingQuery)
        results = cur.fetchall()
    except Exception as e:
        print("Error: SEARCH in 'movie_ratings table: %s" % e)
    
    for row in results:
        user = row['id']
        movie = row['movie_id']
        rating = float(row['rating'])
        if user in data:
            currentRatings = data[user]
        else:
            currentRatings = {}
        currentRatings[movie] = rating
        data[user] = currentRatings
    
    try:
        cur.execute(movieIDQuery)
        results = cur.fetchall()
    except Exception as e:
        print("Error: SEARCH in 'movie_titles' table: %s" % e)
    
    cur.close()
    db.close()
    movieLens = recommender(5, 15) #Manhattan Distance 5 Nearest Neighbors
    movieLens.data = data
    results = movieLens.recommend(session['id'])
    print(results)
    queryResults = []
    for i,movie in results:
        queryResults.append({'text': movie[0]})
        
    print(queryResults)
    
    emit('recommendationResults', queryResults)
def recommend(test):
    data = {}
    db = connect_to_db()
    cur = db.cursor(cursor_factory=psycopg2.extras.DictCursor)
    error = ''
    try:
        cur.execute(movieRatingQuery)
        results = cur.fetchall()
    except Exception as e:
        print("Error: SEARCH in 'movie_ratings table: %s" % e)
    
    if len(results) == 0:
        error += 'You have not rated any movies yet!'
        emit('error', {'exists' : len(error) != 0, 'message' : error, 'type' : 'recommend'})
    else:
        for row in results:
            user = row['id']
            movie = row['movie_id']
            rating = float(row['rating'])
            if user in data:
                currentRatings = data[user]
            else:
                currentRatings = {}
            currentRatings[movie] = rating
            data[user] = currentRatings
        
        try:
            cur.execute(movieIDQuery)
            results = cur.fetchall()
        except Exception as e:
            print("Error: SEARCH in 'movie_titles' table: %s" % e)
        
        cur.close()
        db.close()
        
        movieLens = recommender(5, 15) #Manhattan Distance 5 Nearest Neighbors
        movieLens.data = data
        results = movieLens.recommend(session['id'])
        print(results)
        queryResults = []
        for i,movie in enumerate(results):
            queryResults.append({'text': movie[0], 'rank': str(i+1)})
        
        emit('recommendationResults', {'results' : queryResults})
Exemple #12
0
def main():
    print("This is the demo for the recommender!")

    # because I don't have the keywords for'Office for Students with Disabilities'
    dummy_services = [
        'Peer Support Center', 'Therapist Assisted Online', 'Group Therapy',
        'PhD Support Group', 'Vent Over Tea', '7 Cups',
        'McGill Student\'s Nightline', 'Project 10 Listening Line',
        'SACOMSS Support Group', 'The Buddy Programm'
    ]
    # shall be the review csv file, use the dummy one I created for testing
    review_database = REVIEW_DATABASE
    # points to the folder containing the keywords for each service
    service_folder = SERVICE_KEYWORD_FOLDER

    # init the recommender
    rr = recommender.recommender(n_service=10,
                                 service_list=dummy_services,
                                 n_fixed_feature=4,
                                 top_k=TOP_K,
                                 cut_off=CUTOFF,
                                 review_file=review_database,
                                 service_kw_folder=service_folder,
                                 n_keyword=7,
                                 learning_rate=0.0015)
    # randomly init weights!
    rr.init_weights()

    print("recommender model inited!")

    while (True):
        print("Key in user profile:\n")
        user_profile = dict()
        user_profile["ufeature1"] = input("Gender [f/m]:")
        user_profile["ufeature2"] = input("Language [fr/en]:")
        user_profile["ufeature3"] = input("Year of Study, e.g. U3:")
        user_profile["ufeature4"] = input("cultural background [ca/us/asian]:")

        print(user_profile)

        print(
            "Preset user's goal: I want spend time talking iwth someone. I need advice."
        )
        user_goal = [['time', 0.5], ['talk', 0.5], ['friendly', 0.5],
                     ['advice', 0.5]]
        print(
            "Preset user's rating: I want spend time talking iwth someone. I need advice."
        )
        user_rating = {
            'Group Therapy': (3, 5),
            'Vent Over Tea': (5, 5),
            '7 Cups': (4, 5)
        }

        # get the service index of top_k choices, start from 0
        choices, service_names = rr.get_recommendation(user_profile,
                                                       user_goal,
                                                       verbose=False)
        # print("returned indices (start from 0): {}".format(choices))
        choices_for_chatbot = [c + 1 for c in choices]
        print(
            "service indicies (start from 1): {}".format(choices_for_chatbot))
        print("returned names:{}".format(service_names))

        # update the weights (ML-ish learning)
        user_scores = rr.process_user_rating(user_rating)
        rr.update_weights(user_profile, user_scores, choices, verbose=False)
from parsing_text import parse_train
from parse_test import parse_test
from recommender2 import recommender2
from reco import reco
from recommender import recommender
from recommender_item import recommender_item
from output import output


user_train,movie_train=parse_train('train.txt')
user_test5=parse_test('test5.txt')
user_test10=parse_test('test10.txt')
user_test20=parse_test('test20.txt')
user_test1=parse_test('test1.txt')
k=4
reco_dict=recommender(user_train,user_test20,movie_train,k)
#reco_dict1=recommender(user_train,user_test20,movie_train,k)
#reco_dict2=recommender2(user_train,user_test20,movie_train,k)
#reco_dict=reco(reco_dict1,reco_dict2)
#reco_item=recommender_item(user_train,user_test20,movie_train,k)
output(reco_dict,'test20.txt','result20.txt')
#output(reco_item,'test20.txt','result20.txt')
Exemple #14
0
import psycopg2 as pg
import os
from recommender import recommender

# get heroku database URL
DATABASE_URL = os.environ['DATABASE_URL']

# Postgres connection
sql_conn = pg.connect(DATABASE_URL, sslmode='require')

# create recommender
my_recommender = recommender(sql_conn)
Exemple #15
0
import preprocessing
import recommender

## dev
target_users_list, users, metadata, magazine, read, read_each_article = preprocessing.data_preprocessing(
    'dev')
recommed = recommender.recommender(target_users_list, './recommend.txt')

## test
#target_users_list, users, metadata, magazine, read, read_each_article = data_preprocessing('test')
#recommed = recommender(target_users_list, './recommend.txt')
def main(movieId):
    reco = recommender(movieId=movieId, recommendationsNumber=3)
    return reco
			movie.append(row[0])
			i = 0
			for rating in row:
				if i > 0:
					if rating != '':
						users[i].ratings[row[0]] = float(rating)
				i=i+1
# convert list of User objects to dictionary of user ratings - {'name' : {'movie' : 0-5, 'movie2' : 0-5 ... 'movie_n' : 0-5}}

userDict = {}

for user in users:
	userDict[user.name] = user.ratings

#
r = recommender(userDict)

#print('movie list', movie)

#use movie list to populate recommender.productid2name dictionary - {'film name' : 'film name'}
for film in movie:
	r.productid2name[film] = film

#use user User list to populate recommender.username2id and recommender.userid2name = {'name' : 'name'}
for user in users:
	r.username2id[user.name] = user.name
	r.userid2name[user.name] = user.name
#print(r.productid2name)

#here, for recommender.recommend and recommend.userRatings to function,
# userID and productId lists need to be constructed if they are to utilize the 
Exemple #18
0
#!/usr/bin/python3
from flask import Flask, request, jsonify, render_template
from flask_restful import Resource, Api
from json import dumps

from movielens import *

app = Flask(__name__)
api = Api(app)

from recommender import recommender
r = recommender({})
r.loadmovieDB()

user = []
item = []
d = Dataset()
d.load_users("data/u.user", user)
d.load_items("data/u.item", item)
# print(item[0])


class Users(Resource):
    def get(self):
        return jsonify({'users': [i for i in range(1,1683)]})

class UsersDetail(Resource):
    def get(self,user_id):
        result = user[int(user_id)-1]
        result_dict = {'id':result.id, 'age':result.age, 'sex':result.sex, 'occupation':result.occupation}    #avg_r to be added  
        return jsonify(result_dict) 
Exemple #19
0
uri = '4HJ7mSMtHAdU55lLjGE4zW'

# uri = '17kv7O2z3dLHW0LnXaU5Pn'

# uri = '0SuFqlCe5i30Fr75ZlPQVT'

# genre = 'popindie'

genre = input('Enter a genre: ')

num_tracks = 15

### CALL RECOMMENDER

playlist = r.recommender(uri, genre, num_tracks)

# r.create_playlist_file(playlist['track_id'])

print(playlist)

# results = r.pop_track_reccommender(df, track)
# ## SELECT TOP NUMBER
# rec_tracks = r.top_recommended_tracks(results, 15)

# print(r.display_playlist(rec_tracks['track_id']))

# playlist_file = open('playlist.txt', 'r+')
# playlist = playlist_file.read().splitlines()

# ## create playlist
Exemple #20
0
import recommender

rec_unit = recommender.recommender()

for uid in range(100):
    print(uid)
    res = rec_unit.predict([[uid]], 'feature_name')
    print(res)
Exemple #21
0
    "Enter movie names and rating (both likes and dislikes) in the side panel to build your profile."
)
st.write("")
st.write("")
st.write("")

st.sidebar.markdown("")

userLikes = []
n = st.sidebar.number_input("How many movies do you want to enter?", value=0)
i = 0
while i < n:
    movies = {}
    movie = st.sidebar.text_input("Movie Title", key=i)
    rating = st.sidebar.slider("Rating", min_value=0.01, max_value=5.01, key=i)
    movies["title"] = movie.lower()
    movies["rating"] = rating
    userLikes.append(movies)
    i += 1

st.sidebar.markdown("")
st.sidebar.markdown("")
year = st.sidebar.text_input(
    "Do you want movies after a specific year, if yes, mention the year?",
    value=1900)
noOfMovies = st.sidebar.number_input("How many movies do you want?", value=10)

if st.sidebar.button("Press for Recommendations", key=1):
    recommended = recommender(userLikes, year, noOfMovies)
    st.write(recommended)
Exemple #22
0
import recommender

if __name__=='__main__':

	dictPath='prediction_dict.pkl'
	n=10
	rc=recommender.recommender(dictPath,n)
	rc.train()
	print('train.py complete')
Exemple #23
0
def recommend():  #controller function
    df = load_data()
    recc = r.recommender()
    song = song_in(df)
    recs = recc.recommend(data=df, song=song)
    printresults(song, recs)
    def start_gui(self):
        #start mouse and keyboard listeners
        self.keyboard_listener.start()
        self.mouse_listener.start()
        #######this blocks dont use########
        #self.keyboard_listener.join()
        #self.mouseListener.join()
        ###################################

        in_text=""
        out_text=""
        extra=""

        while True:
            event, values = self.window.read()

            if event=='in':
                print()

            if event=='out':
                out_text=values['out']

            if event=='extra':
                extra=values['extra']

            if event == "_grab_" and self.grab_area_isSet()==True:
                img=ImageGrab.grab(bbox=(int(self.window['mouse_x_start'].get()),int(self.window['mouse_y_start'].get()),int(self.window['mouse_x_end'].get()),int(self.window['mouse_y_end'].get())),include_layered_windows=True,all_screens=True)
                #img.show()
                img.save(self.img_path)
                self.window['_image_'].update(filename= self.img_path)
                #print("grab")
                img_dealer=img=ImageGrab.grab(bbox=(int(self.window['mouse_x_start'].get()),int(self.window['mouse_y_start'].get()),int(self.window['mouse_x_end'].get()),int(self.window['mouse_y_start'].get())+(int(self.window['mouse_y_end'].get())-int(self.window['mouse_y_start'].get()))/2),include_layered_windows=True,all_screens=True)
                img_dealer.save(self.img_dealer_path)
                img_player=img=ImageGrab.grab(bbox=(int(self.window['mouse_x_start'].get()),int(self.window['mouse_y_start'].get())+(int(self.window['mouse_y_end'].get())-int(self.window['mouse_y_start'].get()))/2,int(self.window['mouse_x_end'].get()),int(self.window['mouse_y_end'].get())),include_layered_windows=True,all_screens=True)
                img_player.save(self.img_player_path)
                #img_dealer.show()
                #img_player.show()


            if event=='_calc_':
                #send to model                
                img=Image.open( self.img_path).convert("RGB")
                img_dealer=Image.open( self.img_dealer_path).convert("RGB")
                img_player=Image.open(self.img_player_path).convert("RGB")
                

                #img=(read_image('data\grab1.png')).float()
                a = transforms.Compose([transforms.ToTensor(),transforms.Normalize(mean=[0.485, 0.456, 0.406],std=[0.229, 0.224, 0.225] )])
                img=a(img)

                img_dealer=Image.open(self.img_dealer_path).convert("RGB")
                img_dealer=a(img_dealer)
                img_player=Image.open(self.img_player_path).convert("RGB")
                img_player=a(img_player)   


                #predictions = self.model([img])
                predictions_dealer = self.model([img_dealer])
                predictions_player = self.model([img_player])
                

                #pred_boxes=predictions[0]['boxes'].detach().numpy()
                #pred_labels=predictions[0]['labels'].detach().numpy()
                #pred_scores=predictions[0]['scores'].detach().numpy()
                half_image=(int(self.window['mouse_y_end'].get())-int(self.window['mouse_y_start'].get()))/2
                #print('half image:',half_image)


                dealer_pred_boxes=predictions_dealer[0]['boxes'].detach().numpy()
                dealer_pred_labels=predictions_dealer[0]['labels'].detach().numpy()
                dealer_pred_scores=list(predictions_dealer[0]['scores'].detach().numpy())
                player_pred_boxes=predictions_player[0]['boxes'].detach().numpy()
                player_pred_labels=predictions_player[0]['labels'].detach().numpy()
                player_pred_scores=predictions_player[0]['scores'].detach().numpy()

                out_img=Image.open( self.img_path)
                draw=ImageDraw.Draw(out_img)

                #for i in range(0,len(pred_scores)):
                #    if pred_boxes[i][1]< half_image and pred_boxes[i][3]<half_image:
                #        #dealers
                #         dealer_pred_boxes.append(pred_boxes[i])
                    #     draw.rectangle([(pred_boxes[i][0],pred_boxes[i][1]),(pred_boxes[i][2],pred_boxes[i][3])],outline='red',width=2)
                    #     dealer_pred_labels.append(pred_labels[i])
                    #     dealer_pred_scores.append(pred_scores[i])
                    # elif pred_boxes[i][1]> half_image and pred_boxes[i][3]>half_image:
                    #     #players
                    #     player_pred_boxes.append(pred_boxes[i])
                    #     draw.rectangle([(pred_boxes[i][0],pred_boxes[i][1]),(pred_boxes[i][2],pred_boxes[i][3])],outline='black',width=2)
                    #     player_pred_labels.append(pred_labels[i])
                    #     player_pred_scores.append(pred_scores[i])

                for i in range(0,len(dealer_pred_scores)):
                    draw.rectangle([(dealer_pred_boxes[i][0],dealer_pred_boxes[i][1]),(dealer_pred_boxes[i][2],dealer_pred_boxes[i][3])],outline='red',width=1)

                for i in range(0,len(player_pred_scores)):
                    draw.rectangle([(player_pred_boxes[i][0],half_image+player_pred_boxes[i][1]),(player_pred_boxes[i][2],half_image+player_pred_boxes[i][3])],outline='black',width=1)


                player_pred_labels=list(set(player_pred_labels))
                print(player_pred_labels)

                out_img.save( self.img_path)
                self.window['_image_'].update(filename= self.img_path)
                print('dealer:')
                print(dealer_pred_boxes)
                print(dealer_pred_labels)
                print(dealer_pred_scores)
                print('player:')
                print(player_pred_boxes)
                print(player_pred_labels)
                print(player_pred_scores)
                self.list=[]
                self.window['_list_'].update(self.list)
                
                

                dealer_sum=(dealer_pred_labels[dealer_pred_scores.index(max(dealer_pred_scores))] if len(dealer_pred_scores)>0  else -1) if (dealer_pred_labels[dealer_pred_scores.index(max(dealer_pred_scores))] if len(dealer_pred_scores)>0  else -1) <10 else 10
            
                n=int(self.window['in'].get() if self.window['in'].get() !='' else 2 )
                print('nbr of cards:',n)
                player_sum=0
                player_cards=[]
                for i,j in zip(range(0,n), range(0,len(player_pred_labels))):
                
                    player_sum=player_sum+(player_pred_labels[i] if player_pred_labels[i] <10 else 10)
                    player_cards.append(player_pred_labels[i])
                    print(player_sum)

                self.list.append(('dealer sum:',  dealer_sum ))
                self.list.append(('dealer card:',  (dealer_pred_labels[dealer_pred_scores.index(max(dealer_pred_scores))] if len(dealer_pred_scores)>0  else -1)))
                self.window['_list_'].update(self.list)
                self.list.append(('player sum:',player_sum))
                self.list.append(('player cards:',player_cards))
                self.window['_list_'].update(self.list)

                if player_sum <21 and dealer_sum !=-1 and player_sum:
                    #send to recommender system
                    recommendation = recommender.recommender(a=0,p=player_sum,d=dealer_sum) 
                    #make a decision
                    if recommendation.thorpe()==0:
                        self.list.append(('recommendation: STAND'))
                        self.window['_list_'].update(self.list)
                        #self.click_stand()
                    elif recommendation.thorpe()==1:
                        self.list.append(('recommendation: HIT'))
                        self.window['_list_'].update(self.list)
                        #self.click_hit()
                    elif recommendation.thorpe()==2:
                        self.list.append(('recommendation: DOUBLE'))
                        self.window['_list_'].update(self.list)
                        #self.click_double()
                else:
                    self.list.append(('!!! BUST !!!!'))
                    self.window['_list_'].update(self.list)

                


            if event=='_remove_':
                if len(values['_list_'])>0:
                    self.list.remove(in_text+';'+out_text+';'+extra)
                    self.window['_list_'].update(self.list)

            if event=='_list_':
                
                if len(values['_list_'])>1:
                    list_item_split=values['_list_'][0].strip().split(';')
                    self.window['in'].update(list_item_split[0])
                    in_text=values['in']
                    self.window['out'].update(list_item_split[1])
                    out_text=values['out']
                    self.window['extra'].update(list_item_split[2])
                    extra=values['extra']


            if event == sg.WIN_CLOSED:
                break
Exemple #25
0
         "Chan": {"Blues Traveler": 5.0, "Broken Bells": 1.0,
                  "Deadmau5": 1.0, "Norah Jones": 3.0, "Phoenix": 5,
                  "Slightly Stoopid": 1.0},
         
         "Dan": {"Blues Traveler": 3.0, "Broken Bells": 4.0,
                 "Deadmau5": 4.5, "Phoenix": 3.0,
                 "Slightly Stoopid": 4.5, "The Strokes": 4.0,
                 "Vampire Weekend": 2.0},
         
         "Hailey": {"Broken Bells": 4.0, "Deadmau5": 1.0,
                    "Norah Jones": 4.0, "The Strokes": 4.0,
                    "Vampire Weekend": 1.0},
         
         "Jordyn":  {"Broken Bells": 4.5, "Deadmau5": 4.0,
                     "Norah Jones": 5.0, "Phoenix": 5.0,
                     "Slightly Stoopid": 4.5, "The Strokes": 4.0,
                     "Vampire Weekend": 4.0},
         
         "Sam": {"Blues Traveler": 5.0, "Broken Bells": 2.0,
                 "Norah Jones": 3.0, "Phoenix": 5.0,
                 "Slightly Stoopid": 4.0, "The Strokes": 5.0},
         
         "Veronica": {"Blues Traveler": 3.0, "Norah Jones": 5.0,
                      "Phoenix": 4.0, "Slightly Stoopid": 2.5,
                      "The Strokes": 3.0}
        }
r = recommender.recommender(users)
#print "hello"
#r.loadBookDB('/home/abhiroop/Downloads/WISHLIST/BX-Dump/') 
#print r.recommend('171118') 
print r.recommend('Jordyn') 
def receive_data(idSession):
    if request.method == "POST":
        try:
            if verify_active_session(idSession) == False:
                create_session(idSession)
            idUser = request.form["idUser"]
            event = request.form["tipo"]
            resource = request.form["tag"]
            timestamp = request.form["timeStamp"]
            x = request.form["x"]
            y = request.form["y"]
            #idView = request.form["id"]
            tela = request.form["tela"]
            adaptacao = request.form["adaptacao"]
            idView = request.form["classId"]
            #print tela

            if x == "" and y == "" and resource == "":
                #Neste bloco está sendo atualizado a última linha que significa o timestamp e a tela atual passado pelo Player
                with open(
                        "sessions-Logs/" + idSession + "/" + idUser +
                        "_log.csv", "a+") as f:
                    lines = f.readlines()
                    if len(lines) > 0:
                        lineOld = lines[-1]  #pega ultima linha
                        lineNew = idSession + ";" + idUser + ";" + timestamp + ";" + event + ";" + tela + ";" + idView + ";" + resource + ";" + x + ";" + y + "\n"
                        f.close()

                        fileaux = open(
                            "sessions-Logs/" + idSession + "/" + idUser +
                            "_log.csv", 'r')
                        filedata = fileaux.read()
                        fileaux.close()

                        newdata = filedata.replace(lineOld, lineNew)

                        fileaux = open(
                            "sessions-Logs/" + idSession + "/" + idUser +
                            "_log.csv", 'w')
                        fileaux.write(newdata)
                        fileaux.close()
                    else:
                        newdata = idSession + ";" + idUser + ";" + timestamp + ";" + event + ";" + tela + ";" + idView + ";" + resource + ";" + x + ";" + y + "\n"
                        fileaux = open(
                            "sessions-Logs/" + idSession + "/" + idUser +
                            "_log.csv", 'w')
                        fileaux.write(newdata)
                        fileaux.close()

            else:
                with open(
                        "sessions-Logs/" + idSession + "/" + idUser +
                        "_log.csv", "a+") as f:
                    lines = f.readlines()
                    lineOld = lines[-1]  #pega ultima linha
                    f.close()
                    #print lines

                    fileaux = open(
                        "sessions-Logs/" + idSession + "/" + idUser +
                        "_log.csv", 'r')
                    filedata = fileaux.read()
                    fileaux.close()

                    lineNew = idSession + ";" + idUser + ";" + timestamp + ";" + event + ";" + tela + ";" + idView + ";" + resource + ";" + x + ";" + y + "\n"
                    newdata = filedata.replace(lineOld, lineNew)
                    newdata = newdata + lineOld
                    #print newdata
                    fileaux = open(
                        "sessions-Logs/" + idSession + "/" + idUser +
                        "_log.csv", 'w')
                    fileaux.write(newdata)
                    fileaux.close()

            #data_received =	idSession+";"+idUser+";"+timestamp+";"+event +";"+idView+";"+resource+";"+x+";"+y+"\n"
            #fileBuffer = open("sessions-Logs/"+idSession+"/"+idUser+"_log.csv", "a")
            #fileBuffer.write(data_received)
            #fileBuffer.close()

            print idSession + ";" + idUser + ";" + timestamp + ";" + event + ";" + tela + ";" + idView + ";" + resource + ";" + x + ";" + y
            print ""
            dt = datetime.now()
            strTimeDate = str(dt.day) + "/" + str(dt.month) + "/" + str(
                dt.year
            ) + "-" + str(dt.hour) + ":" + str(dt.minute) + ":" + str(
                dt.second
            ) + "-" + idUser + ";" + timestamp + ";" + event + ";" + tela + ";" + idView + ";" + resource + ";" + x + ";" + y + "\n"
            logService = open("SERVICE_log.csv", "a+")
            logService.write(strTimeDate)
            logService.close()
            #print "btn Storage" + btnTroca[0]
            #Solicita recomendacao caso o aluno estiver em uma questao
            try:
                if idView != "" and (
                        idView == "troca-Q1 btn btn-info btn-lg"
                        or idView == "troca-Q2 btn btn-info btn-lg"
                        or idView == "troca-Q3 btn btn-info btn-lg"
                        or idView == "troca-Q4 btn btn-info btn-lg"
                        or idView == "troca-Q5 btn btn-info btn-lg"
                        or idView == "troca-Q6 btn btn-info btn-lg"
                        or idView == "troca-Q7 btn btn-info btn-lg"
                        or idView == "troca-Q8 btn btn-info btn-lg"
                        or idView == "troca-Q9 btn btn-info btn-lg"
                        or idView == "troca-Q10 btn btn-info btn-lg"):
                    #btnTroca[0] = "1"
                    print "IDVIEW: " + idView
                    auxIdView = idView.split(" ")
                    aux = auxIdView[0]
                    print "aux" + aux
                    i = aux.find("Q")
                    print "AUX: " + aux[i + 1:]
                    changeBtnQuestionEasy(idUser, recomendation,
                                          int(aux[i + 1:]), int(timestamp))
                    #print "AQUI BTN"
                #print "aquiii"
                #print sumario

                if idView != "" and adaptacao == "1" and (
                        idView == "R:1:E:1-1 btn btn-info btn-lg"
                        or idView == "R:2:E:1-1 btn btn-info btn-lg"
                        or idView == "R:3:E:1-1 btn btn-info btn-lg"
                        or idView == "R:4:E:1-1 btn btn-info btn-lg"
                        or idView == "R:5:E:1-1 btn btn-info btn-lg"
                        or idView == "R:6:E:1-1 btn btn-info btn-lg"
                        or idView == "R:7:E:1-1 btn btn-info btn-lg"
                        or idView == "R:8:E:1-2 btn btn-info btn-lg"
                        or idView == "R:9:E:1-2 btn btn-info btn-lg"
                        or idView == "R:10:E:1-2 btn btn-info btn-lg"):
                    #btnTroca[0] = "1"
                    print "IDVIEW: " + idView
                    auxIdView = idView.split(":")
                    aux = auxIdView[1]
                    print "aux: " + aux

                    answerBtnQuestionEasy(idUser, recomendation, int(aux),
                                          int(timestamp))
                    #idViewSplit = idView.split(":")
                    #print idViewSplit
                    #updateQuestionsTime(idUser, timestamp, idView)
                    #print "aqui1"
                    #print "idview: " + idView
                    idQuestion = idView.split(":")
                    idQuestion[0] = "Q"
                    #print "aqui2"
                    feedback = []
                    feedback = recommender(idUser, recomendation,
                                           int(idQuestion[1]), int(timestamp))

                    print "Recomendação(SENT): " + feedback[1]
                    print "Questions (SENT): " + feedback[2]

                    dt = datetime.now()
                    strTimeDate = str(dt.day) + "/" + str(dt.month) + "/" + str(
                        dt.year
                    ) + "-" + str(dt.hour) + ":" + str(dt.minute) + ":" + str(
                        dt.second
                    ) + "-" + idUser + ";" + "Recomendacao(SENT): " + feedback[
                        1] + ";" + "Questions (SENT): " + feedback[2] + "\n"
                    #strTimeDate = "ok\n"
                    logService = open("SERVICE_log.csv", "a+")
                    logService.write(strTimeDate)
                    logService.close()

                    #Zerando sumario
                    sumarioFile = open("sumario.csv", "r")
                    dataSumario = sumarioFile.readlines()
                    sumarioAux = list()
                    for i in dataSumario:
                        sumarioAux.append(i[0:-1])
                    sumarioFile.close()

                    print "\nSUMARIO ANTES DE ZERAR CONTADOR"
                    print sumarioAux

                    sumario = ClearSummarizerByUser(idUser, event, timestamp,
                                                    idView, sumarioAux)

                    print "\nSUMARIO ZERANDO CONTADOR"
                    print sumario

                    sumarioAux = open("sumario.csv", "w")
                    sumarioAux.close

                    sumarioAux = open("sumario.csv", "a+")
                    for i in sumario:
                        sumarioAux.write(i + "\n")
                    sumarioAux.close

                    recommendation = [{
                        "recommendation": feedback[1]
                    }, {
                        "questions": feedback[2]
                    }]
                    #print "----Teste Recommendation OOOOOI------", recommendation
                    return jsonify({'recommendation': recommendation})

                if idView != "" and idView[0] == "Q" and adaptacao == "1":
                    idViewSplit = idView.split(":")
                    #print idViewSplit
                    #updateQuestionsTime(idUser, timestamp, idView)
                    feedback = searchAdaptation(idUser, timestamp, event,
                                                idView)
                    #print feedback
                    if len(feedback) > 0:
                        print "Recomendação(SENT): " + feedback[1]
                        print "Questions (SENT): " + feedback[2]

                        dt = datetime.now()
                        strTimeDate = str(dt.day) + "/" + str(
                            dt.month
                        ) + "/" + str(dt.year) + "-" + str(
                            dt.hour
                        ) + ":" + str(dt.minute) + ":" + str(
                            dt.second
                        ) + "-" + idUser + ";" + "Recomendacao(SENT): " + feedback[
                            1] + ";" + "Questions (SENT): " + feedback[2] + "\n"
                        #strTimeDate = "ok\n"
                        logService = open("SERVICE_log.csv", "a+")
                        logService.write(strTimeDate)
                        logService.close()

                        recommendation = [{
                            "recommendation": feedback[1]
                        }, {
                            "questions": feedback[2]
                        }]
                        #print "----Teste Recommendation OOOOOI------", recommendation
                        return jsonify({'recommendation': recommendation})
                    else:
                        #print "AQUI ELSE1"
                        recommendation = [{
                            "recommendation": "ok"
                        }, {
                            "questions": "nada"
                        }]
                        return jsonify({'recommendation': recommendation})
                else:
                    #idUser, event, timestamp, idView, sumarioL
                    #print "aqui2"
                    #global sumario
                    #print "aqui"
                    print "" + idUser + "/" + timestamp + "/" + event + "/" + idView + "/"
                    sumarioFile = open("sumario.csv", "r")
                    dataSumario = sumarioFile.readlines()
                    sumarioAux = list()
                    for i in dataSumario:
                        sumarioAux.append(i[0:-1])
                    sumarioFile.close()

                    print "\nSUMARIO ANTES DE ZERAR CONTADOR"
                    print sumarioAux

                    sumario = ClearSummarizerByUser(idUser, event, timestamp,
                                                    idView, sumarioAux)

                    print "\nSUMARIO ZERANDO CONTADOR"
                    print sumario

                    sumarioAux = open("sumario.csv", "w")
                    sumarioAux.close

                    sumarioAux = open("sumario.csv", "a+")
                    for i in sumario:
                        sumarioAux.write(i + "\n")
                    sumarioAux.close

                    recommendation = [{
                        "recommendation": "ok"
                    }, {
                        "questions": "nada"
                    }]
                    return jsonify({'recommendation': recommendation})
            except:
                print "Broken1"
                dt = datetime.now()
                strTimeDate = str(dt.day) + "/" + str(dt.month) + "/" + str(
                    dt.year) + "-" + str(dt.hour) + ":" + str(
                        dt.minute) + ":" + str(
                            dt.second) + "-" + idUser + ";" + "Broken1" + "\n"
                logService = open("SERVICE_log.csv", "a+")
                logService.write(strTimeDate)
                logService.close()
                pass

        except:
            print "Broken2"
            dt = datetime.now()
            strTimeDate = str(dt.day) + "/" + str(dt.month) + "/" + str(
                dt.year) + "-" + str(dt.hour) + ":" + str(
                    dt.minute) + ":" + str(
                        dt.second) + "-" + idUser + ";" + "Broken2" + "\n"
            logService = open("SERVICE_log.csv", "a+")
            logService.write(strTimeDate)
            logService.close()
            pass
Exemple #27
0
def app():

    ##### Set up data for modelling

    # import data to model CV against
    workpac_data = pd.read_csv('job_descriptions.csv')

    # remove id column as we can use index
    workpac_data = workpac_data[['job_link', 'job_description', 'job_title']]

    # clean Na's so functions can run
    workpac_data = workpac_data.replace(np.nan, ' ', regex=True)

    # clean job description
    workpac_data['job_description_cleaned'] = workpac_data[
        'job_description'].apply(_removeNonAscii)
    workpac_data[
        'job_description_cleaned'] = workpac_data.job_description_cleaned.apply(
            func=make_lower_case)
    workpac_data[
        'job_description_cleaned'] = workpac_data.job_description_cleaned.apply(
            func=remove_stop_words)
    workpac_data[
        'job_description_cleaned'] = workpac_data.job_description_cleaned.apply(
            func=remove_punctuation)
    workpac_data[
        'job_description_cleaned'] = workpac_data.job_description_cleaned.apply(
            func=remove_html)

    workpac_data['job_title_cleaned'] = workpac_data['job_title'].apply(
        _removeNonAscii)
    workpac_data['job_title_cleaned'] = workpac_data.job_title_cleaned.apply(
        func=make_lower_case)
    workpac_data['job_title_cleaned'] = workpac_data.job_title_cleaned.apply(
        func=remove_stop_words)
    workpac_data['job_title_cleaned'] = workpac_data.job_title_cleaned.apply(
        func=remove_punctuation)
    workpac_data['job_title_cleaned'] = workpac_data.job_title_cleaned.apply(
        func=remove_html)

    # stem cleaned data
    workpac_data['job_description_cleaned'] = workpac_data[
        'job_description_cleaned'].apply(stem_sentences)
    workpac_data['job_title_cleaned'] = workpac_data[
        'job_title_cleaned'].apply(stem_sentences)

    workpac_data['job_text_cleaned'] = workpac_data[
        'job_title_cleaned'] + ' ' + workpac_data['job_description_cleaned']

    model_df = workpac_data[['job_link', 'job_text_cleaned']]

    # title of streamlit app
    st.title(
        'Candidate Job Ranking System Using Natural Language Processing (NLP)')

    # sidebar
    st.subheader('Files')

    # file uploader
    uploaded_file = st.file_uploader(label='Please upload your CV',
                                     type=['docx'])

    # create message variable
    message = ''
    doc = ''

    if uploaded_file is not None:
        try:
            doc = docx2python(uploaded_file).text
            message = 'File upload successful'
        except Exception as e:
            message = 'There was an error uploading your file'

    # display success/failure message

    st.text(message)

    # display uploaded file (text only as the method used in docx2python is .text)

    try:
        st.text(doc)
    except Exception as e:
        print(e)
        st.write('Please upload CV')

    if doc != '':
        # call recommender function
        recommended_jobs = recommender(model_df, doc)

        # create output dataframe
        recommended_jobs = pd.merge(left=recommended_jobs,
                                    right=workpac_data,
                                    left_on='job_link',
                                    right_on='job_link')

        # summarise output
        recommender_summary = recommended_jobs[['job_title', 'job_link']]

        # display output

        fig = go.Figure(data=[
            go.Table(header=dict(values=list(recommender_summary.columns),
                                 fill_color='paleturquoise',
                                 align='left'),
                     cells=dict(values=[
                         recommender_summary.job_title,
                         recommender_summary.job_link
                     ],
                                fill_color='lavender',
                                align='left'))
        ])

        st.write(fig)
Exemple #28
0
        "Vampire Weekend": 1.0
    },
    "Jordyn": {
        "Broken Bells": 4.5,
        "Deadmau5": 4.0,
        "Norah Jones": 5.0,
        "Phoenix": 5.0,
        "Slightly Stoopid": 4.5,
        "The Strokes": 4.0,
        "Vampire Weekend": 4.0
    },
    "Sam": {
        "Blues Traveler": 5.0,
        "Broken Bells": 2.0,
        "Norah Jones": 3.0,
        "Phoenix": 5.0,
        "Slightly Stoopid": 4.0,
        "The Strokes": 5.0
    },
    "Veronica": {
        "Blues Traveler": 3.0,
        "Norah Jones": 5.0,
        "Phoenix": 4.0,
        "Slightly Stoopid": 2.5,
        "The Strokes": 3.0
    }
}

r = recommender.recommender(users)
print(r.recommend("Hailey"))
Exemple #29
0
    def generateHot(self):
        after = self.request.args.get('after')
        if after is None:
            print 'no after'
            msg = None
            if g.user:
                print 'we have a user'
                msg = Database.query(
                    '''select image from Uploads ul 
                        where (select score from imagescores where image=ul.image) > ? 
                        and ul.image not in (select image from likes where userid=?)
                        order by (select score from imagescores where image=ul.image) desc 
                        limit ?''', [
                        config.get('hotFloor'), session['userid'],
                        config.get('perPage')
                    ])
                print[f['image'] for f in msg], 'IMAGES'
            else:
                print 'no user'
                msg = Database.query(
                    '''select image from Uploads ul 
                        where (select score from imagescores where image=ul.image) > ? 
                        order by (select score from imagescores where image=ul.image) desc 
                        limit ?''',
                    [config.get('hotFloor'),
                     config.get('perPage')])

            hot = [image(f['image']) for f in msg]
            print 'hot: ', hot
            recs = []
            if g.user:
                rc = recommender(session['userid'])
                recs = rc.getRecommendations()
                print 'recs ', recs

            ret = self.__createFeed(hot, recs)
            print 'final: ', ret

            return ret

        print "we found an after parameter, and it is", after

        score = Database.query('select score from imagescores where image=?',
                               [after],
                               one=True)['score']

        msg = None
        if g.user:
            msg = Database.query(
                '''select image from uploads ul 
                        where (select score from imagescores where image=ul.image) < ? 
                        and (select score from imagescores where image=ul.image) > ? and
                        ul.image not in (select image from likes where userid=?)
                        order by (select score from imagescores where image=ul.image) desc 
                        limit ?''', [
                    score,
                    config.get('hotFloor'), session['userid'],
                    config.get('perPage')
                ])
        else:
            msg = Database.query(
                '''select image from uploads ul 
                        where (select score from imagescores where image=ul.image) < ? 
                        and (select score from imagescores where image=ul.image) > ? 
                        order by (select score from imagescores where image=ul.image) desc 
                        limit ?''',
                [score, config.get('hotFloor'),
                 config.get('perPage')])

        hot = [image(f['image']) for f in msg]
        print 'hot: ', hot
        recs = []
        if g.user:
            rc = recommender(session['userid'])
            recs = rc.getRecommendations()
            print 'recs ', recs

        ret = self.__createFeed(hot, recs)
        print 'final: ', ret
        return ret
Exemple #30
0
import random
import os
import recommender as rc

users=2100
rcTemp=rc.recommender()

testCase=1

for i in range(testCase):

	uid_random=random.randint(1,users)
	X=[[uid_random]]
	results=rcTemp.predict(X,'featureName')
	
	print('USER ID [%d]' %uid_random)
	print(results)