-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #34 from GTBitsOfGood/Wonho/CustomEventGraphs
Implemented Custom Events Graph
- Loading branch information
Showing
4 changed files
with
51 additions
and
8 deletions.
There are no files selected for viewing
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
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
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
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 |
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