joshdavham commited on
Commit
7ce5cb1
·
1 Parent(s): 1f1f5dd

add sps vs wpm scatter plot

Browse files
Files changed (1) hide show
  1. app.py +102 -0
app.py CHANGED
@@ -175,6 +175,108 @@ else:
175
 
176
  st.altair_chart(layered_chart, use_container_width=True)
177
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
178
  # word coverage chart
179
 
180
  def get_word_coverage_chart():
 
175
 
176
  st.altair_chart(layered_chart, use_container_width=True)
177
 
178
+ # wpm vs sps chart
179
+
180
+ def get_wpm_vs_sps_chart(interactive=False):
181
+
182
+ selection = alt.selection_point(fields=['level'], bind='legend', on='click')
183
+
184
+ highlight = alt.selection_point(name="highlight", fields=['level'], on='mouseover', empty=False)
185
+
186
+ # Create the scatter plot
187
+ scatter_plot = alt.Chart(video_df).mark_circle(
188
+ cursor='pointer',
189
+ size=80,
190
+ ).encode(
191
+ x=alt.X(
192
+ 'wpm:Q',
193
+ scale=alt.Scale(domain=[30,215]),
194
+ title='Words per minute',
195
+ axis=alt.Axis(
196
+ labelFontSize=14,
197
+ titleFontSize=18,
198
+ #titleFont='Urbanist',
199
+ titleColor='black',
200
+ titleFontWeight='normal',
201
+ #titleFontStyle='italic',
202
+ titlePadding=20
203
+ )
204
+ ),
205
+ y=alt.Y(
206
+ 'sps:Q',
207
+ title='Syllables per second',
208
+ axis=alt.Axis(
209
+ labelFontSize=14,
210
+ titleFontSize=18,
211
+ #titleFont='Urbanist',
212
+ titleColor='black',
213
+ titleFontWeight='normal',
214
+ #titleFontStyle='italic',
215
+ titlePadding=20,
216
+ #tickCount=5
217
+ ),
218
+ ),
219
+ color=alt.Color(
220
+ 'level:N',
221
+ scale=alt.Scale(range=['#a5bee4', '#9ad6d8', '#c7aecd', '#dd9e9e']),
222
+ sort=['Complete Beginner', 'Beginner', 'Intermediate', 'Advanced'],
223
+ legend=alt.Legend(
224
+ title='CIJ Level',
225
+ titleFontSize=18,
226
+ titleFontWeight='bolder',
227
+ labelFontSize=16,
228
+ symbolType='circle',
229
+ symbolSize=200,
230
+ #symbolStrokeWidth=3,
231
+ orient='right',
232
+ direction='vertical',
233
+ #fillColor='black',
234
+ padding=10,
235
+ cornerRadius=5,
236
+ )
237
+ ),
238
+ tooltip=[
239
+ alt.Tooltip('video:N', title='Video number:'),
240
+ alt.Tooltip('level:N', title='Level:'),
241
+ alt.Tooltip('wpm:Q', title='WPM:'),
242
+ alt.Tooltip('sps:Q', title='SPS:'),
243
+
244
+ ],
245
+ opacity=alt.condition(selection, alt.value(1.0), alt.value(0.2)),
246
+ #strokeWidth=alt.condition(selection | highlight, alt.value(6), alt.value(2))
247
+ ).properties(
248
+ width='container',
249
+ height=500,
250
+ title=alt.TitleParams(
251
+ text='Rate of speech: Syllables per second vs. words per minute',
252
+ offset=20,
253
+ #subtitle='(clickable)',
254
+ #font='Urbanist',
255
+ fontSize=24,
256
+ fontWeight='normal',
257
+ anchor='middle',
258
+ color='black',
259
+ subtitleFontSize=15,
260
+ subtitleColor='gray'
261
+ )
262
+ ).add_params(
263
+ selection,
264
+ highlight
265
+ )
266
+
267
+ # Display the plot
268
+ if interactive:
269
+ return scatter_plot.interactive()
270
+ else:
271
+ return scatter_plot
272
+
273
+ if st.checkbox('Enable zooming and panning ( ↕ / ↔️ )'):
274
+ wpm_vs_sps_chart = get_wpm_vs_sps_chart(interactive=True)
275
+ else:
276
+ wpm_vs_sps_chart = get_wpm_vs_sps_chart(interactive=False)
277
+
278
+ st.altair_chart(wpm_vs_sps_chart, use_container_width=True)
279
+
280
  # word coverage chart
281
 
282
  def get_word_coverage_chart():