Last active
October 16, 2022 16:43
-
-
Save leeadh/26241547770a7235b2c20b5431dab316 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""This application experiments with the (grid) layout and some styling | |
Can we make a compact drequesthboard across several columns and with a dark theme?""" | |
from typing import List, Optional | |
import uuid | |
import snowflake.connector | |
import markdown | |
import pandas as pd | |
import streamlit as st | |
from plotly import express as px | |
from sql import * | |
@st.experimental_singleton | |
def init_connection(): | |
return snowflake.connector.connect(**st.secrets["snowflake"]) | |
def run_query(query): | |
conn = init_connection() | |
with conn.cursor() as cur: | |
cur.execute(query) | |
return cur.fetch_pandas_all() | |
def set_detail_session(rowdetails): | |
st.session_state.page = "Details" | |
st.session_state.pageitem =rowdetails | |
def render_tiles(row): | |
with st.expander("", expanded=True): | |
st.image("../images/automation.png", width=100) | |
st.header("βοΈ Block No. " + str(row['BLOCK_NUMBER']) ) | |
st.markdown("""<span style="word-wrap:break-word;">Block Hash: """"" + str(row['BLOCK_HASH'])+ """</span>""", unsafe_allow_html=True ) | |
st.markdown("""<span style="word-wrap:break-word;">TX Hash: """"" + str(row['TX_HASH'])+ """</span>""", unsafe_allow_html=True ) | |
if row['EVENT_TYPE'] is None: | |
with st.container(): | |
st.subheader("π Contract") | |
st.error("Contract Event: No Contract Event") | |
st.error("Product ID: "+ str(row['PRODUCT_ID'])) | |
st.error("Product Name: "+ str(row['PRODUCT_NAME']) ) | |
st.error("Product Price: "+ str(row['PRODUCT_PRICE']/1000000)) | |
st.subheader("π Address Details") | |
if row['ADDR_SENDER'] is None: | |
st.markdown("Sender address:") | |
st.markdown("""<span style="word-wrap:break-word;">""""" + "0x0000000000000000000000000000000000000000" + """</span>""", unsafe_allow_html=True ) | |
else: | |
st.markdown("Sender address:") | |
st.markdown("""<span style="word-wrap:break-word;">""""" + str(row['ADDR_SENDER'])+ """</span>""", unsafe_allow_html=True ) | |
if row['ADDR_RECEIVER'] is None: | |
st.markdown("Receiver address:") | |
st.markdown("""<span style="word-wrap:break-word;">""""" + "0x0000000000000000000000000000000000000000" + """</span>""", unsafe_allow_html=True ) | |
else: | |
st.markdown("Receiver address:") | |
st.markdown("""<span style="word-wrap:break-word;">""""" + str(row['ADDR_RECEIVER'])+ """</span>""", unsafe_allow_html=True ) | |
st.metric("Gas used", row['GAS_USED'], row['DIFF_GAS']) | |
else: | |
with st.container(): | |
st.subheader("π Contract") | |
st.info("Contract Event: " + row['EVENT_TYPE']) | |
st.info("Product ID: "+ str(row['PRODUCT_ID'])) | |
st.info("Product Name: "+ str(row['PRODUCT_NAME']) ) | |
st.info("Product Price: "+ str(row['PRODUCT_PRICE']/1000000)) | |
st.subheader("π Address Details") | |
if row['ADDR_SENDER'] is None: | |
st.markdown("Sender address:") | |
st.markdown("""<span style="word-wrap:break-word;">""""" + "0x0000000000000000000000000000000000000000" + """</span>""", unsafe_allow_html=True ) | |
else: | |
st.markdown("Sender address:") | |
st.markdown("""<span style="word-wrap:break-word;">""""" + str(row['ADDR_SENDER'])+ """</span>""", unsafe_allow_html=True ) | |
if row['ADDR_RECEIVER'] is None: | |
st.markdown("Receiver address:") | |
st.markdown("""<span style="word-wrap:break-word;">""""" + "0x0000000000000000000000000000000000000000" + """</span>""", unsafe_allow_html=True ) | |
else: | |
st.markdown("Receiver address:") | |
st.markdown("""<span style="word-wrap:break-word;">""""" + str(row['ADDR_RECEIVER'])+ """</span>""", unsafe_allow_html=True ) | |
st.metric("Gas used", row['GAS_USED'], row['DIFF_GAS']) | |
def render_catalogue(df): | |
for index, row in df.iterrows(): | |
num = index+1 | |
if num %5 ==1: | |
with col1: | |
render_tiles(row) | |
elif num %5 ==2: | |
with col2: | |
render_tiles(row) | |
elif num %5 ==3: | |
with col3: | |
render_tiles(row) | |
elif num %5 ==4: | |
with col4: | |
render_tiles(row) | |
elif num %5 ==0: | |
with col5: | |
render_tiles(row) | |
#df = pd.DataFrame(data) | |
st.set_page_config(layout="wide") | |
with open('../css/style.css') as f: | |
st.markdown(f'<style>{f.read()}</style>', unsafe_allow_html=True) | |
if 'page' not in st.session_state: | |
st.session_state.page = "Main" | |
if st.session_state.page=="Main": | |
catalogue_items = get_service_catalogue() | |
df = run_query(catalogue_items) | |
df['DIFF_GAS'] = df['GAS_USED'].diff() | |
col1, col2, col3, col4, col5 = st.columns(5, gap="medium") | |
df.reset_index(inplace=True) | |
render_catalogue(df) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment