Skip to content

Commit

Permalink
remove snake case
Browse files Browse the repository at this point in the history
  • Loading branch information
SamratSahoo committed Mar 5, 2024
1 parent 145fdb0 commit 6080205
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 63 deletions.
52 changes: 26 additions & 26 deletions dashboard/scripts/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,59 +8,59 @@


class BaseEvent:
def __init__(self, event_properties, category, subcategory) -> None:
def __init__(self, eventProperties, category, subcategory) -> None:
self.category = category
self.subcategory = subcategory
self.event_properties = event_properties
self.eventProperties = eventProperties
self.createdAt = random.choice(possible_dates)


class VisitEventProperties:
def __init__(self, pageUrl, user_id) -> None:
def __init__(self, pageUrl, userId) -> None:
self.pageUrl = pageUrl
self.user_id = user_id
self.userId = userId


class VisitEvent(BaseEvent):
def __init__(
self, event_properties, category="Activity", subcategory="Visit"
self, eventProperties, category="Activity", subcategory="Visit"
) -> None:
super().__init__(event_properties, category, subcategory)
super().__init__(eventProperties, category, subcategory)


class ClickEventProperties:
def __init__(self, object_id, user_id) -> None:
self.object_id = object_id
self.user_id = user_id
def __init__(self, objectId, userId) -> None:
self.objectId = objectId
self.userId = userId


class ClickEvent(BaseEvent):
def __init__(
self, event_properties, category="Interaction", subcategory="Click"
self, eventProperties, category="Interaction", subcategory="Click"
) -> None:
super().__init__(event_properties, category, subcategory)
super().__init__(eventProperties, category, subcategory)


class InputEventProperties:
def __init__(self, object_id, user_id, text_value) -> None:
self.object_id = object_id
self.user_id = user_id
self.text_value = text_value
def __init__(self, objectId, userId, textValue) -> None:
self.objectId = objectId
self.userId = userId
self.textValue = textValue


class InputEvent(BaseEvent):
def __init__(
self, event_properties, category="Interaction", subcategory="Input"
self, eventProperties, category="Interaction", subcategory="Input"
) -> None:
super().__init__(event_properties, category, subcategory)
super().__init__(eventProperties, category, subcategory)


possible_custom_properties = [f"prop{i}" for i in range(0, 5)]


class CustomEvent(BaseEvent):
def __init__(self, event_properties, category, subcategory) -> None:
super().__init__(event_properties, category, subcategory)
def __init__(self, eventProperties, category, subcategory) -> None:
super().__init__(eventProperties, category, subcategory)


class CustomGraphType:
Expand All @@ -78,7 +78,7 @@ def __init__(self, category, subcategory, xProperty, yProperty, graphType) -> No
possible_buttons = [f"button_{i}" for i in range(0, 5)]
possible_inputs = [f"input_{i}" for i in range(0, 5)]
possible_users = [f"user_{i}" for i in range(0, 100)]
possible_text_values = [f"text_{i}" for i in range(0, 5)]
possible_textValues = [f"text_{i}" for i in range(0, 5)]

possible_custom_event_categories = [f"custom{i}" for i in range(0, 2)]
possible_custom_event_subcategories = [f"custom{i}" for i in range(0, 2)]
Expand All @@ -93,21 +93,21 @@ def __init__(self, category, subcategory, xProperty, yProperty, graphType) -> No
for i in range(0, 100):
visit_properties = VisitEventProperties(
pageUrl=random.choice(possible_urls),
user_id=random.choice(possible_users),
userId=random.choice(possible_users),
)
visit_events.append(VisitEvent(visit_properties))

click_properties = ClickEventProperties(
object_id=random.choice(possible_buttons),
user_id=random.choice(possible_users),
objectId=random.choice(possible_buttons),
userId=random.choice(possible_users),
)

click_events.append(ClickEvent(click_properties))

input_properties = InputEventProperties(
object_id=random.choice(possible_inputs),
user_id=random.choice(possible_users),
text_value=random.choice(possible_text_values),
objectId=random.choice(possible_inputs),
userId=random.choice(possible_users),
textValue=random.choice(possible_textValues),
)

input_events.append(InputEvent(input_properties))
Expand Down
22 changes: 9 additions & 13 deletions dashboard/widgets/click_event_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@ def init_object_click_bar_graph(st, click_events):
st.write("**Clicks Per Object Graph**")
object_clicks = defaultdict(int)
for click_event in click_events:
object_id = click_event.event_properties.object_id
object_clicks[object_id] += 1
objectId = click_event.eventProperties.objectId
object_clicks[objectId] += 1

df_visits = pd.DataFrame(
list(object_clicks.items()), columns=["Object Id", "Clicks"]
)


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


st.altair_chart(chart, use_container_width=True)


def init_object_active_users_bar_graph(st, click_events):
st.write("**User Clicks Per Object Graph**")
user_clicks_per_object = defaultdict(lambda: defaultdict(int))
for click_event in click_events:
object_id = click_event.event_properties.object_id
user_id = click_event.event_properties.user_id
user_clicks_per_object[object_id][user_id] += 1
objectId = click_event.eventProperties.objectId
userId = click_event.eventProperties.userId
user_clicks_per_object[objectId][userId] += 1

object_ids = list(user_clicks_per_object.keys())
selected_object_id = st.selectbox("Select an Object to inspect", object_ids)
objectIds = list(user_clicks_per_object.keys())
selected_objectId = st.selectbox("Select an Object to inspect", objectIds)

clicks_data = user_clicks_per_object[selected_object_id]
clicks_data = user_clicks_per_object[selected_objectId]
df_clicks = (
pd.DataFrame(list(clicks_data.items()), columns=["User ID", "Clicks"])
.sort_values(by="Clicks", ascending=False)
.head(5)
)
)


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


st.altair_chart(chart, use_container_width=True)
4 changes: 2 additions & 2 deletions dashboard/widgets/custom_event_graphs.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ def init_plot_custom_graphs(custom_events, custom_graphs):
]

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

Expand Down
32 changes: 17 additions & 15 deletions dashboard/widgets/input_event_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@

def init_input_object_frequency_graph(st, input_events):
st.write("**Input Object Frequency Graph**")
df = pd.DataFrame([vars(event.event_properties) for event in input_events])
df = pd.DataFrame([vars(event.eventProperties) for event in input_events])

object_counts = (
df["object_id"].value_counts().rename_axis("x").reset_index(name="y")
)
object_counts = df["objectId"].value_counts().rename_axis("x").reset_index(name="y")
object_counts = object_counts.sort_values(by="y", ascending=False)

chart = (
Expand All @@ -23,28 +21,32 @@ def init_input_object_frequency_graph(st, input_events):

st.altair_chart(chart, use_container_width=True)


def init_input_value_frequency_graph(st, input_events):
st.write("**Text Value Frequency Graph for Selected Object**")
df = pd.DataFrame([vars(event.event_properties) for event in input_events])
df = pd.DataFrame([vars(event.eventProperties) for event in input_events])

# create a select box for the user to select an object
unique_objects = df['object_id'].unique()
selected_object = st.selectbox('Select an Object', unique_objects)
filtered_df = df[df['object_id'] == selected_object]
unique_objects = df["objectId"].unique()
selected_object = st.selectbox("Select an Object", unique_objects)
filtered_df = df[df["objectId"] == selected_object]

# bar chart w/desc order of frequency of each unique TextValue
text_value_counts = (
filtered_df['text_value'].value_counts().rename_axis('text_value').reset_index(name='Frequency')
textValue_counts = (
filtered_df["textValue"]
.value_counts()
.rename_axis("textValue")
.reset_index(name="Frequency")
)
text_value_counts = text_value_counts.sort_values(by='Frequency', ascending=False)
textValue_counts = textValue_counts.sort_values(by="Frequency", ascending=False)

chart = (
alt.Chart(text_value_counts)
alt.Chart(textValue_counts)
.mark_bar()
.encode(
x=alt.X('text_value', axis=alt.Axis(title='Text Value')),
y=alt.Y('Frequency', axis=alt.Axis(title='Frequency')),
tooltip=['text_value', 'Frequency']
x=alt.X("textValue", axis=alt.Axis(title="Text Value")),
y=alt.Y("Frequency", axis=alt.Axis(title="Frequency")),
tooltip=["textValue", "Frequency"],
)
.properties(width=600, height=400)
)
Expand Down
14 changes: 7 additions & 7 deletions dashboard/widgets/visit_event_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ def init_recent_events_table(st, visit_events):
visit_sorted = sorted(visit_events, key=lambda event: event.createdAt)
data = [
{
"Page URL": event.event_properties.pageUrl,
"User ID": event.event_properties.user_id,
"Page URL": event.eventProperties.pageUrl,
"User ID": event.eventProperties.userId,
"Date": event.createdAt,
}
for event in visit_sorted
Expand All @@ -38,7 +38,7 @@ def init_page_visit_graph(st, visit_events):
st.write("**Page Visit Frequency Graph**")
page_visits = {}
for event in visit_events:
page_url = event.event_properties.pageUrl
page_url = event.eventProperties.pageUrl
if page_url in page_visits:
page_visits[page_url] += 1
else:
Expand All @@ -65,9 +65,9 @@ def init_page_active_users_graph(st, visit_events):
st.write("**Page Specific User Visit Frequency Graph**")
page_user_visits = defaultdict(lambda: defaultdict(int))
for event in visit_events:
page_url = event.event_properties.pageUrl
user_id = event.event_properties.user_id
page_user_visits[page_url][user_id] += 1
page_url = event.eventProperties.pageUrl
userId = event.eventProperties.userId
page_user_visits[page_url][userId] += 1

page_urls = list(page_user_visits.keys())
selected_page_url = st.selectbox("Select a Page to Inspect", page_urls)
Expand Down Expand Up @@ -97,7 +97,7 @@ def init_visitors_over_time_graph(st, visit_events):
st.write("**Visitors Over Time Graph**")
data = {
"Date": [event.createdAt for event in visit_events],
"pageUrl": [event.event_properties.pageUrl for event in visit_events],
"pageUrl": [event.eventProperties.pageUrl for event in visit_events],
"Number of Visitors": [1 for _ in visit_events],
}
df = pd.DataFrame(data)
Expand Down

0 comments on commit 6080205

Please sign in to comment.