Пример #1
0
def main():
    """ 
    Gets login credentials from the user and
    establishes a connection to the TigerGraph database 
    """
    
    st.title("TigerGraph Visual Query Tool")

    st.write("Welcome to my first Streamlit + TigerGraph project connecting a web application to a graph database and visualizing query data.")

    graph = None
    authToken = None

    sb = st.sidebar
    sb.header("Connect to TigerGraph Database")
    host = sb.text_input("Host URL")
    username = sb.text_input("Username")
    password = sb.text_input("Password", type="password")
    graphname = sb.text_input("Graph Name")
    if sb.checkbox("Connect to Graph"):
        # establish connection to TG database
        graph = tg.TigerGraphConnection(
            host=host, 
            username=username, 
            password=password, 
            graphname=graphname, 
        )
        st.success(f"Connected to {graphname} graph")
        secret = sb.text_input("Secret", type="password")
        if (sb.checkbox("Get Auth Token")):
            # get auth token using user inputted secret
            authToken = graph.getToken(secret)
            tasks.main(graph, authToken)
Пример #2
0
def connect_to_tigergraph() -> Optional[dict]:
    if ('TIGERGRAPH_HOST' in os.environ and 'TIGERGRAPH_USERNAME' in os.environ
        and 'TIGERGRAPH_PASSWORD' in os.environ and 'TIGERGRAPH_GRAPHNAME' in os.environ):

        creds = {
            'host': os.environ["TIGERGRAPH_HOST"],
            'username': os.environ["TIGERGRAPH_USERNAME"],
            'password': os.environ["TIGERGRAPH_PASSWORD"],
            'graphname': os.environ["TIGERGRAPH_GRAPHNAME"]
        }
        logger.info('Connecting to TigerGraph using environment variables: %s',
            {**creds,
            'password': ''.join(['*' for x in creds['password']]) if creds['password'] is not None else ''})

        conn = tg.TigerGraphConnection(**creds, version=TIGERGRAPH_CONNECTION_VERSION)

        if ('TIGERGRAPH_SECRET' in os.environ and os.environ["TIGERGRAPH_SECRET"] is not None):
            logger.info('... Connected to TG, getting token via provided secret...')
            secret = os.environ["TIGERGRAPH_SECRET"]
            conn.getToken(secret)
        else:
            # FIXME: This times out in practice, maybe TG 3.0 -> 3.1 version issues?
            logger.info('... Connected to TG, creating secret and getting token...')
            conn.getToken(conn.createSecret())

        logger.info('Successfully finished connecting to TG!')
        return conn

    logger.debug("Missing TigerGraph environment variables; skipping connection")
    return None
Пример #3
0
def sidebar():
    conn = tg.TigerGraphConnection(host=TG_HOST,
                                   username=TG_USERNAME,
                                   password=TG_PASSWORD,
                                   graphname=TG_GRAPHNAME)
    token = conn.getToken(TG_SECRET)
    st.sidebar.subheader("Select two People see their connection(s)")
    idList = [i for i in range(1, 20000)]
    pid_a = st.sidebar.selectbox('Person A ID ', idList)
    pid_b = st.sidebar.selectbox('Person B ID ', idList)
    kList = [i for i in range(1, 11)]
    k = st.sidebar.selectbox('K hops ', kList)
    return {'person_a': pid_a, 'person_b': pid_b, 'k_hops': k}
def sidebar_area():

    logger.info('sidebar_area')

    st.sidebar.subheader('Select account for 360 view')
    idList = [i for i in range(1, 500)]
    user_id = st.sidebar.selectbox('User ID ', idList)
    urlParams.set_field('user_id', user_id)

    # Optional, can replace with: conn = tg_helper.connect_to_tigergraph()
    conn = None
    st.sidebar.subheader('Optional: Override tigergraph.env')
    tg_host = st.sidebar.text_input('TigerGraph Host')
    tg_username = st.sidebar.text_input('TigerGraph Username')
    tg_password = st.sidebar.text_input('TigerGraph Password', type='password')
    tg_secret = st.sidebar.text_input('TigerGraph Secret', type='password')
    tg_graphname = st.sidebar.text_input('TigerGraph Graphname')
    if st.sidebar.button("Connect"):
        try:
            conn = tg.TigerGraphConnection(
                host=tg_host,
                graphname=tg_graphname,
                username=tg_username,
                password=tg_password,
                version=tg_helper.TIGERGRAPH_CONNECTION_VERSION)
            if tg_secret:
                conn.getToken(tg_secret)
            else:
                conn.getToken(conn.createSecret())
        # FIXME: What is the expected exn?
        except Exception as e:  # noqa: E722
            logger.error('Failed dynamic tg connection: %s', e, exc_info=True)
            st.sidebar.error("Failed to Connect")
            st.sidebar.error(e)
            return None
    else:
        conn = tg_helper.connect_to_tigergraph()
    if conn is None:
        logger.error('Cannot run tg demo without creds')
        st.write(
            RuntimeError(
                'Demo requires a TigerGraph connection. Put creds into left sidebar, or fill in envs/tigergraph.env & restart'
            ))
        return None

    st.sidebar.success("Connnected Successfully")
    return {'user_id': user_id, 'conn': conn}
Пример #5
0
def connect_to_tigergraph():
    if ('TIGERGRAPH_HOST' in os.environ and 'TIGERGRAPH_USERNAME' in os.environ and 'TIGERGRAPH_PASSWORD' in os.environ and 'TIGERGRAPH_GRAPHNAME' in os.environ):
        host = os.environ["TIGERGRAPH_HOST"]
        username = os.environ["TIGERGRAPH_USERNAME"]
        password = os.environ["TIGERGRAPH_PASSWORD"]
        graphname = os.environ["TIGERGRAPH_GRAPHNAME"]
        conn = tg.TigerGraphConnection(host=host, graphname=graphname, username=username, password=password)
        if ('TIGERGRAPH_SECRET' in os.environ and os.environ["TIGERGRAPH_SECRET"] != None):
            secret = os.environ["TIGERGRAPH_SECRET"]
            conn.getToken(secret)
        else:
            conn.getToken(conn.createSecret())
        logger.info(host)
        return conn
    else:
        logging.error("Internal Configuraiton Error Occurred.  ")
        return None
Пример #6
0
def sidebar_area():

    num_edges_init = urlParams.get_field('num_matches', 0.5)
    # MI_List.reverse()
    idList = [i for i in range(1, 500)]

    #TigerGraph connection input fields
    st.sidebar.header("TigerGraph Anti-Fraud")
    tg_host = st.sidebar.text_input('TigerGraph Host')
    tg_username = st.sidebar.text_input('TigerGraph Username')
    tg_password = st.sidebar.text_input('TigerGraph Password')
    tg_graphname = st.sidebar.text_input('TigerGraph Graphname')
    tg_secret = st.sidebar.text_input('TigerGraph Secret')

    # Connect to TigerGraph
    if st.sidebar.button("Connect"):
        try:
            conn = tg.TigerGraphConnection(host=tg_host,
                                           graphname=tg_graphname,
                                           username=tg_username,
                                           password=tg_password)
            if tg_secret:
                conn.getToken(tg_secret)
            else:
                conn.getToken(conn.createSecret())
            st.sidebar.success("Connnected Successfully")
            user_id = st.sidebar.selectbox('User ID ', idList)
            urlParams.set_field('user_id', user_id)

            return {'user_id': user_id, 'conn': conn}

        except:
            st.sidebar.error("Failed to Connect")
            return None

    return None

    user_id = st.sidebar.selectbox('User ID ', idList)

    urlParams.set_field('user_id', user_id)

    return {'user_id': user_id, 'conn': conn}
Пример #7
0
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
Пример #8
0
""")
    for e in res:
        print(e)



def usage():
    print("the usage is :\n")
    print("python3 ioT.py <tag>.i.tgcloud.io tigergraph password")

server =sys.argv[1] 
user =sys.argv[2] 
password =sys.argv[3] 
if (server !="" and user != "" and password != ""):
    try:
        conn = tg.TigerGraphConnection(host=server,username=user,password=password,version="3.0.5")
        conn.getVer()
    except Exception as e:
        usage()
    print("DDL ...")
    schema()
    print("Schema ceated !")
else:
    usage()






from unweight import *
import graphistry
import streamlit.components.v1 as components


#set layout as wide 
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')
Пример #10
0
import requests
import configs

configs = {
    "server": "https://rasa.i.tgcloud.io",
    "user": "******",
    "password": "******",
    "version": "3.1.0",
    "graph": "c360",
    "secret": configs.secret
}

app = Flask(__name__, static_url_path='/static')

conn = tg.TigerGraphConnection(host="https://discord.i.tgcloud.io",
                               password="******",
                               useCert=True)

conn.graphname = "DiscordGraph"
conn.apiToken = conn.getToken(configs["secret"])


@app.route('/js/<path:path>')
def send_js(path):
    return send_from_directory('static/js', path)


@app.route('/css/<path:path>')
def send_css(path):
    return send_from_directory('static/css', path)
Пример #11
0
#!/usr/bin/python3

import sys
from typing import Optional, Any

import pyTigerGraphBeta as tg

conn = tg.TigerGraphConnection(host="http://172.22.0.2",
                               useCert=False,
                               username="******",
                               password="******",
                               version="3.0.5",
                               gsPort=14240)
# conn = tg.TigerGraphConnection(host="https://iot.i.tgcloud.io",username="******",password="******",version="3.0.5")
# print(conn.getVer())
# https://iot.i.tgcloud.io/
# https://iot.i.tgcloud.io/api/info/schema/style/ioT_Graph


def schema():
    #  Apply the
    res = conn.gsql("""
CREATE GRAPH ioT ()    
CREATE SCHEMA_CHANGE JOB change_schema_of_ioT  FOR GRAPH ioT {
ADD VERTEX Location (PRIMARY_ID Points STRING, Latitude FLOAT, Longitude FLOAT) WITH primary_id_as_attribute="TRUE"; 
ADD VERTEX Measurement (PRIMARY_ID meas_id STRING, dm_name STRING, dm_value FLOAT, dm_date STRING, dm_unit STRING, dm_abv_unit STRING)  WITH primary_id_as_attribute="TRUE"; 
ADD VERTEX Device (PRIMARY_ID device_id STRING, location_id STRING, topic STRING)  WITH primary_id_as_attribute="TRUE"; 
ADD VERTEX Topic (PRIMARY_ID  topic_name STRING, topic_description STRING, topic_type STRING)  WITH primary_id_as_attribute="TRUE";

ADD UNDIRECTED EDGE device_topic (FROM Device, TO Topic);
ADD UNDIRECTED EDGE measurement_topic (FROM Measurement, TO Topic);
Пример #12
0
# this package Imports
from flask import  request, render_template
import requests
import pyTigerGraphBeta as tg


configs = {
    "server" : "http://142.93.194.191",
    "user" : "tigergraph",
    "password" : "tigergraphtester",
    "version" : "3.1.0",
    "graph" : "c360",
    "secret" : "94q1hn6bl3lmvkueodthe78e90369n8p",
}

conn = tg.TigerGraphConnection(host=configs["server"], graphname=configs["graph"], username=configs["user"],
                               password=configs["password"], useCert=False)
conn.apiToken = conn.getToken(configs["secret"])

# Get Most Starred Repos ?

GetMostStarred = conn.runInstalledQuery("GetMostStarred")[0]["Result"]
resSorted = sorted(GetMostStarred, key=lambda i: i['StarCount'], reverse=True)
RepoStarsList = resSorted[:40]

# Get the Most Active Users

GetMostActiveUsers = conn.runInstalledQuery("getMostActiveUsers")[0]["Result"]
usrSorted = sorted(GetMostActiveUsers, key=lambda i: i['valueStars'], reverse=True)
UserStarsList = usrSorted[:20]

# repo Count