Commit 5a183a84 authored by DmitSPopov's avatar DmitSPopov
Browse files

Fix recomendation_system.py

parent 4735075e
......@@ -3,34 +3,10 @@ from scipy import sparse
from sklearn.preprocessing import normalize
from random import randint
from web_setting import db
from models.all_models import TagsUsers, TagsAdvertisement
from models.all_models import TagsUsers, TagsAdvertisement, ClickHistory
from collections import Counter
def get_recomendation_by_tags(user_id):
queryset = db.session.query(TagsUsers).filter(TagsUsers.user_id==user_id).all()
all_tags = []
for _ in queryset:
all_tags.append(_.tags_id)
all_tags.sort()
user_data = dict(Counter(all_tags))
from api.api_advertisment import all_advertisments
all_data = dict()
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
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
......@@ -72,8 +48,7 @@ def calc_recomendation_by_tags(user_data, all_data):
return result_id
def get_recomendation_by_location(user_data, all_data):
tags_recomendation = get_recomendation_by_tags(data1)
def calc_recomendation_by_location(user_data, all_data, tags_recomendation):
row_column_index = []
for i in range(len(tags_recomendation)):
......@@ -123,3 +98,32 @@ def get_recomendation_by_location(user_data, all_data):
return result_id
def get_recomendation_by_tags(user_id: int):
queryset = db.session.query(ClickHistory).filter(ClickHistory.user_id==user_id).all()
all_tags = []
for _ in queryset:
all_tags.append(_.tags_id)
all_tags.sort()
user_data = dict(Counter(all_tags))
from api.api_advertisment import all_advertisments
all_data = dict()
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
def get_recomendation_by_location(user_id: int, location_str: str):
location = location_str.split()
distance_user = {}
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