class_docstr: Renders customizable statistics on top of event logs.
  
  This renderer provides a central rendering functionality for event log data. Elementary customizability
  is offered (e.g. simple aggregation etc.). For more complex operations with the data, it is advised
  to work with the TSV event logs directly.
class_docstr_tok: ["Renders","customizable","statistics","on","top","of","event","logs",".","This","renderer","provides","a","central","rendering","functionality","for","event","log","data",".","Elementary","customizability","is","offered","(","e.g",".","simple","aggregation","etc.",")",".","For","more","complex","operations","with","the","data",",","it","is","advised","to","work","with","the","TSV","event","logs","directly","."]
docstr: Render event statistics from a data frame according to the supplied options.
  
  Does not create a figure, renders into the currently active ax.
  
  :param df: Event log to render statistics from
  :param event_name: Name of the even the even log corresponds to
  :param metric_name: Metric to use (one of the event attributes, e.g. "n_items" -- depends on the event type)
  :param aggregation_func: Optionally, specifies how to aggregate the metric on step level, i.e. when there
                           are multiple same events dispatched during the same step.
  :param group_by: Optionally, another of event attributes to group by on the step level (e.g. "product_id")
  :param post_processing_func: Optionally, a function to post-process the data ("cumsum" is often used)
docstr_tok: ["Render","event","statistics","from","a","data","frame","according","to","the","supplied","options",".","Does","not","create","a","figure",",","renders","into","the","currently","active","ax",".",":","param","df",":","Event","log","to","render","statistics","from",":","param","event_name",":","Name","of","the","even","the","even","log","corresponds","to",":","param","metric_name",":","Metric","to","use","(","one","of","the","event","attributes",",","e.g",".","``","n_items","''","--","depends","on","the","event","type",")",":","param","aggregation_func",":","Optionally",",","specifies","how","to","aggregate","the","metric","on","step","level",",","i.e",".","when","there","are","multiple","same","events","dispatched","during","the","same","step",".",":","param","group_by",":","Optionally",",","another","of","event","attributes","to","group","by","on","the","step","level","(","e.g",".","``","product_id","''",")",":","param","post_processing_func",":","Optionally",",","a","function","to","post-process","the","data","(","``","cumsum","''","is","often","used",")"]
code: def render_timeline_stat(
      df: pd.DataFrame,
      event_name: str = "BaseEnvEvents.reward",
      metric_name: str = "value",
      aggregation_func: Optional[Union[str, Callable]] = None,
      group_by: str = None,
      post_processing_func: Optional[Union[str, Callable]] = "cumsum",
  ):
      """Render event statistics from a data frame according to the supplied options.
  
      Does not create a figure, renders into the currently active ax.
  
      :param df: Event log to render statistics from
      :param event_name: Name of the even the even log corresponds to
      :param metric_name: Metric to use (one of the event attributes, e.g. "n_items" -- depends on the event type)
      :param aggregation_func: Optionally, specifies how to aggregate the metric on step level, i.e. when there
                               are multiple same events dispatched during the same step.
      :param group_by: Optionally, another of event attributes to group by on the step level (e.g. "product_id")
      :param post_processing_func: Optionally, a function to post-process the data ("cumsum" is often used)
      """
      assert (
          metric_name != group_by
      ), "group by attribute cannot be the same as metric attribute"
      assert (
          metric_name in df.columns
      ), "metric by must be present in event attributes"
      assert (
          group_by is None or group_by in df.columns
      ), "group by must be none or present in event attributes"
  
      grouping = ["episode_id", "env_time"]
      if group_by in df.columns:
          grouping.append(group_by)
  
      # Aggregate
      if aggregation_func is not None:
          df = df.groupby(grouping, as_index=False).agg(
              {metric_name: aggregation_func}
          )
  
      # Post-process
      if post_processing_func is not None:
          df[metric_name] = df.groupby(grouping, as_index=False)[
              metric_name
          ].transform(post_processing_func)
  
      sns.lineplot(x="env_time", y=metric_name, hue=group_by, data=df)
  
      # Add plot labels
      event_name_components = list(
          map(
              lambda x: EventStatsRenderer._humanize(x),
              event_name.split("."),
          )
      )
      plt.title(": ".join(event_name_components))
      ylabel_suffix = (
          f" ({aggregation_func})"
          if aggregation_func is not None
          else ""
      )
      plt.xlabel(EventStatsRenderer._humanize("env_time"))
      plt.ylabel(
          EventStatsRenderer._humanize(metric_name) + ylabel_suffix
      )
      plt.xlim([0, None])
  
file_path: maze/maze/core/rendering/events_stats_renderer.py
imports: import re
  from typing import Optional, Callable, Union
  import matplotlib.pyplot
  import pandas
  import seaborn
  from maze.core.log_events.episode_event_log import EpisodeEventLog
label_desc: Use image node_id 2 for calling the EventStatsRenderer obj's underlying member method code with example usage: obj.render_timeline_stat(df, event_name, metric_name, aggregation_func, group_by, post_processing_func) without return types