Ejemplo n.º 1
0
def fun3():
    results2 = conn.runInstalledQuery("allConnection", params={'p': pat_id})
    df2 = pd.DataFrame(results2)
    data2 = flat_table.normalize(df2)  # Cleaning uo the data
    #g2 = graphistry.bind(source='@@edgeList.from_id', destination='@@edgeList.to_id').edges(data2)
    #iframe_url2 = g2.plot(render=False)
    return data2
Ejemplo n.º 2
0
def fun1():
    results = conn.runInstalledQuery("edgeCrawl")
    df = pd.DataFrame(results)
    data = flat_table.normalize(df)  # Cleaning uo the data
    #st.write(data)
    g = graphistry.bind(source='@@edgeList.from_id',
                        destination='@@edgeList.to_id').edges(data)
    iframe_url = g.plot(render=False)
    return iframe_url
Ejemplo n.º 3
0
def load_national_timeseries(download: bool = False) -> pd.DataFrame:
    print(":: loading case timeseries data")
    if download:
        download_data(data, 'timeseries.json',
                      "https://api.covid19india.org/v3/")
    with (data / 'timeseries.json').open("rb") as fp:
        df = flat_table.normalize(pd.read_json(fp)).fillna(0)
    df.columns = df.columns.str.split('.', expand=True)
    dates = np.squeeze(df["index"][None].values)
    return df.drop(columns="index",
                   level=0).set_index(dates).stack([1, 2]).drop("UN", axis=1)
Ejemplo n.º 4
0
def fun2():
    results4 = conn.runInstalledQuery("st2", params={'p': pat_id})
    df = pd.DataFrame(results4)
    if (bool(df['S1'][0][0]['attributes']["S1.@Loc"])):
        data = flat_table.normalize(df)
        data['lat'] = data['*****@*****.**']
        data['lon'] = data['*****@*****.**']
        return data

    else:
        st.error('No coordinates, choose another patient ID')
        st.stop()
Ejemplo n.º 5
0
 def __to_dataframe(self, raw_data):
   '''
     Converts the json raw data into a dataframe
   '''
   # Flatten json object
   df = pd.DataFrame(raw_data)
   
   #if the df is empty
   if(df.size == 0):
     return pd.DataFrame()
   df = flat_table.normalize(df)
   return df
Ejemplo n.º 6
0
def installedQuery(graph):
    """ 
    Prompts the user to choose an installed query, define its arguments, and choose the display format 
    
    :param graph: instance of TigerGraphConnection
    :type graph: TigerGraphConnection
    """

    st.header("Run an Installed Query")
    st.write(
        "Run any queries currently installed on the graph database. Pick a query, define arguments on-the-fly, and choose how to display the output."
    )

    # st.subheader("Currently Installed Queries")
    # st.json(graph.getInstalledQueries())
    installed = graph.getInstalledQueries()
    names = installed.keys()

    st.subheader("Choose an Installed Query")
    command = st.selectbox("Query", list(names))

    # get arguments from user
    st.subheader("Define arguments")
    temp = installed[command]["parameters"].keys()
    temp = list(filter(lambda p: p != "query", temp))
    args = {key: None for key in temp}
    for i in range(0, len(temp)):
        p = temp[i]
        ptype = installed[command]["parameters"][p]["type"]
        if (ptype == "INT64"):
            args[p] = st.number_input(f"{p}: {ptype}",
                                      min_value=int(-(1 << 53) + 1),
                                      max_value=int((1 << 53) - 1),
                                      value=0,
                                      step=1,
                                      key=i)
        elif (ptype == "STRING"):
            args[p] = st.text_input(f"{p}: {ptype}", value="blank", key=i)

    st.header("Output")
    data_format = st.selectbox("Output Format", ["JSON", "Table"])
    if st.button("Run Query"):
        query = graph.runInstalledQuery(command[17:],
                                        args)  # returns JSON object
        if data_format == "JSON":
            st.json(query)
        elif data_format == "Table":
            df = pd.DataFrame(query[0][list(query[0].keys())[0]])
            data = flat_table.normalize(df)
            st.table(data)
Ejemplo n.º 7
0
def nums():
    results6 = conn.runInstalledQuery("allConnection", params={'p': pat_id})
    df = pd.DataFrame(results6)
    data = flat_table.normalize(df)
    #data['lat']=data['*****@*****.**']
    #data['lon']=data['*****@*****.**']
    #d3=data
    #d3
    index_to_drop = data[data['@@edgeList.to_type'] != 'Patient'].index
    data.drop(index_to_drop, inplace=True)

    numeros = data['@@edgeList.to_id']
    numeros.drop_duplicates(keep=False, inplace=True)
    #numeros=numeros.astype(int)
    numeros = numeros.to_list()
    return numeros
Ejemplo n.º 8
0
def customQuery(graph):
    """ 
    Prompts the user to write a custom query, define its arguments, and choose the display format 

    :param graph: instance of TigerGraphConnection
    :type graph: TigerGraphConnection
    """

    st.header("Write a Custom Query")
    st.write(
        "Write an interpreted GSQL query to the database, define arguments, and choose how ot display the output."
    )
    st.markdown(
        "**Note: Start the query with 'INTERPRET QUERY () FOR GRAPH $graphname { }**"
    )
    custom = st.text_area(
        "Write a Query",
        '''INTERPRET QUERY (STRING str, INT num) FOR GRAPH $graphname {
        PRINT str;
        PRINT num;
    }
    ''',
        height=250)
    args = st.text_input("Enter list of arguments separated with '&'",
                         "str=nothing&num=25")

    st.header("Output")
    data_format = st.selectbox("Output Format", ["JSON", "Table"])
    if st.button("Run Query"):
        query = query = graph.runInterpretedQuery(custom,
                                                  args)  # returns JSON object
        if data_format == "JSON":
            st.json(query)
        elif data_format == "Table":
            df = pd.DataFrame(query[0],
                              index=[x for x in range(0, len(query[0]))])
            data = flat_table.normalize(df)
            st.table(data)
from scipy.stats import expon as Exponential, gamma as Gamma

data, _ = setup()

# load population data
india_pop = pd.read_csv(data / "india_pop.csv",
                        names=["state", "population"],
                        index_col="state").to_dict()["population"]
india_pop["India"] = sum(india_pop.values())
india_pop["Odisha"] = india_pop["Orissa"]
india_pop["Puducherry"] = india_pop["Pondicherry"]
india_pop["Uttarakhand"] = india_pop["Uttaranchal"]

# load case data
with (data / 'timeseries.json').open("rb") as fp:
    df = flat_table.normalize(pd.read_json(fp)).fillna(0)
df.columns = df.columns.str.split('.', expand=True)
dates = np.squeeze(df["index"][None].values)
df = df.drop(columns="index").set_index(dates).stack([1, 2]).drop("UN", axis=1)

state = "KA"
# state = "TN"
# state = "TT"

# assemble observation matrix
obs = pd.concat([
    df[state][:, "delta", "tested"], df[state][:, "delta", "confirmed"],
    df[state][:, "delta", "recovered"], df[state][:, "delta", "deceased"]
],
                axis=1)
obs.columns = ["tested", "confirmed", "recovered", "deceased"]
Ejemplo n.º 10
0
    numeros.drop_duplicates(keep=False, inplace=True)
    #numeros=numeros.astype(int)
    numeros = numeros.to_list()
    return numeros


#-----------------actualiza coord--------------------------
numeros = nums()

options = st.sidebar.selectbox('select contact', numeros)
results5 = conn.runInstalledQuery("st2", params={'p': int(options)})

df5 = pd.DataFrame(results5)

if (bool(df5['S1'][0][0]['attributes']["S1.@Loc"])):
    data = flat_table.normalize(df5)
    data['lat'] = data['*****@*****.**']
    data['lon'] = data['*****@*****.**']
    d4 = data
    d3 = d3.append(d4)

#d3

#-----------------actualiza coord--------------------------

fig = px.scatter_mapbox(d3,
                        lat=d3['lat'],
                        lon=d3['lon'],
                        opacity=0.4,
                        color=d3['S1.v_id'],
                        size=d3['index'] + 1)
Ejemplo n.º 11
0
def load_count(data):
    df = json_normalize(data)
    table = flat_table.normalize(df)
    table.drop(columns=['index'], inplace=True)
    return table
Ejemplo n.º 12
0
# %%
request_url = utils.generate_auth_url()
pyperclip.copy(request_url)

# %%
token = utils.url_get_token(input("Enter authorized url"))
print(token)
pyperclip.copy(token)

# %%
# Get library
df = pd.DataFrame(
    utils.spotify_track_pager_add_audio_features(
        token=token, track_pager_url=utils.library_url
    )
)
df = flat_table.normalize(df=df, expand_dicts=True, expand_lists=False)

# %%
names = df["user.display_name"].unique()
if len(names) == 1:
    name = names[0]
else:
    raise Exception

# %%
df.to_hdf(path_or_buf="archive.hdf", key=f"{name}-Library-{datetime.now().isoformat()}")

# %%
Ejemplo n.º 13
0
from bokeh.plotting import figure
import plotly.express as px
import plotly.graph_objects as go


st.title('Dynamically Visualize South Korea COVID-19 data using TigerGraph and Streamlit')

min_age, max_age = st.slider("Select Age Range", 0, 104, [10, 20])
sex = st.multiselect('Sex', ['male', 'female'])


results = graph.runInstalledQuery("streamlit")

df = pd.DataFrame(results[0]["s2"])

data = flat_table.normalize(df) # Cleaning uo the data
data = data[['v_id', 'attributes.Age', 'attributes.Sex', 'attributes.Location.latitude', 'attributes.Location.longitude']] 
if(len(sex)==1): # Filtering the data based on the sex filter input
    data = data[data['attributes.Sex']==sex[0]] 

data = data[data['attributes.Age'].between(left=min_age, right=max_age)] # Filtering the data based on age input

# grabbing location data for map 
locations = data[['attributes.Location.latitude', 'attributes.Location.longitude']] 
locations = locations.rename({'attributes.Location.latitude': 'lat', 'attributes.Location.longitude': 'lon'}, axis=1)
st.map(locations) # Using the streamlit map widget with locations input

gender_data = data['attributes.Sex']
age = data['attributes.Age']
s = age.value_counts()
age = pd.DataFrame({'Age':s.index, 'Count':s.values})
Ejemplo n.º 14
0
 def run(self):
     data = json.load(open("temp.json"))
     df = json_normalize(data)
     table = flat_table.normalize(df)
     table.to_csv("labeled_data.csv", index=False)
Ejemplo n.º 15
0
# Create connection to TG Cloud
graph = tg.TigerGraphConnection(
            host="https://61af4f31021c449e85f690cbec28ef7a.i.tgcloud.io",
            graphname="MyGraph",
            apiToken="r72kccg1jaso02s8gn20fskgfnh7brim"
        )
# Query to grab all authors, publication doi, number of publications
parsAuth = graph.runInstalledQuery("AuthorSearchDash", {}, timeout=20000, sizeLimit=40000000)

# Query to grab publication doi, title, URL
parsPubs = graph.runInstalledQuery("GrabPubs", {}, timeout=20000, sizeLimit=40000000)

# Sort Publication data
df_pub = pd.DataFrame(parsPubs[0])
df1_pub = flat_table.normalize(df_pub)
df2_pub = df1_pub.rename(columns={'Pubs.attributes.Pubs.id': 'Doi',
                                  'Pubs.attributes.Pubs.pub_title': 'Title',
                                  'Pubs.attributes.Pubs.pub_url': 'URL'})
df3_pub = df2_pub[['Doi', 'Title', 'URL']]

# Sort Author data
df_auth = pd.DataFrame(parsAuth[0])
df1_auth = flat_table.normalize(df_auth)
df2_auth = df1_auth.rename(columns={'Author.attributes.@pubNum': 'pubCount',
                                    'Author.attributes.author_name': 'Name',
                                    'Author.attributes.@pubList': 'Publications'})
df3_auth = df2_auth[['index', 'Name', 'pubCount', 'Publications']]

# Create lists to easily access data
temp_list = set()             # Set of author names