def graph(self): """Return the Graphistry URL for the graph, or an IPython Widget Parameters ---------- render : bool, optional Should the result be a IPython widget? (default value is False, which returns the URL). Returns ------- Union[str, IPython.core.display.HTML] str with URL to graphistry object when render if False, otherwise HTML widget for IPython. """ super().graph() graphistry.register(self.key) # Convert to JSON for graphistry due to node data being objects. if self.anonymize: G = self.anoynmize_graph() return graphistry.bind(source="src", destination="dst", point_label="_id", edge_label="type").plot(G, render=self.render) else: G = nx.readwrite.json_graph.node_link_graph(self.to_json()) return graphistry.bind(source="src", destination="dst", point_label="_display", edge_label="type").plot(G, render=self.render)
def __init__(self, overrides={}): cfg = { 'api': 3, **({ 'username': os.environ['GRAPHISTRY_USERNAME'] } if 'GRAPHISTRY_USERNAME' in os.environ else {}), **({ 'password': os.environ['GRAPHISTRY_PASSWORD'] } if 'GRAPHISTRY_PASSWORD' in os.environ else {}), **({ 'token': os.environ['GRAPHISTRY_TOKEN'] } if 'GRAPHISTRY_TOKEN' in os.environ else {}), **({ 'protocol': os.environ['GRAPHISTRY_PROTOCOL'] } if 'GRAPHISTRY_PROTOCOL' in os.environ else {}), **({ 'server': os.environ['GRAPHISTRY_SERVER'] } if 'GRAPHISTRY_SERVER' in os.environ else {}), **({ 'client_protocol_hostname': os.environ['GRAPHISTRY_CLIENT_PROTOCOL_HOSTNAME'] } if 'GRAPHISTRY_CLIENT_PROTOCOL_HOSTNAME' in os.environ else {}), **overrides } if not (('username' in cfg) and ('password' in cfg)) and not ('token' in cfg): #logger.info('No graphistry creds set, skipping') return if not ('store_token_creds_in_memory' in cfg): cfg['store_token_creds_in_memory'] = True graphistry.register(**cfg) graphistry.login(username=cfg['username'], password=cfg['password'])
def setup_class(cls): from neo4j import GraphDatabase NEO4J_CREDS = { 'uri': 'bolt://neo4j4-test:7687', 'auth': ('neo4j', 'test') } graphistry.pygraphistry.PyGraphistry._is_authenticated = True graphistry.register(api=3, bolt=GraphDatabase.driver(**NEO4J_CREDS))
def test_login(self, verbose=True): try: graphistry.register() return True except: # noqa: E722 if verbose: st.write( Exception("""Not logged in for Graphistry plots: Get free GPU account at graphistry.com/get-started and plug into src/docker/.env using template at envs/graphistry.env""" )) return False
def __init__(self, uri='bolt://localhost:7687', username='******', password='******'): """ Initializes connection to database. :param str URI: location of graph database on local host. :param str username: the name of the user to login to local database with. :param str password: password of the user to login with. """ neo4j_creds = {'uri': uri, 'auth': (username, password)} graphistry_creds = {'server': uri, 'api': 2, 'key': 'apikey'} self.__db__ = GraphDatabase.driver(**neo4j_creds) graphistry.register(bolt=neo4j_creds, **graphistry_creds) with self.__db__.session() as session: session.write_transaction(self.set_constraints)
def draw_graph(graph, nodes=None): ''' 采用pygraphistry 来绘制网络图,节点颜色目前还不能超过12种 :param graph: networkx.Graph/DiGraph :param nodes: DataFrame,如果需要按社区颜色绘制,请传入带有社区信息的节点表, ['Id','modulraity_class'] :return: None ''' graphistry.register(key='contact pygraphistry for api key') ploter = graphistry.bind(source='Source', destination='Target').graph(graph) if nodes is not None: ploter = ploter.bind(node='Id', point_color='modularity_class').nodes(nodes) ploter.plot() return None
def call_host(): graphistry.register(api=3, protocol="https", server="hub.graphistry.com", username="******", password="******") TG_HOST = 'https://_______.i.tgcloud.io' #TG_HOST2 = '________' TG_USERNAME = '******' TG_PASSWORD = '******' TG_GRAPHNAME = '_________' TG_SECRET = '_____________' conn = tg.TigerGraphConnection( host=TG_HOST, username=TG_USERNAME, password=TG_PASSWORD, graphname=TG_GRAPHNAME, ) conn.getToken(TG_SECRET) return conn
import streamlit as st import graphistry import pandas as pd from css import all_css from components import GraphistrySt #URLParam graphistry.register(api=3, protocol="https", server="hub.graphistry.com", username="******", password="******") ## or via fresh short-lived token below that expires in 1:00:00 after initial generation ## graphistry.register(api=3, protocol="https", server="hub.graphistry.com", token="eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VybmFtZSI6ImtldmluIiwiaWF0IjoxNjE1ODQ5ODcyLCJleHAiOjE2MTU4NTM0NzIsImp0aSI6IjQ5MjI0NzliLTJjMTAtNDA3YS04MWI2LTI1ZTA2YjUzZGVhNiIsInVzZXJfaWQiOjM4ODQsIm9yaWdfaWF0IjoxNjE1ODQ5ODcyfQ.sf5e0fRuZ5d_oNpzsZ1kuywBclbcBS0FmuSISnK4_1A") def sidebar_area(): # regular param (not in url) e = st.sidebar.number_input('Number of edges', min_value=10, max_value=100000, value=100, step=20) # deep-linkable param (in url) # n_init = urlParams.get_field('N', 100) n_init = 100 n = st.sidebar.number_input('Number of nodes', min_value=10, max_value=100000, value=n_init, step=20)
st.set_page_config(layout="wide") #conncet with tg and graphistry tg_host = "https://graph.i.tgcloud.io" graph_name = "MyGraph" tg_username = "******" tg_password = '******' apiToken = "r633lnmiia9sad9dd3u1pl79787ploqu" conn = tg.TigerGraphConnection(host=tg_host, graphname=graph_name, username=tg_username, password=tg_password, apiToken=apiToken) #connect with graphistry gs_usernane = 'qi2' gs_password = '******' graphistry.register(api=3, protocol="https", server="hub.graphistry.com", username="******", password="******") #set debug mode as true # conn.debug = True #read country from csv file country = pd.read_csv('./country.csv', usecols=['0']) country = country.drop([1]).reset_index(drop=True) #sidebar st.sidebar.title('Choose your favorite Graph') sidebar = st.sidebar graph_option = sidebar.selectbox( 'select graph', ('Data overview', 'Shortest path', 'Centrality')) # cover image and title
#!/usr/bin/env python # coding: utf-8 # In[1]: import graphistry import pandas as pd import numpy as np import requests # In[2]: graphistry.register(api=3, protocol="https", server="hub.graphistry.com", username="******", password="******") # In[3]: import pyTigerGraph as tg TG_HOST = "https://halal.i.tgcloud.io" TG_USERNAME = "******" TG_PASSWORD = "******" TG_GRAPH = "halal" TG_SECRET = "gh9urnvt8aa0hk2tppic1r9vck0jmumj" conn = tg.TigerGraphConnection(host=TG_HOST, graphname=TG_GRAPH, username=TG_USERNAME,
import os import graphistry import graph_builder as gb graphistry.register(os.environ["GRAPHISTRY_KEY"]) def make_graphistry_plot(graph): graphistry.bind(source='src', destination='dst', node='nodeid').plot(graph) graph = gb.build_directed_graph_from_csvs("data/", num_files=None) make_graphistry_plot(graph)
def setUpClass(cls): graphistry.pygraphistry.PyGraphistry._is_authenticated = True graphistry.register(api=2)
# external libraries from sanic import Sanic from sanic.response import html, redirect, text from jinja2 import Environment, PackageLoader import graphistry import igraph as ig graphistry.register( key='77ab9bcccd62c6bcf10ed37fb759fa849cd9bb1157cff17260da05e9e898d6ba' ) env = Environment( loader=PackageLoader("app", "templates"), ) app = Sanic(__name__) app.static("/static", "./static") @app.route("/") async def start(request): template = env.get_template("home.html") html_content = template.render() return html(html_content) @app.route("/query", methods=['POST', 'GET']) async def query(request): req_file = request.files.get("file") file_name = req_file.name body = req_file.body.decode("unicode_escape")
import pandas as pd import graphistry import warnings import datetime import dateutil.relativedelta as relativedelta from methods import * __author__ = "Tamara Komnenic" # Definisati putanju do projekta prefix_path = "/home/cm/PycharmProjects/drustvene_mreze/" # setup warnings.filterwarnings('ignore') api_key = open(prefix_path + 'API_key.txt').read() graphistry.register(key=api_key) edges = pd.read_csv(prefix_path + 'dataset/new_data/all_text_lines.txt', sep='\t\t\t', names=['src', 'dest']) graph = nx.from_pandas_dataframe(edges, source='src', target='dest', create_using=nx.DiGraph()) attributes = pd.read_csv(prefix_path + 'dataset/new_data/name_date.txt', sep='\t', names=['node', 'value']) attrs = attributes.set_index('node')['value'].to_dict() filter_nodes(attrs, edges) stop = datetime.datetime(1801, 1, 1) current = datetime.datetime.now() nx.set_node_attributes(graph, 'timestamp', attrs)
import dash_bootstrap_components as dbc import dash_core_components as dcc import dash_html_components as html import dash_cytoscape as cyto from dash.dependencies import Input, Output, State import graphistry as graphistry import pandas as pd import plotly.figure_factory as ff from datetime import timedelta, datetime import time import threading from config import graphistry_pw, graphistry_un graphistry.register(api=3, protocol="https", server="hub.graphistry.com", username=graphistry_un, password=graphistry_pw) def type_to_color(t): mapper = {'Patient': 0xFF000000} if t in mapper: return mapper[t] else: return 0xFFFFFF00 def plotter_thread(df2): g = graphistry.edges(df2).bind(edge_color='my_color', source='Source',
def login(): if 'user' in session: return redirect(url_for('dashboard', user=session['user'])) if request.method == 'POST': login_user = db.users.find_one({'username': request.form['username']}) if login_user: data = { 'username': login_user['username'], 'is_active': login_user['is_active'], 'follower_count': login_user['follower_count'], 'following_count': login_user['following_count'], 'profile_picture': login_user['profile_picture'], 'full_name': login_user['full_name'], 'rank_token': login_user['rank_token'], 'graph': login_user['graph'] } session['user'] = json.loads(json_util.dumps(data)) return redirect(url_for('dashboard', user=session['user'])) else: try: # try logging in user Client( request.form['username'], request.form['password']) except ClientLoginError: return redirect(url_for('login')) except ClientChallengeRequiredError: # redirect the user back to the login page if username and passwword fails pass except ClientCheckpointRequiredError: pass # set client agent api = Client(request.form['username'], request.form['password']) # create a new user from the username store it into the variable called me :) me = User() # set the username me.set_username(request.form['username']) # set user to active me.set_to_active() # create user is user_id = api.authenticated_user_id # set my id me.set_id(user_id) # set set full name me.set_name(api.user_info(me.get_id())['user']['full_name']) # set rank token me.set_rank_token(api.generate_uuid()) #####################!You need at least 32 cores to run this f**k shit!############################################ # test = [] # results = api.user_followers(me.id, me.rank_token) # test.extend(results.get('users', [])) # next_max_id = results.get('next_max_id') # while next_max_id: # results = api.user_followers( # me.id, me.rank_token, max_id=next_max_id) # test.extend(results.get('users', [])) # if len(test) >= 8000: # break # next_max_id2 = results.get('next_max_id') # test2 = [] # results2 = api.user_following(me.id, me.rank_token) # test2.extend(results2.get('users', [])) # next_max_id2 = results2.get('next_max_id') # while next_max_id2: # results2 = api.user_following( # me.id, me.rank_token, max_id=next_max_id) # test2.extend(results2.get('users', [])) # if len(test2) >= 8000: # break # next_max_id2 = results2.get('next_max_id') # relations = [] # for user in test: # # grab followed user id # followed_id = user['pk'] # followed_name = user['full_name'] # relations.append(( # me.get_id(), followed_id, me.get_full_name(), followed_name)) # # if test2.get('users') is not None: # for users in test2: # relations.append( # (followed_id, users['pk'], followed_name, users['full_name'])) # df = pd.DataFrame(relations, columns=[ # 'src_id', 'dst_id', 'src_name', 'dst_name']) # key = os.environ.get('graphistry_key') # graphistry.register(key=key) # graph = graphistry.bind(source='src_name', # destination='dst_name').edges(df).plot() #####################!You need at least 32 cores to run this f**k shit!############################################ # followers followers = api.user_followers( me.get_id(), me.get_rank_token()) # following following = api.user_following( me.get_id(), me.get_rank_token()) # set the likes # me.set_likes(api.feed_liked()) # print(me.likes) # set followers count count = 0 for user in followers['users']: count += 1 me.set_follower_count(count) val = 0 for user in following['users']: val += 1 # set following count me.set_following_count(val) # set picture me.set_picture(api.user_info(me.id)['user']['profile_pic_url']) # wtf is this # print(api.explore()) # follow relationtionships # api.story_viewers() follow_relationships = [] # create network for user in tqdm(following['users']): # grab followed user id followed_user_id = user['pk'] # grab followed user full name followed_user_name = user['full_name'] # append my id, followed user id, my full name, followed user full name follow_relationships.append( (me.get_id(), followed_user_id, me.get_full_name(), followed_user_name)) # if you are following no one break if following.get('users') is not None: for users in followers['users']: follow_relationships.append( (followed_user_id, users['pk'], followed_user_name, users['full_name'])) # set network me.set_network(follow_relationships) df = pd.DataFrame(follow_relationships, columns=[ 'src_id', 'dst_id', 'src_name', 'dst_name']) graphistry.register(key=key) me.set_graph(graphistry.bind(source='src_name', destination='dst_name').edges(df).plot()) graph = str(me.get_graph()) # set our graph # me.set_graph(graph) # get data from user object data = me.json() # push data to our collection in data base db.users.insert_one(json.loads(json_util.dumps(data))) # store session data as cookie session['user'] = json.loads(json_util.dumps(data)) # redirect to dashboard return redirect(url_for('dashboard', user=session['user'])) if request.method == 'GET': return render_template('login.html')
import dash import dash_bootstrap_components as dbc import dash_core_components as dcc import dash_html_components as html import graphistry as graphistry from dash.dependencies import Input, Output, State import pandas as pd import urllib.request from pandas.tseries.offsets import * graphistry.register(api=3, protocol="https", server="hub.graphistry.com", username="******", password="******") url = "https://raw.githubusercontent.com/uber-web/kepler.gl-data/master/earthquakes/data.csv" download_file = urllib.request.urlretrieve(url, "data.csv") df = pd.read_csv("data.csv") my_src_col = 'DateTime' my_dest_col = 'EventID' g = None g = graphistry.edges(df).bind(source=my_src_col, destination=my_dest_col) graph = g.plot() graph_viz = html.Iframe(src=graph, height='800', width='100%') graphistry_page = html.Div([html.H2("Graphistry Visualization"), graph_viz])
def visualize(self, query): """ Create display of the graph after performing the query attached." """ graphistry.register()
def setUpClass(cls): graphistry.pygraphistry.PyGraphistry._is_authenticated = True graphistry.pygraphistry.PyGraphistry.store_token_creds_in_memory(True) graphistry.pygraphistry.PyGraphistry.relogin = lambda: True graphistry.register(api=3)