code: def total_episode_reward_logger(
      rew_acc, rewards, masks, writer, steps
  ):
      """
      calculates the cumulated episode reward, and prints to tensorflow log the output
  
      :param rew_acc: (np.array float) the total running reward
      :param rewards: (np.array float) the rewards
      :param masks: (np.array bool) the end of episodes
      :param writer: (TensorFlow Session.writer) the writer to log to
      :param steps: (int) the current timestep
      :return: (np.array float) the updated total running reward
      :return: (np.array float) the updated total running reward
      """
      with tf.variable_scope("environment_info", reuse=True):
          for env_idx in range(rewards.shape[0]):
              dones_idx = np.sort(np.argwhere(masks[env_idx]))
  
              if len(dones_idx) == 0:
                  rew_acc[env_idx] += sum(rewards[env_idx])
              else:
                  rew_acc[env_idx] += sum(
                      rewards[env_idx, : dones_idx[0, 0]]
                  )
                  summary = tf.Summary(
                      value=[
                          tf.Summary.Value(
                              tag="episode_reward",
                              simple_value=rew_acc[env_idx],
                          )
                      ]
                  )
                  writer.add_summary(summary, steps + dones_idx[0, 0])
                  for k in range(1, len(dones_idx[:, 0])):
                      rew_acc[env_idx] = sum(
                          rewards[
                              env_idx,
                              dones_idx[k - 1, 0] : dones_idx[k, 0],
                          ]
                      )
                      summary = tf.Summary(
                          value=[
                              tf.Summary.Value(
                                  tag="episode_reward",
                                  simple_value=rew_acc[env_idx],
                              )
                          ]
                      )
                      writer.add_summary(
                          summary, steps + dones_idx[k, 0]
                      )
                  rew_acc[env_idx] = sum(
                      rewards[env_idx, dones_idx[-1, 0] :]
                  )
  
      return rew_acc
  
imports: import os
  import collections
  import functools
  import multiprocessing
  from typing import Set
  import numpy
  import tensorflow
label_desc: Use image node_id 24 for calling a global function with example usage: total_episode_reward_logger(rew_acc, rewards, masks, writer, steps) and returns: rew_acc