def add_authors_to_graph(nodes: list, edges: list, author_ids: Union[list, int], base_author_id: int=None) \ -> (list, list): """ Add a list of author ids to the graph Args: edges: current list of edges nodes: current list of nodes author_ids: a list of authors to add to the list base_author_id: the author of which the authors should be connected by edges Returns: updates list of nodes and edges """ author_ids = makelist(author_ids) for author_id in author_ids: author = Authors.select().where(Authors.id == author_id).get() new_node = { "id": author.id, "label": author.name, "shape": "dot", "value": author.pagerank, "font": "14px arial black", "color": '#97C2FC' if author.id == int(options.author) else '#FB7E81' } if new_node not in nodes: nodes.append(new_node) if base_author_id is not None and int(base_author_id) != author.id: new_edge = { "from": min(author.id, int(base_author_id)), "to": max(author.id, int(base_author_id)) } if new_edge not in edges: edges.append(new_edge) return nodes, edges
def main(): authors = Authors.select().limit(LIMIT) rating_list = [] for a in authors: print(a.name) rating_list.append(get_data(a.name)) ratings_to_csv(rating_list)
def api_author(aid): if request.method == 'GET': rs = Authors.select().where(Authors.id == aid).dicts().get() return jsonify(rs) else: data = request.get_json(force=True) rs = Authors.update(**data).where(Authors.id == aid).execute() return jsonify(data)
def api_authors(): if request.method == 'GET': rs = Authors.select().order_by(Authors.second_name, Authors.first_name).dicts() return jsonify({'result': list(rs)}) else: rs = Authors.create(**request.get_json(force=True)) return jsonify(model_to_dict(rs))
author = int(author) except ValueError: continue if paper in paper_index: paper_index[paper].append(author) else: paper_index[paper] = [author] for paper, authors in paper_index.items(): for author1 in authors: for author2 in authors: if author1 != author2: author_matrix[author1, author2] += 1 # print(author_matrix, 10) # Graph analysis G_mat = author_matrix # Create a directed graph G1 = nx.DiGraph(G_mat) # Write edge list to csv file for further analysis in Gephi or something else #nx.write_edgelist(G1,'edges.csv',delimiter=',' ,data=False) # Calculate PageRank per author with parameter alpha = 0.8 pagerank = nx.pagerank(G1, alpha=0.8) for author in Authors.select(): author.pagerank = pagerank[author.id] author.save()
def api_stories_by_id(aid): story = Stories.select().where(Stories.id == aid).dicts().get() story['authors'] = list( Authors.select().join(AuthorsStories).join(Stories).where( Stories.id == aid).dicts()) return jsonify({'result': story})