Commit f33ae851 authored by DmitSPopov's avatar DmitSPopov
Browse files

Add get_recomedation_by_location def

parent 5a183a84
......@@ -3,13 +3,9 @@ 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, ClickHistory
from models.all_models import ClickHistory
from collections import Counter
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
from api.api_advertisment import all_advertisments
def calc_recomendation_by_tags(user_data, all_data):
......@@ -98,7 +94,7 @@ def calc_recomendation_by_location(user_data, all_data, tags_recomendation):
return result_id
def get_recomendation_by_tags(user_id: int):
def get_recomendation_by_tags(user_id: int, all_adv=all_advertisments()):
queryset = db.session.query(ClickHistory).filter(ClickHistory.user_id==user_id).all()
all_tags = []
for _ in queryset:
......@@ -108,11 +104,9 @@ def get_recomendation_by_tags(user_id: int):
user_data = dict(Counter(all_tags))
from api.api_advertisment import all_advertisments
all_data = dict()
for _ in all_advertisments():
for _ in all_adv:
tag_id = []
for val in _['adv_id_tagsadv']:
tag_id.append(val['connect_tags']['id'])
......@@ -121,9 +115,18 @@ def get_recomendation_by_tags(user_id: int):
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
def get_recomendation_by_location(user_id: int, location_str: str):
location = location_str.split()
distance_user = {}
distance_user = {user_id: location}
distance_data = dict()
all_adv = all_advertisments()
for _ in all_adv:
distance_data[_['id']] = _['connect_coordinates']['coordinates']
return calc_recomendation_by_location(distance_user, distance_data, get_recomendation_by_tags(user_id, all_adv))
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