Commit 2c51ba97 authored by DmitSPopov's avatar DmitSPopov
Browse files

Fix recomendation_system.py

parent c3f26086
......@@ -3,22 +3,26 @@ from scipy import sparse
from sklearn.preprocessing import normalize
from random import randint
from web_setting import db
from models.all_models import TagsUsers, Tags
from models.all_models import TagsUsers, TagsAdvertisement
from collections import Counter
def get_calc_recomendation(user_id):
def calc_data_for_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()
return Counter(all_tags)
print(get_calc_recomendation(1))
user_data = dict(Counter(all_tags))
queryset = db.session.query(TagsUsers).all()
print(queryset[0][0])
return user_data
print(calc_data_for_recomendation_by_tags(user_id=1))
"""
......@@ -42,14 +46,14 @@ print(get_calc_recomendation(1))
"""
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]}
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]}
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]}
7: [-120, 1432]} # key - id_adv
def get_recomendation_tags(user_data, all_data):
def get_recomendation_by_tags(user_data, all_data):
row_column_index = []
for i in range(len(user_data)):
row_column_index.append(randint(0, 10))
......@@ -85,11 +89,8 @@ def get_recomendation_tags(user_data, all_data):
return result_id
print(get_recomendation_tags(input_user_data, input_all_data))
def get_recomendation_location(user_data, all_data):
tags_recomendation = get_recomendation_tags(input_user_data, input_all_data)
def get_recomendation_by_location(user_data, all_data):
tags_recomendation = get_recomendation_by_tags(input_user_data, input_all_data)
row_column_index = []
for i in range(len(tags_recomendation)):
......@@ -139,5 +140,3 @@ def get_recomendation_location(user_data, all_data):
return result_id
print(get_recomendation_location(input_distance_user, input_distance_data))
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