class_docstr: Test Case to generate html report
class_docstr_tok: ["Test","Case","to","generate","html","report"]
code: def test_add_data_analysis(self):
      self.name = "data-analysis"
      self.report_name = "Data Analysis Report"
      self.tag_number = 1
      ## Create Report
      self.report = Report(name=self.report_name)
      ### Create Data Analysis Section
      self.report.detail.add_section_title("Example for Data Analysis ")
      ### Add Header Level 1
      self.report.detail.add_header_level_1(text="Data Analysis")
      self.assertEqual(len(self.report.detail.contents), 2)
  
      ### Load Data
      file_name = prepare_input_path(
          data_path="sample_data/titanic.csv"
      )
      data = pd.read_csv(file_name)
      ### Add dummy birthday to demonstrate datetime presentation
      bday = []
      for i in range(len(data)):
          year = np.random.randint(low=1960, high=1979)
          month = np.random.randint(low=1, high=12)
          day = np.random.randint(low=1, high=28)
          bday.append("%s" % (10000 * year + 100 * month + day))
      data["Birthday"] = bday
  
      label_column = "Survived"
  
      ### Get data types - scenario where no metadata provided
      (
          feature,
          valid_feature_names,
          valid_feature_types,
          meta,
      ) = DataUtil.get_column_types(
          data=data, threshold=0.3, label=label_column
      )
      # -- Cast Data to String --
      non_numeric_features = [
          name
          for name, _type in list(
              zip(valid_feature_names, valid_feature_types)
          )
          if _type != DATATYPE.NUMBER
      ]
      if label_column is not None:
          non_numeric_features += [label_column]
      DataUtil.cast_type_to_string(
          data=data, feature_names=non_numeric_features
      )
  
      ### Add Header Level 2
      self.report.detail.add_header_level_2(
          text="Data Class (Label) Distribution"
      )
      ### Add Label distribution
      label_distributions = DataUtil.get_label_distribution(
          data=data, label=label_column
      )
      self.report.detail.add_data_set_distribution(label_distributions)
      self.assertEqual(len(self.report.detail.contents), 4)
  
      ### Get Data Stats
      stats = DataUtil.get_data_statistics(
          data=data,
          feature_names=valid_feature_names,
          feature_types=valid_feature_types,
          label=label_column,
      )
  
      ### Add Header Level 2
      self.report.detail.add_header_level_2(text="Data Field Attribute")
      ### Data Field Attribute
      self.report.detail.add_data_attributes(meta)
      self.assertEqual(len(self.report.detail.contents), 6)
  
      ### Add Header Level 2
      self.report.detail.add_header_level_2(
          text="Data Missing Value Check"
      )
      ### Missing value count
      missing_count, total_count = DataUtil.get_missing_value_count(
          data=data,
          feature_names=valid_feature_names,
          feature_types=valid_feature_types,
      )
      print(missing_count)
      self.assertEqual(missing_count["Age"], 177)
      self.assertEqual(missing_count["Embarked"], 2)
      print(total_count)
      self.assertEqual(total_count["Name"], 891)
      self.assertEqual(total_count["Embarked"], 891)
      self.assertEqual(len(self.report.detail.contents), 7)
      self.report.detail.add_data_missing_value(
          missing_count=dict(missing_count), total_count=total_count
      )
      self.assertEqual(len(self.report.detail.contents), 8)
  
      ### Add Header Level 2
      self.report.detail.add_header_level_2(
          text="Data Field Distribution"
      )
      ### Data Field Distribution Desc
      self.report.detail.add_paragraph(
          text="This section displays distribution for categorical fields, numerical fields and text fields."
      )
      self.assertEqual(len(self.report.detail.contents), 10)
  
      ### Add Header Level 3
      self.report.detail.add_header_level_3(
          text="Categorical Field Distribution"
      )
      print(feature[DATATYPE.CATEGORY])
      self.assertEqual(len(feature[DATATYPE.CATEGORY]), 5)
      ### Categorical field distribution
      for field_name in feature[DATATYPE.CATEGORY]:
          labelled_stats, all_stats = stats[field_name]
          self.report.detail.add_categorical_field_distribution(
              field_name=field_name, field_distribution=labelled_stats
          )
      self.assertEqual(len(self.report.detail.contents), 16)
  
      ### Add Header Level 3
      self.report.detail.add_header_level_3(
          text="Numerical Field Distribution"
      )
      print(feature[DATATYPE.NUMBER])
      self.assertEqual(len(feature[DATATYPE.NUMBER]), 2)
      ### Numerical field distribution
      for field_name in feature[DATATYPE.NUMBER]:
          labelled_stats, all_stats = stats[field_name]
          self.report.detail.add_numeric_field_distribution(
              field_name=field_name, field_distribution=labelled_stats
          )
      self.assertEqual(len(self.report.detail.contents), 19)
  
      ### Add Header Level 3
      self.report.detail.add_header_level_3(
          text="Text Field Distribution"
      )
      print(feature[DATATYPE.FREETEXT])
      self.assertEqual(len(feature[DATATYPE.FREETEXT]), 1)
      ### Text field distribution
      for field_name in feature[DATATYPE.FREETEXT]:
          labelled_stats, all_stats = stats[field_name]
          self.report.detail.add_text_field_distribution(
              field_name=field_name, field_distribution=labelled_stats
          )
      self.assertEqual(len(self.report.detail.contents), 21)
  
      ### Add Header Level 3
      self.report.detail.add_header_level_3(
          text="Datetime Field Distribution"
      )
      print(feature[DATATYPE.DATETIME])
      self.assertEqual(len(feature[DATATYPE.DATETIME]), 1)
      ### Datetime field distribution
      for field_name in feature[DATATYPE.DATETIME]:
          labelled_stats, all_stats = stats[field_name]
          self.report.detail.add_datetime_field_distribution(
              field_name=field_name, field_distribution=labelled_stats
          )
  
      print(self.report.detail.contents)
      self.assertEqual(len(self.report.detail.contents), 23)
  
imports: import json
  import os
  import sys
  import unittest
  import warnings
  from pathlib import Path
  import numpy
  import pandas
  from datetime import datetime
  from xai.data import DataUtil
  from xai.data.constants import DATATYPE
  from xai.model.interpreter import FeatureInterpreter
  from xai.formatter import Report, HtmlWriter
  from tests.formatter.util import prepare_input_path, prepare_output_path
label_desc: Use image node_id 6 for calling the TestGenerateHtmlReport obj's underlying member method code with example usage: obj.test_add_data_analysis() without return types