code: def test_dsjson_with_metrics():
      vw = vowpalwabbit.Workspace(
          "--extra_metrics metrics.json --cb_explore_adf --epsilon 0.2 --dsjson"
      )
  
      ex_l_str = '{"_label_cost":-0.9,"_label_probability":0.5,"_label_Action":1,"_labelIndex":0,"o":[{"v":1.0,"EventId":"38cbf24f-70b2-4c76-aa0c-970d0c8d388e","ActionTaken":false}],"Timestamp":"2020-11-15T17:09:31.8350000Z","Version":"1","EventId":"38cbf24f-70b2-4c76-aa0c-970d0c8d388e","a":[1,2],"c":{ "GUser":{"id":"person5","major":"engineering","hobby":"hiking","favorite_character":"spock"}, "_multi": [ { "TAction":{"topic":"SkiConditions-VT"} }, { "TAction":{"topic":"HerbGarden"} } ] },"p":[0.5,0.5],"VWState":{"m":"N/A"}}\n'
      ex_l = vw.parse(ex_l_str)
      vw.learn(ex_l)
      pred = ex_l[0].get_action_scores()
      expected = [0.5, 0.5]
      assert len(pred) == len(expected)
      for a, b in zip(pred, expected):
          assert isclose(a, b)
      vw.finish_example(ex_l)
  
      ex_p = '{"_label_cost":-1.0,"_label_probability":0.5,"_label_Action":1,"_labelIndex":0,"o":[{"v":1.0,"EventId":"38cbf24f-70b2-4c76-aa0c-970d0c8d388e","ActionTaken":false}],"Timestamp":"2020-11-15T17:09:31.8350000Z","Version":"1","EventId":"38cbf24f-70b2-4c76-aa0c-970d0c8d388e","a":[1,2],"c":{ "GUser":{"id":"person5","major":"engineering","hobby":"hiking","favorite_character":"spock"}, "_multi": [ { "TAction":{"topic":"SkiConditions-VT"} }, { "TAction":{"topic":"HerbGarden"} } ] },"p":[0.5,0.5],"VWState":{"m":"N/A"}}\n'
      pred = vw.predict(ex_p)
      expected = [0.9, 0.1]
      assert len(pred) == len(expected)
      for a, b in zip(pred, expected):
          assert isclose(a, b)
  
      learner_metric_dict = vw.get_learner_metrics()
      assert len(vw.get_learner_metrics()) == 27
  
      assert learner_metric_dict["total_predict_calls"] == 2
      assert learner_metric_dict["total_learn_calls"] == 1
      assert learner_metric_dict["cbea_labeled_ex"] == 1
      assert learner_metric_dict["cbea_predict_in_learn"] == 0
      assert learner_metric_dict["cbea_label_first_action"] == 1
      assert learner_metric_dict["cbea_label_not_first"] == 0
      assert pytest.approx(learner_metric_dict["cbea_sum_cost"]) == -0.9
      assert (
          pytest.approx(learner_metric_dict["cbea_sum_cost_baseline"])
          == -0.9
      )
      assert learner_metric_dict["cbea_non_zero_cost"] == 1
      assert (
          pytest.approx(learner_metric_dict["cbea_avg_feat_per_event"])
          == 24
      )
      assert (
          pytest.approx(
              learner_metric_dict["cbea_avg_actions_per_event"]
          )
          == 2
      )
      assert (
          pytest.approx(learner_metric_dict["cbea_avg_ns_per_event"])
          == 16
      )
      assert (
          pytest.approx(learner_metric_dict["cbea_avg_feat_per_action"])
          == 12
      )
      assert (
          pytest.approx(learner_metric_dict["cbea_avg_ns_per_action"])
          == 8
      )
      assert learner_metric_dict["cbea_min_actions"] == 2
      assert learner_metric_dict["cbea_max_actions"] == 2
      assert (
          learner_metric_dict["sfm_count_learn_example_with_shared"]
          == 1
      )
  
imports: import os
  from pathlib import Path
  import vowpalwabbit
  from vowpalwabbit import Workspace
  import pytest
  import warnings
  import filecmp
label_desc: Use image node_id 46 for calling a global function with example usage: test_dsjson_with_metrics() without return types