code: def pareto_and_runtimes_by_task(df: pd.DataFrame) -> alt.Chart:
      """Creates an interactive Pareto curve and scatter plot of task runtimes.
  
      Tracing each curve shows to what extent a small proportion of long-running
      regions contribute disproportionately to the overall runtime. That is,
      "The longest-running X% of regions account for Y% of the total runtime."
      There is a curve for each task.
  
      Args:
        df: A dataframe of all regions.
  
      Returns:
        An altair chart.
      """
      grouped = df.groupby(df["Task"], sort=False, group_keys=False)
      df = grouped.apply(calculate_pareto_metrics)
  
      # Sample along the Pareto curve, ensuring the longest regions are shown.
      if len(df) > 5000:
          x = 1000
          df = pd.concat(
              [df.nlargest(x, "total runtime"), df.sample(5000 - x)]
          )
  
      # Limit columns to greatly reduce the size of the html report.
      columns_used = [
          "task cumsum order",
          "task cumsum fraction",
          "tooltip",
          "Task",
          "task total runtime",
          "task num examples",
          "Runtime for task",
      ]
      df = df[columns_used]
  
      # Brushing on the task_scatter plot highlights the same tasks in the Pareto
      # curve.
      brush = alt.selection_interval()
  
      pareto_by_task = (
          alt.Chart(df)
          .mark_line(size=2)
          .encode(
              x=alt.X(
                  "task cumsum order",
                  title="The longest-runtime X% of regions",
                  axis=alt.Axis(format="%"),
              ),
              y=alt.Y(
                  "task cumsum fraction",
                  title="Account for Y% of the total runtime",
                  axis=alt.Axis(format="%"),
              ),
              tooltip="tooltip",
              color=alt.condition(
                  brush, "Task:N", alt.value("lightgray")
              ),
          )
          .properties(title="Pareto curve for each task")
          .interactive()
      )
  
      # This chart needs to use the same dataframe as the first chart to enable the
      # brushing on one to affect the other. Using max(task) for 'text' is a
      # trick that causes bundling by task to avoid showing multiple overlapping
      # points which otherwise make the text look funky.
      task_scatter = (
          alt.Chart(df)
          .mark_point(size=10)
          .encode(
              x=alt.X(
                  "max(task total runtime)", title="Runtime (seconds)"
              ),
              y=alt.Y(
                  "task num examples:Q", title="Number of examples"
              ),
              color=alt.condition(
                  brush, "Task:N", alt.value("lightgray")
              ),
              tooltip=["Task", "Runtime for task"],
          )
          .properties(
              title="Total runtime for each task (drag to highlight)"
          )
          .add_selection(brush)
      )
  
      return pareto_by_task | task_scatter
  
imports: from typing import Dict, Sequence, List, Tuple, Text, Union
  from absl import app
  from absl import flags
  import altair
  import pandas
  import tensorflow
  from third_party.nucleus.io import sharded_file_utils
  from deepvariant import dashboard_utils
label_desc: Use image node_id 10 for calling a global function with example usage: pareto_and_runtimes_by_task(df) and returns: unknown