Commit 4735075e authored by DmitSPopov's avatar DmitSPopov
Browse files

End function for recomendation_system.py

parent e7327f97
......@@ -7,7 +7,7 @@ from models.all_models import TagsUsers, TagsAdvertisement
from collections import Counter
def calc_data_for_recomendation_by_tags(user_id):
def get_recomendation_by_tags(user_id):
queryset = db.session.query(TagsUsers).filter(TagsUsers.user_id==user_id).all()
all_tags = []
for _ in queryset:
......@@ -17,43 +17,26 @@ def calc_data_for_recomendation_by_tags(user_id):
user_data = dict(Counter(all_tags))
queryset = db.session.query(TagsUsers).all()
print(queryset[0][0])
from api.api_advertisment import all_advertisments
return user_data
all_data = dict()
print(calc_data_for_recomendation_by_tags(user_id=1))
for _ in all_advertisments():
tag_id = []
for val in _['adv_id_tagsadv']:
tag_id.append(val['connect_tags']['id'])
all_data[_['id']] = tag_id
result_id = calc_recomendation_by_tags(user_data, all_data)
return result_id
"""
Формат вывода: Counter({1: 3, 2: 2})
Функция возвращает коллекцию со словарем
ключ-значение
ключ - tag_id
значение - количество повторений tag_id
Если присвоить переменной, например val = Counter({1: 3, 2: 2}), то
In 1: val[1]
Out 2: 3
In 1: val[2]
Out 2: 2
"""
input_user_data = {1: 2, 2: 21, 3: 13, 4: 9}
input_all_data = {1: [1, 2], 2: [1, 4, 5], 3: [2], 4: [1], 5: [6], 6: [1, 2], 7: [1, 2, 3]} # Ключ - id бращения, значения [id тэгов]
input_distance_user = {1: [10, 200]} # key - user_id, [x, y]
input_distance_data = {1: [20, 120], 2: [25, -100], 3: [10, 133], 4: [400, 300], 5: [144, 1322], 6: [122, -10],
7: [-120, 1432]} # key - id_adv
def get_recomendation_by_tags(user_data, all_data):
def calc_recomendation_by_tags(user_data, all_data):
row_column_index = []
for i in range(len(user_data)):
row_column_index.append(randint(0, 10))
......@@ -90,7 +73,7 @@ def get_recomendation_by_tags(user_data, all_data):
def get_recomendation_by_location(user_data, all_data):
tags_recomendation = get_recomendation_by_tags(input_user_data, input_all_data)
tags_recomendation = get_recomendation_by_tags(data1)
row_column_index = []
for i in range(len(tags_recomendation)):
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment