def jump(args): try: search_history_id = args.get('search_history_id') paper_id = args.get('paper_id') search_history = SearchHistory.objects(id=search_history_id).get() search_item = search_history.item paper = Paper.objects(id=paper_id).get() click_history = ClickHistory( search_item=search_item, search_history=search_history, paper=paper, user=User.objects(id=flask_login.current_user.id).get() if flask_login.current_user.is_authenticated else None ) click_history.save() if ClickCount.objects(search_item=search_item, paper=paper).count() > 0: click_count = ClickCount.objects(search_item=search_item, paper=paper).get() else: click_count = ClickCount( search_item=search_item, paper=paper ) click_count.count = click_count.count + 1 click_count.save() return redirect(paper.url) except Exception as e: logging.warning(e) abort(401)
def train_model(item): x, y = [], [] if len(item.papers) > 0 and ClickCount.objects(search_item=item).count() > 0: try: click_counts = ClickCount.objects(search_item=item) h = {} for click_count in click_counts: h[str(click_count.paper.id)] = click_count.count for paper in item.papers: if str(paper.id) in h: count = h[str(paper.id)] else: count = 0 x.append(vectorize_paper(paper)) y.append(count) regressor = tree.DecisionTreeRegressor() regressor.fit(x, y) return regressor except: print(x) print(y) else: return None