Commit ·
1c61d89
1
Parent(s): bd89273
add urbanist font to charts
Browse files
app.py
CHANGED
|
@@ -1,27 +1,167 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
-
import numpy as np
|
| 3 |
import pandas as pd
|
| 4 |
-
import
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
st.title("CIJ by the numbers")
|
| 7 |
|
| 8 |
st.markdown("[Comprehensible Japanese (CIJ)](https://cijapanese.com/) is a \
|
| 9 |
video platform for learning Japanese.")
|
| 10 |
|
| 11 |
-
|
| 12 |
|
| 13 |
# Plot the WPM histogram
|
| 14 |
-
levels = list(df['level'].unique())
|
| 15 |
-
colors = ['red', 'green', 'blue', 'yellow']
|
| 16 |
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
ax.set_ylabel("Frequency")
|
| 26 |
|
| 27 |
-
st.
|
|
|
|
| 1 |
import streamlit as st
|
|
|
|
| 2 |
import pandas as pd
|
| 3 |
+
import altair as alt
|
| 4 |
+
|
| 5 |
+
st.markdown("""
|
| 6 |
+
<link href="https://fonts.googleapis.com/css2?family=Urbanist:wght@400;700&display=swap" rel="stylesheet">
|
| 7 |
+
<style>
|
| 8 |
+
.vega-embed * {
|
| 9 |
+
font-family: 'Urbanist', sans-serif;
|
| 10 |
+
}
|
| 11 |
+
</style>
|
| 12 |
+
""", unsafe_allow_html=True)
|
| 13 |
|
| 14 |
st.title("CIJ by the numbers")
|
| 15 |
|
| 16 |
st.markdown("[Comprehensible Japanese (CIJ)](https://cijapanese.com/) is a \
|
| 17 |
video platform for learning Japanese.")
|
| 18 |
|
| 19 |
+
video_df = pd.read_csv("video_data.tsv", sep="\t")
|
| 20 |
|
| 21 |
# Plot the WPM histogram
|
|
|
|
|
|
|
| 22 |
|
| 23 |
+
# Data for vertical lines corresponding to each level
|
| 24 |
+
line_data = pd.DataFrame({
|
| 25 |
+
'x': [75, 91, 124, 149],
|
| 26 |
+
'level': ['Complete Beginner', 'Beginner', 'Intermediate', 'Advanced'],
|
| 27 |
+
'text': ['Complete Beginner', 'Beginner', 'Intermediate', 'Advanced']
|
| 28 |
+
})
|
| 29 |
+
|
| 30 |
+
selection = alt.selection_point(fields=['level'], bind='legend', on='click')
|
| 31 |
+
|
| 32 |
+
highlight = alt.selection_point(name="highlight", fields=['level'], on='mouseover', empty=False)
|
| 33 |
+
|
| 34 |
+
histogram = alt.Chart(video_df).mark_bar(
|
| 35 |
+
opacity=0.5,
|
| 36 |
+
binSpacing=3,
|
| 37 |
+
stroke='black',
|
| 38 |
+
strokeWidth=0,
|
| 39 |
+
cornerRadius=5,
|
| 40 |
+
cursor="pointer"
|
| 41 |
+
).encode(
|
| 42 |
+
alt.X(
|
| 43 |
+
'wpm:Q',
|
| 44 |
+
bin=alt.Bin(maxbins=20),
|
| 45 |
+
title='Words per minute',
|
| 46 |
+
axis=alt.Axis(
|
| 47 |
+
labelFontSize=14,
|
| 48 |
+
titleFontSize=18,
|
| 49 |
+
titleFont='Urbanist',
|
| 50 |
+
titleColor='black',
|
| 51 |
+
titleFontWeight='normal',
|
| 52 |
+
#titleFontStyle='italic',
|
| 53 |
+
titlePadding=20
|
| 54 |
+
)
|
| 55 |
+
),
|
| 56 |
+
alt.Y(
|
| 57 |
+
'count()',
|
| 58 |
+
title="Num. videos",
|
| 59 |
+
axis=alt.Axis(
|
| 60 |
+
labelFontSize=14,
|
| 61 |
+
titleFontSize=18,
|
| 62 |
+
titleFont='Urbanist',
|
| 63 |
+
titleColor='black',
|
| 64 |
+
titleFontWeight='normal',
|
| 65 |
+
#titleFontStyle='italic',
|
| 66 |
+
titlePadding=20,
|
| 67 |
+
tickCount=5
|
| 68 |
+
),
|
| 69 |
+
scale=alt.Scale(domain=[0,100])
|
| 70 |
+
).stack(None),
|
| 71 |
+
alt.Color(
|
| 72 |
+
'level:N',
|
| 73 |
+
scale=alt.Scale(range=['#a5bee4', '#9ad6d8', '#c7aecd', '#dd9e9e']),
|
| 74 |
+
sort=['Complete Beginner', 'Beginner', 'Intermediate', 'Advanced'],
|
| 75 |
+
legend=alt.Legend(
|
| 76 |
+
title='CIJ Level',
|
| 77 |
+
titleFont='Urbanist',
|
| 78 |
+
titleFontSize=18,
|
| 79 |
+
titleFontWeight='bolder',
|
| 80 |
+
labelFontSize=16,
|
| 81 |
+
labelFont='Urbanist',
|
| 82 |
+
symbolType='circle',
|
| 83 |
+
symbolSize=200,
|
| 84 |
+
orient='right',
|
| 85 |
+
direction='vertical',
|
| 86 |
+
fillColor='white',
|
| 87 |
+
padding=10,
|
| 88 |
+
cornerRadius=5,
|
| 89 |
+
)
|
| 90 |
+
),
|
| 91 |
+
tooltip=[
|
| 92 |
+
alt.Tooltip('wpm:Q', title='Words per minute:', bin=True), # Properly indicate that `wpm` is binned
|
| 93 |
+
alt.Tooltip('level:N', title='Level:'),
|
| 94 |
+
alt.Tooltip('count()', title='Video count:')
|
| 95 |
+
],
|
| 96 |
+
opacity=alt.condition(selection, alt.value(0.75), alt.value(0.1)),
|
| 97 |
+
strokeWidth=alt.condition(highlight, alt.value(2), alt.value(1))
|
| 98 |
+
).properties(
|
| 99 |
+
#width=750,
|
| 100 |
+
#width='container',
|
| 101 |
+
#height='container',
|
| 102 |
+
#background='beige',
|
| 103 |
+
#padding=50,
|
| 104 |
+
title=alt.TitleParams(
|
| 105 |
+
text='Rate of speech in words per minute (WPM)',
|
| 106 |
+
offset=20,
|
| 107 |
+
#subtitle='(clickable)',
|
| 108 |
+
font='Urbanist',
|
| 109 |
+
fontSize=24,
|
| 110 |
+
fontWeight='normal',
|
| 111 |
+
anchor='middle',
|
| 112 |
+
color='black',
|
| 113 |
+
subtitleFontSize=15,
|
| 114 |
+
subtitleColor='gray'
|
| 115 |
+
)
|
| 116 |
+
).add_params(
|
| 117 |
+
selection,
|
| 118 |
+
highlight
|
| 119 |
+
)
|
| 120 |
+
|
| 121 |
+
# Vertical lines corresponding to each level
|
| 122 |
+
vertical_lines = alt.Chart(line_data).mark_rule(
|
| 123 |
+
color='red',
|
| 124 |
+
strokeWidth=6,
|
| 125 |
+
strokeDash = [5, 4], # first arg is length, second is gap
|
| 126 |
+
).encode(
|
| 127 |
+
x='x:Q',
|
| 128 |
+
tooltip=[
|
| 129 |
+
alt.Tooltip('x:N', title='Median WPM:'),
|
| 130 |
+
alt.Tooltip('level:N', title='Level:')
|
| 131 |
+
],
|
| 132 |
+
#color=alt.condition(select, 'level:N', alt.value('gray')), # Link the color with the selection
|
| 133 |
+
color=alt.Color(
|
| 134 |
+
'level:N',
|
| 135 |
+
scale=alt.Scale(range=['red', 'green', 'blue', 'yellow']), # Use the same color scale as the histogram
|
| 136 |
+
sort=['Complete Beginner', 'Beginner', 'Intermediate', 'Advanced'],
|
| 137 |
+
legend=None # No legend for lines, it is already shown in the histogram
|
| 138 |
+
),
|
| 139 |
+
opacity=alt.condition(selection, alt.value(1.0), alt.value(0.1)), # Link opacity with selection
|
| 140 |
+
strokeWidth=alt.condition(highlight, alt.value(20), alt.value(1))
|
| 141 |
+
).add_params(
|
| 142 |
+
selection,
|
| 143 |
+
highlight
|
| 144 |
+
)
|
| 145 |
|
| 146 |
+
text_labels = alt.Chart(line_data).mark_text(
|
| 147 |
+
align='left', # Align text to the left of the line
|
| 148 |
+
dx=5, # Offset the text to the right by 5 pixels
|
| 149 |
+
dy=-5, # Adjust vertical positioning
|
| 150 |
+
fontSize=16,
|
| 151 |
+
fontWeight='bold'
|
| 152 |
+
).encode(
|
| 153 |
+
x='x:Q',
|
| 154 |
+
y=alt.value(0), # Positioning y at the top of the chart, can be adjusted as needed
|
| 155 |
+
text=alt.Text('x:Q', format='.0f'), # Display the x value, formatted as an integer
|
| 156 |
+
color=alt.Color(
|
| 157 |
+
'level:N',
|
| 158 |
+
scale=alt.Scale(range=['red', 'green', 'blue', 'orange']),
|
| 159 |
+
sort=['Complete Beginner', 'Beginner', 'Intermediate', 'Advanced'],
|
| 160 |
+
legend=None
|
| 161 |
+
)
|
| 162 |
+
)
|
| 163 |
|
| 164 |
+
#layered_chart = alt.layer(histogram, background='#f6f8fb')
|
| 165 |
+
layered_chart = alt.layer(histogram, vertical_lines, text_labels, background='#f6f8fb')
|
|
|
|
| 166 |
|
| 167 |
+
st.altair_chart(layered_chart, use_container_width=True)
|