Skip to content

Commit a7b55ae

Browse files
committed
fix and updated files
1 parent cbc8426 commit a7b55ae

File tree

7 files changed

+85
-40
lines changed

7 files changed

+85
-40
lines changed

engine/data/items.csv

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
16,La Super Pizza da Franco,Bari,0,0,1,0,0,0,0,0,0,0,0
1414
17,Capolinea Cafe,Ceglie Messapica,0,0,1,0,0,0,0,1,0,0,0
1515
18,Falsopepe,Massafra,0,1,1,0,0,0,0,0,0,0,0
16-
20,Gaonas Officine del Gusto ,Martina Franca,0,0,1,0,0,0,0,1,0,0,0
17-
21,Miseria e Nobiltà,Alberobello,0,1,1,0,0,0,0,0,0,0,0
16+
20,Gaonas Officine del Gusto,Martina Franca,0,0,1,0,0,0,0,1,0,0,0
17+
21,Miseria e Nobilta,Alberobello,0,1,1,0,0,0,0,0,0,0,0
1818
22,Le Arcure,Lecce,0,0,1,0,0,0,0,0,0,0,0
1919
23,Remix Fruttabar,Cisternino,0,1,0,0,0,0,0,0,0,0,0
2020
24,Terrazze Belvedere,Conversano,0,1,1,0,0,0,0,0,0,0,0
@@ -3304,7 +3304,7 @@
33043304
5109,Parco Multimedia,Brindisi,0,0,0,0,0,0,0,0,1,0,0
33053305
5111,Parco Naturale Regionale delle Dune Costiere,Ostuni,0,0,0,0,0,0,0,0,1,1,0
33063306
5112,Cantieri Maggese,Taranto,0,0,0,0,0,0,1,0,0,0,0
3307-
5113,Laboratorio Urbano TheFactory ,Palagiano,0,0,0,0,0,0,0,0,0,0,1
3307+
5113,Laboratorio Urbano TheFactory,Palagiano,0,0,0,0,0,0,0,0,0,0,1
33083308
5116,Piazza Galtieri,Adelfia,0,0,0,0,0,0,0,0,1,0,0
33093309
5117,Le Segrete,Adelfia,0,1,0,0,0,0,1,0,0,0,0
33103310
5118,Auditorium Centro Anziani,Zollino,0,0,0,0,0,0,0,0,0,0,1

engine/data/model_checkpoint.pickle

-1 Bytes
Binary file not shown.

engine/data/ratings_train.csv

+18-18
Original file line numberDiff line numberDiff line change
@@ -2398,21 +2398,21 @@
23982398
10032,757,2
23992399
10032,760,2
24002400
10032,783,1
2401-
10321,83,3
2402-
10321,84,3
2403-
10321,85,3
2404-
10322,80,3
2405-
10322,81,3
2406-
10322,82,3
2407-
10311,89,3
2408-
10311,90,3
2409-
10311,91,3
2410-
10312,86,3
2411-
10312,87,3
2412-
10312,88,3
2413-
10331,95,3
2414-
10331,96,3
2415-
10331,97,3
2416-
10332,92,3
2417-
10332,93,3
2418-
10332,94,3
2401+
10321,4802,3
2402+
10321,6966,3
2403+
10321,1936,3
2404+
10322,6175,3
2405+
10322,2530,3
2406+
10322,5602,3
2407+
10311,3065,3
2408+
10311,3060,3
2409+
10311,4639,3
2410+
10312,6629,3
2411+
10312,4901,3
2412+
10312,8363,3
2413+
10331,4720,3
2414+
10331,3947,3
2415+
10331,1248,3
2416+
10332,2400,3
2417+
10332,6792,3
2418+
10332,8237,3

engine/data/users.csv

+7-7
Original file line numberDiff line numberDiff line change
@@ -597,10 +597,10 @@
597597
10021,Adelfia,0,3,5,3,5,3,0,2,0,1
598598
10022,Adelfia,0,3,5,3,5,3,0,2,0,1
599599
10031,Adelfia,0,3,5,3,5,3,0,2,0,1
600-
10032,Adelfia,0,3,5,3,5,3,0,2,0,1
601-
10321,Santeramo in Colle,0,0,0,0,0,0,0,0,0,0
602-
10322,Santeramo in Colle,0,0,0,0,0,0,0,0,0,0
603-
10311,Santeramo in Colle,0,0,0,0,0,0,0,0,0,0
604-
10312,Santeramo in Colle,0,0,0,0,0,0,0,0,0,0
605-
10331,Santeramo in Colle,0,0,0,0,0,0,0,0,0,0
606-
10332,Santeramo in Colle,0,0,0,0,0,0,0,0,0,0
600+
10032,Adelfia,0,3,5,3,5,3,0,2,0,1
601+
10321,Santeramo in Colle,0,0,0,0,0,0,0,0,0,0
602+
10322,Santeramo in Colle,0,0,0,0,0,0,0,0,0,0
603+
10311,Santeramo in Colle,0,0,0,0,0,0,0,0,0,0
604+
10312,Santeramo in Colle,0,0,0,0,0,0,0,0,0,0
605+
10331,Santeramo in Colle,0,0,0,0,0,0,0,0,0,0
606+
10332,Santeramo in Colle,0,0,0,0,0,0,0,0,0,0

pugliaeventi/settings.py

+12-10
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727

2828
ALLOWED_HOSTS = []
2929

30+
CORS_ORIGIN_ALLOW_ALL = True
31+
CORS_ALLOW_CREDENTIALS = True
3032

3133
# Application definition
3234

@@ -48,25 +50,25 @@
4850
CRISPY_TEMPLATE_PACK = 'bootstrap4'
4951

5052
MIDDLEWARE = [
53+
'corsheaders.middleware.CorsMiddleware',
54+
'django.middleware.common.CommonMiddleware',
5155
'django.middleware.security.SecurityMiddleware',
5256
'django.contrib.sessions.middleware.SessionMiddleware',
5357
'django.middleware.common.CommonMiddleware',
5458
'django.middleware.csrf.CsrfViewMiddleware',
5559
'django.contrib.auth.middleware.AuthenticationMiddleware',
5660
'django.contrib.messages.middleware.MessageMiddleware',
5761
'django.middleware.clickjacking.XFrameOptionsMiddleware',
58-
'corsheaders.middleware.CorsMiddleware',
59-
'django.middleware.common.CommonMiddleware',
6062
]
6163

62-
CORS_ORIGIN_ALLOW_ALL = True
63-
CORS_ALLOW_CREDENTIALS = True
64-
CORS_ORIGIN_WHITELIST = (
65-
'localhost:8080',
66-
)
67-
CORS_ORIGIN_REGEX_WHITELIST = (
68-
'localhost:8080',
69-
)
64+
65+
#CORS_ALLOW_CREDENTIALS = True
66+
#CORS_ORIGIN_WHITELIST = (
67+
# 'localhost:8080',
68+
#)
69+
#CORS_ORIGIN_REGEX_WHITELIST = (
70+
# 'localhost:8080',
71+
#)
7072

7173
ROOT_URLCONF = 'pugliaeventi.urls'
7274

recommender_webapp/common/data_loader.py

+35-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from recommender_webapp.common import constant
2-
from recommender_webapp.models import Place
2+
from api.models import Place
3+
#from recommender_webapp.models import Place
34

45

56
class DataLoader:
@@ -9,10 +10,13 @@ def __init__(self):
910
self.__load_data_from_db()
1011

1112
def __load_data_from_db(self):
13+
print ("+++++ dataloader.load_data_from_db()")
14+
i = 0
1215
for place in Place.objects.all():
1316
self.data_in_memory['places_dict'][place.placeId] = place
1417
self.data_in_memory['places_list'].append(place)
1518

19+
1620
if place.freeEntry:
1721
self.data_in_memory['place_feature'][constant.FREE_ENTRY] = place
1822
if place.teatro:
@@ -35,3 +39,33 @@ def __load_data_from_db(self):
3539
self.data_in_memory['place_feature'][constant.GOLOSO] = place
3640
if place.libri:
3741
self.data_in_memory['place_feature'][constant.LIBRI] = place
42+
43+
'''print ("LIBRI\n")
44+
print(str(self.data_in_memory['place_feature'][constant.LIBRI]) + "\n")
45+
print ("DORMIRE\n")
46+
print(str(self.data_in_memory['place_feature'][constant.DORMIRE]) + "\n")
47+
print ("MUSEO\n")
48+
print(str(self.data_in_memory['place_feature'][constant.MUSEO]) + "\n")
49+
print(str(i))
50+
print(str(self.data_in_memory['place_feature']))
51+
#print(str(len(self.data_in_memory)))
52+
#break
53+
#print(self.data_in_memory)
54+
55+
data = {'a': {}, 'b': [], 'c': {}}
56+
data['a'][3] = "x1"
57+
data['b'].append("x1")
58+
data['c']['c3'] = "x1"
59+
data['a'][1] = "x2"
60+
data['b'].append("x2")
61+
data['c']['c1'].append("x2")
62+
data['c']['c1'].append("x3")
63+
64+
65+
66+
print(data['a'])
67+
print(data['b'])
68+
print(data['c'])
69+
print(data['c']["c1"])
70+
print(data)'''
71+
#print(self.data_in_memory['place_feature'])

recommender_webapp/common/lightfm_manager.py

+10-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ def add_user(user_id, user_location, user_contexts, data):
1717
"""
1818

1919
lightfm_user_id = constant.DJANGO_USER_ID_BASE_START_LIGHTFM + user_id
20+
print("user_id: " + str(user_id) + " --- django id: " + str(lightfm_user_id) + " --- user_loc: " + str(user_location) + " --- user_contexts: " + str(user_contexts) + " --- data: " + str(data))
2021
for user_context in user_contexts:
2122
contextual_lightfm_user_id = str(lightfm_user_id) + str(user_context.get('mood').value) + str(user_context.get('companionship').value)
2223

@@ -26,11 +27,13 @@ def add_user(user_id, user_location, user_contexts, data):
2627
writer.writerow([contextual_lightfm_user_id, user_location, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
2728

2829
contextual_ratings = data.filter(mood=user_context.get('mood').name, companionship=user_context.get('companionship').name)
30+
print ("contextual ratings: " + str(contextual_ratings))
2931

3032
# Add ratings to ratings.csv
3133
with open(r'engine/data/ratings_train.csv', 'a') as f:
3234
writer = csv.writer(f)
3335
for rating in contextual_ratings:
36+
print ("writing rating: " +str(rating.rating) + " - place: " + str(rating.place.placeId) + " - id_user: " + str(contextual_lightfm_user_id))
3437
writer.writerow([contextual_lightfm_user_id, rating.place.placeId, rating.rating])
3538

3639
# LightFM model recreation - NEW USER SIGN UP-> NEW MODEL
@@ -88,11 +91,16 @@ def find_recommendations(user, user_location, distance, any_events):
8891
caricato al momento dell'avvio di Django all'interno del modulo initializer.py. In questo modo è possibile
8992
restituire i risultati di raccomandazione in modo più efficiente.
9093
"""
91-
94+
print("PAGE IS: LIGHTFM_MANAGER.PY >> find_recommendations(" + str(user) + ", " + str(user_location) + ", " + str(distance) + ", " + str(any_events) + ")")
9295
recommended_places = []
96+
print("find_recommendations.calling data_loader.data_in_memory for places")
9397
places_dict = data_loader.data_in_memory['places_dict']
9498
user = int(user) - 1 # LightFM uses a zero-based indexing
99+
print("find_recommendations.calling lightfm_pugliaeventi.learn_model on model and data")
95100
model, data = lightfm_pugliaeventi.learn_model()
101+
print("MODEL: " + str(model))
102+
print("DATA: " + str(data))
103+
print("find_recommendations.calling lightfm_pugliaeventi.find_recommendations on user, model and data")
96104
recommendations = lightfm_pugliaeventi.find_recommendations(user, model, data)[:constant.NUM_RECOMMENDATIONS_FROM_LIGHTFM]
97105
recommendation_objects = []
98106
for index in recommendations:
@@ -122,4 +130,5 @@ def find_recommendations(user, user_location, distance, any_events):
122130
for place in places_to_show:
123131
recommended_places.append(place)
124132

133+
print("find_recommendations. returning recommended_places")
125134
return recommended_places

0 commit comments

Comments
 (0)