Skip to content

Commit

Permalink
Add word counts
Browse files Browse the repository at this point in the history
  • Loading branch information
ColinDaglish committed Oct 18, 2023
1 parent 1ab6d3a commit 511201f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/modules/word_counts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import plotly.graph_objects as go
from matplotlib.figure import Figure
from pandas import Series

Check warning on line 3 in src/modules/word_counts.py

View check run for this annotation

Codecov / codecov/patch

src/modules/word_counts.py#L1-L3

Added lines #L1 - L3 were not covered by tests


def plot_word_counts(data: Series) -> Figure:

Check warning on line 6 in src/modules/word_counts.py

View check run for this annotation

Codecov / codecov/patch

src/modules/word_counts.py#L6

Added line #L6 was not covered by tests
"""Create a word count boxplot
Parameters
----------
data : Series
a series of word counts corrosponding to the original data
Returns
-------
Figure
a boxplot of word counts for the responses
"""
fig = go.Figure()
fig.add_trace(go.Box(x=data, name=""))
fig.update_layout(title=go.layout.Title(text="Response word counts"), height=300)

Check warning on line 21 in src/modules/word_counts.py

View check run for this annotation

Codecov / codecov/patch

src/modules/word_counts.py#L19-L21

Added lines #L19 - L21 were not covered by tests

return fig

Check warning on line 23 in src/modules/word_counts.py

View check run for this annotation

Codecov / codecov/patch

src/modules/word_counts.py#L23

Added line #L23 was not covered by tests
7 changes: 7 additions & 0 deletions streamlit_app.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import re
import warnings
from collections import Counter
from datetime import datetime as dt

Check warning on line 4 in streamlit_app.py

View check run for this annotation

Codecov / codecov/patch

streamlit_app.py#L3-L4

Added lines #L3 - L4 were not covered by tests

import numpy as np
Expand All @@ -14,6 +15,7 @@
from src.modules import spell_correct as spell
from src.modules import streamlit as stream
from src.modules import topic_modelling as topic
from src.modules import word_counts

Check warning on line 18 in streamlit_app.py

View check run for this annotation

Codecov / codecov/patch

streamlit_app.py#L18

Added line #L18 was not covered by tests
from src.modules.config import Config

# Page configuration
Expand Down Expand Up @@ -210,6 +212,8 @@
spell_checker = spell.update_spell_dictionary(config["spelling"])
raw_series = raw_data[question]

Check warning on line 213 in streamlit_app.py

View check run for this annotation

Codecov / codecov/patch

streamlit_app.py#L213

Added line #L213 was not covered by tests
response_char_lengths = prep.get_response_length(raw_series)
response_word_counts = pd.Series([len(Counter(x.split())) for x in raw_series])
word_counts_fig = word_counts.plot_word_counts(response_word_counts)

Check warning on line 216 in streamlit_app.py

View check run for this annotation

Codecov / codecov/patch

streamlit_app.py#L215-L216

Added lines #L215 - L216 were not covered by tests
average_response_char_length = response_char_lengths.mean()
# Cleaning
no_ans_removed = prep.remove_no_answer(raw_series)
Expand Down Expand Up @@ -278,6 +282,9 @@
st.metric("Question Responses", len(spelling_fixed))

Check warning on line 282 in streamlit_app.py

View check run for this annotation

Codecov / codecov/patch

streamlit_app.py#L282

Added line #L282 was not covered by tests
with a2:
st.metric("Total Responses", len(raw_data))

Check warning on line 284 in streamlit_app.py

View check run for this annotation

Codecov / codecov/patch

streamlit_app.py#L284

Added line #L284 was not covered by tests

container = st.container()
container.plotly_chart(word_counts_fig)

Check warning on line 287 in streamlit_app.py

View check run for this annotation

Codecov / codecov/patch

streamlit_app.py#L286-L287

Added lines #L286 - L287 were not covered by tests
st.divider()

# Topic Word Dataframe configuration
Expand Down

0 comments on commit 511201f

Please sign in to comment.