def rank_node(discussion_id, parent_id): # parent_id is node_id query = DBQuery() temp_parent = parent_id status = query.get_discussions_by_id(discussion_id) if status[0].status == 'Voting': if request.method == 'POST': amount = request.form['rank'] query = DBQuery() first_time = 0 last_time = 1 last_parent = parent_id while parent_id is not None: print('Boaz') print(parent_id) rank_node = query.vote_for_comment(session['email'], discussion_id, parent_id, amount, first_time, last_time) parent_id, parent_content = query.get_parent_id(parent_id) first_time = 1 last_time = 0 rank_node = query.vote_for_comment(session['email'], discussion_id, last_parent, amount, first_time, last_time) else: if request.method == 'POST': amount = request.form['rank'] query = DBQuery() discussion = query.get_discussions_by_id(discussion_id) comments = query.get_all_comments_list(discussion_id) # sub_comments = query.get_all_sub_comments_list(discussion_id) graph = {} counter = 1 level = [1] # num75 = get_num_75(discussion_id) # get_nodes_75(discussion_id, num75) for s in comments: # if node_id == s[0].node_id mylist = [] node_id = s[0] counter = counter + 1 for j in comments: parent_id = (j[2]) if parent_id == node_id: level.append(counter) mylist.append(str(j[0])) graph[str(node_id)] = mylist if str(node_id) not in graph: graph[str(node_id)] = [] visited = dfs_voting(graph, temp_parent, [], discussion_id, amount) print('we are printing dfs VOTING VISITED @@@@@@@@@@@@@@@@@@@@@@@') print('we are printing dfs VOTING VISITED @@@@@@@@@@@@@@@@@@@@@@@') print(visited) query.rank_final_decision(session['email'], discussion_id, parent_id, amount) return redirect('/discussions/' + discussion_id + '/tree')
def discussion_page_settings(discussion_id): query = DBQuery() discussion = query.get_discussions_by_id(discussion_id) comments = query.get_all_comments_list(discussion_id) user = '' joined = '' user_score_discussion = '' big_dict = {} for c in comments: parent_id = c[2] parent_content = c[3] value_list = [] while parent_id is not None: value_list.insert(0, parent_content) big_dict[c[0]] = value_list parent_id, parent_content = query.get_parent_id(parent_id) user_score_discussion = '' if session['logged_in']: user = query.get_user_details(session['email']) joined = query.check_if_joined(discussion_id, session['email']) user_score_discussion = query.get_user_vote_details_discussion( discussion_id, session['email']) return render_template('discussion_page.html', discussion=discussion, comments=comments, main=False, user=user, joined=joined, user_score_discussion=user_score_discussion, big_dict=big_dict, settings=True)
def remove_branches(discussion_id): query = DBQuery() discussion = query.get_discussions_by_id(discussion_id) comments = query.get_all_comments_list(discussion_id) graph = {} counter = 1 level = [1] if request.method == 'POST': percentile = int(request.form['percentile']) num75 = get_num_75(discussion_id, percentile) get_nodes_75(discussion_id, num75) for s in comments: mylist = [] node_id = s[0] counter = counter + 1 for j in comments: parent_id = (j[2]) if parent_id == node_id: level.append(counter) mylist.append(str(j[0])) graph[str(node_id)] = mylist if str(node_id) not in graph: graph[str(node_id)] = [] global html_string html_string = [] status = discussion[0][6] print(status) visited = dfs(graph, str(comments[0][0]), [], html_string, comments, status) str1 = ''.join(html_string) user = query.get_user_details(session['email']) reset_ranking = query.reset_ranking(discussion_id) return redirect( url_for('discussions.discussion_page_tree', discussion_id=discussion_id, discussion=discussion, comments=comments, html_string=Markup(str1), main=True, tree=True, status=True, user=user))
def discussion_page_main(discussion_id): query = DBQuery() discussion = query.get_discussions_by_id(discussion_id) comments = query.get_all_comments_list(discussion_id) graph = {} counter = 1 level = [1] for s in comments: mylist = [] node_id = s[0] counter = counter + 1 for j in comments: parent_id = (j[2]) if parent_id == node_id: level.append(counter) mylist.append(str(j[0])) graph[str(node_id)] = mylist if str(node_id) not in graph: graph[str(node_id)] = [] global html_string status = discussion[0][6] html_string = [] visited = dfs(graph, str(comments[0][0]), [], html_string, comments, status) str1 = ''.join(html_string) user = '' merge_comments = '' joined = '' big_dict = {} for c in comments: parent_id = c[2] parent_content = c[3] value_list = [] if parent_id is None: value_list.insert(0, parent_content) big_dict[c[0]] = value_list else: while parent_id is not None: value_list.insert(0, parent_content) big_dict[c[0]] = value_list parent_id, parent_content = query.get_parent_id(parent_id) print(big_dict) user_score_discussion = '' if session['logged_in']: user = query.get_user_details(session['email']) user_score_discussion = query.get_user_vote_details_discussion( discussion_id, session['email']) merge_comments = query.get_merge_list(discussion_id) joined = query.check_if_joined(discussion_id, session['email']) return render_template('discussion_page.html', discussion=discussion, comments=comments, main=True, tree=False, html_string=Markup(str1), user=user, merge_list=merge_comments, joined=joined, user_score_discussion=user_score_discussion, big_dict=big_dict)