Last active
July 20, 2021 21:18
-
-
Save mneedham/8db353cca747ea1e0129e82c41fb3881 to your computer and use it in GitHub Desktop.
Streamlit/Pinot - dynamic selection of metric and time range
This file contains 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
import streamlit as st | |
from pinotdb import connect | |
import pandas as pd | |
import time | |
st.title("GitHub Events") | |
broker_port = 8000 | |
conn = connect(host='localhost', port=broker_port, path='/query/sql', scheme='http') | |
metrics = [ | |
"count(*)", "sum(numCommits)", | |
"sum(numLinesAdded)", "sum(numLinesDeleted)", | |
"sum(numFilesChanged)", "sum(numReviewComments)", | |
"avg(numReviewers)" | |
] | |
time_range = { | |
"All events": round(time.time() * 1000), | |
"Last week": 7*24*60, | |
"Last day": 24*60, | |
"Last 12 hours": 12*60, | |
"Last hour": 60 | |
} | |
st.header("Most active repositories") | |
with st.form(key='searchForm'): | |
metric = st.selectbox('Select a metric:', metrics) | |
timestamp = st.selectbox('Select time range:', list(time_range.keys())) | |
submit_button = st.form_submit_button(label='Refresh') | |
query = f""" | |
select organization, repo, {metric} | |
from pullRequestMergedEvents | |
where createdTimeMillis > cast((now() - %(subtract_time)d*1000*60) as long) | |
group by organization, repo | |
order by {metric} DESC | |
limit 10 | |
""" | |
curs = conn.cursor() | |
curs.execute(query, {"subtract_time": time_range[timestamp]}) | |
st.table(pd.DataFrame(curs, columns=[item[0] for item in curs.description])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment