Improve charting for admin
parent
350b719db9
commit
500466aca9
|
|
@ -16,7 +16,7 @@ def query_data():
|
|||
df = conn.sql(
|
||||
"""
|
||||
SELECT
|
||||
date_trunc('hour', to_timestamp(CAST(created AS int64))) AS Date,
|
||||
date_trunc('day', to_timestamp(CAST(created AS int64))) AS Date,
|
||||
SUM(IF(view, 1, 0)) as "Views",
|
||||
SUM(IF("select", 1, 0)) as "Acceptances"
|
||||
FROM completion_events
|
||||
|
|
@ -30,12 +30,36 @@ def query_data():
|
|||
|
||||
df = query_data()
|
||||
|
||||
if len(df) > 0:
|
||||
|
||||
def plot_summary():
|
||||
sum_views = int(sum(df.Views))
|
||||
sum_acceptances = int(sum(df.Acceptances))
|
||||
ratio = (sum_acceptances / sum_views) * 100
|
||||
|
||||
col1, col2, col3 = st.columns(3)
|
||||
|
||||
with col1:
|
||||
st.metric("Views", sum_views)
|
||||
with col2:
|
||||
st.metric("Acceptances", sum_acceptances)
|
||||
with col3:
|
||||
st.metric("Accept Ratio", f"{round(ratio)} %")
|
||||
|
||||
|
||||
plot_summary()
|
||||
st.write("---")
|
||||
|
||||
|
||||
def plot_charts():
|
||||
st.markdown("### Completion Events")
|
||||
st.line_chart(df, x="Date")
|
||||
|
||||
st.markdown("### Acceptance Rate")
|
||||
df["Acceptance Rate"] = df["Acceptances"] / df["Views"]
|
||||
st.line_chart(df, x="Date", y="Acceptance Rate")
|
||||
|
||||
|
||||
if len(df) > 0:
|
||||
plot_charts()
|
||||
else:
|
||||
st.markdown("No data available")
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import os
|
||||
from pathlib import Path
|
||||
|
||||
import pandas as pd
|
||||
import streamlit as st
|
||||
import toml
|
||||
from datasets import load_from_disk
|
||||
|
|
@ -12,27 +13,42 @@ dataset_dir = os.environ.get("DATASET_DIR", None)
|
|||
git_repositories_dir = os.environ.get("GIT_REPOSITORIES_DIR", None)
|
||||
config_file = os.environ.get("CONFIG_FILE", None)
|
||||
config = toml.load(config_file)
|
||||
projects = config.get("projects", {})
|
||||
|
||||
|
||||
def count_by_language(dataset):
|
||||
key = "language"
|
||||
df = (
|
||||
pd.DataFrame(dataset[key], columns=[key])
|
||||
.groupby([key])
|
||||
.size()
|
||||
.to_frame("# Files")
|
||||
)
|
||||
return df
|
||||
|
||||
|
||||
def dataset_info():
|
||||
st.subheader("Dataset")
|
||||
if not Path(dataset_dir).is_dir():
|
||||
st.write("*Not populated*")
|
||||
st.write("*n/a*")
|
||||
return
|
||||
|
||||
info = load_from_disk(dataset_dir)
|
||||
st.write("Source files: ", len(info))
|
||||
dataset = load_from_disk(dataset_dir)
|
||||
|
||||
col1, col2 = st.columns(2)
|
||||
with col1:
|
||||
st.metric("Total files", len(dataset))
|
||||
|
||||
with col2:
|
||||
st.bar_chart(count_by_language(dataset))
|
||||
|
||||
|
||||
def project_list():
|
||||
data = config.get("projects", {})
|
||||
|
||||
if len(data) <= 0:
|
||||
if len(projects) <= 0:
|
||||
st.write("Your project list is empty")
|
||||
st.write(f"Edit `{config_file}` to add projects")
|
||||
return
|
||||
|
||||
for k, v in data.items():
|
||||
for k, v in projects.items():
|
||||
st.subheader(k)
|
||||
st.write(f'Git: {v["git_url"]}')
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue