Skip to content

Commit

Permalink
Merge pull request #34 from GTBitsOfGood/Wonho/CustomEventGraphs
Browse files Browse the repository at this point in the history
Implemented Custom Events Graph
  • Loading branch information
SamratSahoo authored Mar 1, 2024
2 parents da3721b + 3bb6297 commit e172989
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 8 deletions.
7 changes: 6 additions & 1 deletion dashboard/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
init_object_active_users_bar_graph,
)
from widgets.input_event_widgets import init_input_object_frequency_graph

from widgets.custom_event_graphs import init_plot_custom_graphs
from utils import EventTypes

st.title("Analytics Dashboard")
Expand Down Expand Up @@ -53,3 +53,8 @@
st.header("Input Events")
init_input_object_frequency_graph(st, input_events)
pass


custom_charts = init_plot_custom_graphs(custom_events, custom_graphs)
for chart in custom_charts:
st.altair_chart(chart, use_container_width=True)
10 changes: 5 additions & 5 deletions dashboard/widgets/click_event_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def init_object_click_bar_graph(st, click_events):
list(object_clicks.items()), columns=["Object Id", "Clicks"]
)

# Create the bar chart

chart = (
alt.Chart(df_visits)
.mark_bar()
Expand All @@ -25,7 +25,7 @@ def init_object_click_bar_graph(st, click_events):
.properties(width=600, height=400)
)

# Display the chart using Streamlit

st.altair_chart(chart, use_container_width=True)


Expand All @@ -45,9 +45,9 @@ def init_object_active_users_bar_graph(st, click_events):
pd.DataFrame(list(clicks_data.items()), columns=["User ID", "Clicks"])
.sort_values(by="Clicks", ascending=False)
.head(5)
) # Focus on top 5 users
)

# Create the bar chart

chart = (
alt.Chart(df_clicks)
.mark_bar()
Expand All @@ -58,5 +58,5 @@ def init_object_active_users_bar_graph(st, click_events):
.properties(width=600, height=400)
)

# Display the chart using Streamlit

st.altair_chart(chart, use_container_width=True)
39 changes: 39 additions & 0 deletions dashboard/widgets/custom_event_graphs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import streamlit as st
import pandas as pd
import altair as alt
from data import visit_events, click_events, input_events, custom_events, custom_graphs



def init_plot_custom_graphs(custom_events, custom_graphs):
charts = []
for graph in custom_graphs:
matching_events = [
event for event in custom_events
if event.category == graph.category and event.subcategory == graph.subcategory
]

data = {
"x": [event.event_properties[graph.xProperty] for event in matching_events],
"y": [event.event_properties[graph.yProperty] for event in matching_events],
}
df = pd.DataFrame(data)

base = alt.Chart(df).encode(
x=alt.X('x:Q', axis=alt.Axis(title=graph.xProperty)),
y=alt.Y('y:Q', axis=alt.Axis(title=graph.yProperty))
).properties(
title=f"Event Category: {graph.category} - Subcategory: {graph.subcategory}"
)

if graph.graphType == "bar":
chart = base.mark_bar().encode(
x=alt.X('x:N', axis=alt.Axis(title=graph.xProperty)))
elif graph.graphType == "line":
chart = base.mark_line()
elif graph.graphType == "scatter":
chart = base.mark_circle()

charts.append(chart)

return charts
3 changes: 1 addition & 2 deletions dashboard/widgets/visit_event_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ def init_page_active_users_graph(st, visit_events):
.head(5)
)

# Create the bar chart
chart = (
alt.Chart(df_user_visits)
.mark_bar()
Expand All @@ -91,7 +90,7 @@ def init_page_active_users_graph(st, visit_events):
.properties(width=600, height=400)
)

# Display the chart using Streamlit

st.altair_chart(chart, use_container_width=True)


Expand Down

0 comments on commit e172989

Please sign in to comment.