duongthienz commited on
Commit
4ed414e
·
verified ·
1 Parent(s): 1a3edda

Re-order and rename the tabs, and adjust the content

Browse files
Files changed (1) hide show
  1. utils.py +22 -8
utils.py CHANGED
@@ -253,9 +253,9 @@ def build_df5(oneVoice, multiVoice, sumNoVoice, sumOneVoice, sumMultiVoice, curr
253
 
254
 
255
  def build_df2(df4_names, df4_values, currTotalTime):
256
- """Percentage-of-total DataFrame (used by the bar chart tab)."""
257
  return pd.DataFrame({
258
- "values": [100 * v / currTotalTime for v in df4_values],
259
  "names": df4_names,
260
  })
261
 
@@ -405,20 +405,34 @@ def build_fig_timeline(speakers_dataFrame, currTotalTime, speakerColors, get_dis
405
  return fig
406
 
407
 
 
 
 
 
 
 
 
 
 
408
  def build_fig_bar(df2, catColors, speakerColors, get_display_name_fn, currFile):
409
- """Horizontal bar chart — time spoken per speaker."""
410
  df2 = df2.copy()
411
- df2["names"] = df2["names"].apply(lambda s: get_display_name_fn(s, currFile))
 
412
  fig = px.bar(
413
  df2, x="values", y="names", color="names", orientation="h",
414
- custom_data=["names", "values"],
415
  title="Time Spoken by each Speaker",
416
  color_discrete_sequence=catColors + speakerColors,
417
  )
418
- fig.update_xaxes(ticksuffix="%")
 
 
 
 
419
  fig.update_yaxes(autorange="reversed")
420
  fig.update_layout(
421
- xaxis_title="Percentage Time Spoken",
422
  yaxis_title=None,
423
  showlegend=False,
424
  yaxis={"showticklabels": True},
@@ -426,7 +440,7 @@ def build_fig_bar(df2, catColors, speakerColors, get_display_name_fn, currFile):
426
  )
427
  fig.update_traces(hovertemplate="<br>".join([
428
  "<b>%{customdata[0]}</b>",
429
- "Percentage of Time: %{customdata[1]:.2f}%",
430
  ]))
431
  return fig
432
 
 
253
 
254
 
255
  def build_df2(df4_names, df4_values, currTotalTime):
256
+ """Time-spoken DataFrame (raw seconds) used by the bar chart tab."""
257
  return pd.DataFrame({
258
+ "values": list(df4_values),
259
  "names": df4_names,
260
  })
261
 
 
405
  return fig
406
 
407
 
408
+ def _seconds_to_hhmmss(seconds):
409
+ """Convert a float seconds value to a hh:mm:ss.ss string."""
410
+ seconds = float(seconds)
411
+ h = int(seconds // 3600)
412
+ m = int((seconds % 3600) // 60)
413
+ s = seconds % 60
414
+ return f"{h:02d}:{m:02d}:{s:05.2f}"
415
+
416
+
417
  def build_fig_bar(df2, catColors, speakerColors, get_display_name_fn, currFile):
418
+ """Horizontal bar chart — time spoken per speaker (hh:mm:ss.ss)."""
419
  df2 = df2.copy()
420
+ df2["names"] = df2["names"].apply(lambda s: get_display_name_fn(s, currFile))
421
+ df2["time_label"] = df2["values"].apply(_seconds_to_hhmmss)
422
  fig = px.bar(
423
  df2, x="values", y="names", color="names", orientation="h",
424
+ custom_data=["names", "time_label"],
425
  title="Time Spoken by each Speaker",
426
  color_discrete_sequence=catColors + speakerColors,
427
  )
428
+ # Format x-axis ticks as hh:mm:ss by converting seconds to milliseconds for plotly
429
+ fig.update_xaxes(
430
+ tickvals=df2["values"].tolist(),
431
+ ticktext=df2["time_label"].tolist(),
432
+ )
433
  fig.update_yaxes(autorange="reversed")
434
  fig.update_layout(
435
+ xaxis_title="Time Spoken",
436
  yaxis_title=None,
437
  showlegend=False,
438
  yaxis={"showticklabels": True},
 
440
  )
441
  fig.update_traces(hovertemplate="<br>".join([
442
  "<b>%{customdata[0]}</b>",
443
+ "Time Spoken: %{customdata[1]}",
444
  ]))
445
  return fig
446