def possible_partners(): """Return the possible donors given a nonprofit""" attr = request.args.get('attr') if attr == 'description': query = "call from_id_to_companies_by_desc('%d')" % int(request.args.get('id')) elif attr == 'homepage': query = "call from_id_to_companies_by_home('%d')" % int(request.args.get('id')) elif attr == 'tweets': query = "call from_id_to_companies_by_tweets('%d')" % int(request.args.get('id')) result = DBSession.execute(query) return json.dumps(procedure_to_json(result))
def sector_summary(): """Return the summary of a given NTEE code""" query = "call sector_summary('%s')" % request.args.get('ntee') result = DBSession.execute(query) my_dict = procedure_to_json(result) nonprofits = my_dict['results'] result = { 'avg_closeness_centrality': 0, 'avg_clustering_coefficient': 0, 'avg_degree': 0, 'avg_hubAuth': 0, 'avg_weighted_degree': 0, 'avg_eccentricity': 0, 'avg_clustering_coefficient': 0 } tw_communities = {} web_communities = {} desc_communities = {} for nonprofit in nonprofits: result['avg_closeness_centrality'] += nonprofit[ 'closeness_centrality'] / float(len(nonprofits)) result['avg_clustering_coefficient'] += nonprofit[ 'clustering_coefficient'] / float(len(nonprofits)) result['avg_degree'] += nonprofit['degree'] / float(len(nonprofits)) result['avg_hubAuth'] += nonprofit['hubAuth'] / float(len(nonprofits)) result['avg_weighted_degree'] += nonprofit['weighted_degree'] / float( len(nonprofits)) result['avg_eccentricity'] += nonprofit['eccentricity'] / float( len(nonprofits)) result['avg_clustering_coefficient'] += nonprofit[ 'clustering_coefficient'] / float(len(nonprofits)) if nonprofit['tw_community'] not in tw_communities: tw_communities[nonprofit['tw_community']] = 0 else: tw_communities[nonprofit['tw_community']] += 1 if nonprofit['web_community'] not in web_communities: web_communities[nonprofit['web_community']] = 0 else: web_communities[nonprofit['web_community']] += 1 if nonprofit['desc_community'] not in desc_communities: desc_communities[nonprofit['desc_community']] = 0 else: desc_communities[nonprofit['desc_community']] += 1 result['tw_communities'] = tw_communities result['web_communities'] = web_communities result['desc_communities'] = desc_communities return json.dumps(result)
def similarity(): """Return the most similar nonprofits given a nonprofits and a metric.""" top = 10 if request.args.get('top') is None else int(request.args.get('top')) attr = request.args.get('attr') if attr == 'description': query = 'call from_nonprofit_id_to_similar_charities_by_description(%d, %d)' % (int(request.args.get('id')), top) elif attr == 'homepage': query = 'call from_nonprofit_id_to_similar_charities_by_homepage(%d, %d)' % (int(request.args.get('id')), top) elif attr == 'tweets': query = 'call from_nonprofit_id_to_similar_charities_by_tweets(%d, %d)' % (int(request.args.get('id')), top) elif attr == 'followers': query = 'call from_nonprofit_id_to_similar_charities_by_followers(%d, %d)' % (int(request.args.get('id')), top) result = DBSession.execute(query) return json.dumps(procedure_to_json(result))
def possible_partners(): """Return the possible donors given a nonprofit""" attr = request.args.get('attr') if attr == 'description': query = "call from_id_to_companies_by_desc('%d')" % int( request.args.get('id')) elif attr == 'homepage': query = "call from_id_to_companies_by_home('%d')" % int( request.args.get('id')) elif attr == 'tweets': query = "call from_id_to_companies_by_tweets('%d')" % int( request.args.get('id')) result = DBSession.execute(query) return json.dumps(procedure_to_json(result))
def sector_summary(): """Return the summary of a given NTEE code""" query = "call sector_summary('%s')" % request.args.get('ntee') result = DBSession.execute(query) my_dict = procedure_to_json(result) nonprofits = my_dict['results'] result = { 'avg_closeness_centrality': 0, 'avg_clustering_coefficient': 0, 'avg_degree': 0, 'avg_hubAuth': 0, 'avg_weighted_degree': 0, 'avg_eccentricity': 0, 'avg_clustering_coefficient': 0 } tw_communities = {} web_communities = {} desc_communities = {} for nonprofit in nonprofits: result['avg_closeness_centrality'] += nonprofit['closeness_centrality'] / float(len(nonprofits)) result['avg_clustering_coefficient'] += nonprofit['clustering_coefficient'] / float(len(nonprofits)) result['avg_degree'] += nonprofit['degree'] / float(len(nonprofits)) result['avg_hubAuth'] += nonprofit['hubAuth'] / float(len(nonprofits)) result['avg_weighted_degree'] += nonprofit['weighted_degree'] / float(len(nonprofits)) result['avg_eccentricity'] += nonprofit['eccentricity'] / float(len(nonprofits)) result['avg_clustering_coefficient'] += nonprofit['clustering_coefficient'] / float(len(nonprofits)) if nonprofit['tw_community'] not in tw_communities: tw_communities[nonprofit['tw_community']] = 0 else: tw_communities[nonprofit['tw_community']] += 1 if nonprofit['web_community'] not in web_communities: web_communities[nonprofit['web_community']] = 0 else: web_communities[nonprofit['web_community']] += 1 if nonprofit['desc_community'] not in desc_communities: desc_communities[nonprofit['desc_community']] = 0 else: desc_communities[nonprofit['desc_community']] += 1 result['tw_communities'] = tw_communities result['web_communities'] = web_communities result['desc_communities'] = desc_communities return json.dumps(result)
def similarity(): """Return the most similar nonprofits given a nonprofits and a metric.""" top = 10 if request.args.get('top') is None else int( request.args.get('top')) attr = request.args.get('attr') if attr == 'description': query = 'call from_nonprofit_id_to_similar_charities_by_description(%d, %d)' % ( int(request.args.get('id')), top) elif attr == 'homepage': query = 'call from_nonprofit_id_to_similar_charities_by_homepage(%d, %d)' % ( int(request.args.get('id')), top) elif attr == 'tweets': query = 'call from_nonprofit_id_to_similar_charities_by_tweets(%d, %d)' % ( int(request.args.get('id')), top) elif attr == 'followers': query = 'call from_nonprofit_id_to_similar_charities_by_followers(%d, %d)' % ( int(request.args.get('id')), top) result = DBSession.execute(query) return json.dumps(procedure_to_json(result))
def twitter(): """Return twitter-related information given a nonprofit""" query = 'call from_nonprofit_id_to_twitter(%d)' % int(request.args.get('id')) result = DBSession.execute(query) return json.dumps(procedure_to_json(result))
def graph_stats(): """Return the SNA indexes given a nonprofit""" query = 'call from_nonprofit_id_to_sna(%d)' % int(request.args.get('id')) result = DBSession.execute(query) return json.dumps(procedure_to_json(result))
def related_companies(): """Return the companies that are mentioned with a nonprofit in news articles""" query = 'call related_companies(%d)' % int(request.args.get('id')) result = DBSession.execute(query) return json.dumps(procedure_to_json(result))
def twitter(): """Return twitter-related information given a nonprofit""" query = 'call from_nonprofit_id_to_twitter(%d)' % int( request.args.get('id')) result = DBSession.execute(query) return json.dumps(procedure_to_json(result))