Focal Point Basics Jobsheets

Setting up Product Parts and Product Dictionary Print-outs for Debugging and Diagnostics

Purpose:

Two simple overrides provide invaluable diagnostic information for product generation. First: Configuring the "printDebugProductParts" method will help identify the precise "product part" building blocks which compose every product. Second: Enabling a full print-out of the product dictionary provides a view of the complex data structure accessed by all product generation code.

Tasks:

Print Product Parts Information 

  1. In the Localization Perspective, navigate to the Product Formats sub-directory under the Hazard Services folder.
  2. Double click on NWS_Base_Formatter.py to find the base version of this file. This file affects all products, so there won't be a need to modify any other files.
  3. Right click on BASE and choose "Create Override File" --> "User" 
  4. In the newly created user override for NWS_Base_Formatter, add the following lines, with the method definition intended to the same level as the "pass": 
        def printDebugProductParts(self):
            # IF True will print the product parts and associated text during execution
            return True
    
  5. Save the user override file, and save/close the merge file as well, if prompted. 
  6. Switch to D2D or Hydro perspective, and open Hazard Services if not already open. 
  7. Create a hazard of ANY type (or if you already have one, open the HID for it). 
  8. Press the "Preview" button to open the Product Editor. At this point, the method in the override file has been run, and you don't need to issue the product to see the results. 
  9. Open a terminal window from your desktop (right click on the desktop and click "Open Terminal". 
  10. Run the following command in your terminal window, which will print out the contents of the file that stores the product parts debug information: 
    cat /tmp/printDebugProductParts.txt
    
  11. What follows after each "Legacy Part:" is the precise name of the product part "building block", followed by its associated text (if any).
    1. Knowing the precise product part name is essential to finding its reference in the product assembly code 
  12. You can compare each of the listed "Legacy Parts" to parts that are shown in ProductEditorFields.py (found in the Utilities folder of Hazard Services) to help determine the part name needed for your specific customization desires. 
    1. NOTE: You may not find all of the product parts listed in the text file in ProductEditorFields.py. Some of them may be found in SectionLevelMethods.py (also in Utilities folder), and even some elsewhere. For more information about product parts, please reference section 3.3 of the Hazard Services Focal Point Guide
  13. This file will be recreated each time the "Preview" button on the HID is clicked, or "Issue All" on the product editor, and will work for any hazard type. Rerun the command to print the contents of the file each time a new Product Editor is loaded and product parts need to be evaluated. 

 

Print Contents of the Product Dictionary 

Additionally, you can print out the entire Product Dictionary for even more detailed information about the product generator output. Follow the steps below to see this information. 

  1. In the user override for NWS_Base_Formatter.py created in the previous step, add the following lines. Remember to keep the indentation at the same level as the previous method added to this override. 
        def recordGeneratedText(self, dictionary, text):
            ffff = open("/tmp/productDict.txt", "w")
            try :
                myJC = jsonCombine()
                productDictClean = myJC.arbCopyRobust(dictionary)
                ffff.write(json.dumps(productDictClean, indent=4, sort_keys=True)+"\n")
            except :
                ffff.write(str(dictionary)+"\n")
            ffff.close()
    
  2. You will also need to add a few import statements above the class definition. Add these 2 lines to the VERY top of the user override for NWS_Base_Formatter.py, above the class definition. No indentation is needed for these. 
    import json
    from jsonCombine import jsonCombine
    

  3. Once you have saved the file, you can again press "Preview" to generate the Product Editor and run this method. 

  4. Run the following command in your terminal window, which will print out the contents of the file that stores the product dictionary, similar to the print out of the Product Parts information: 

    cat /tmp/productDict.txt
    
  5. The text you see is the complete structure of the Product Dictionary for your previewed product.  Use this to see the complete set of data made available to any product generation and formatting code, and how to access it (what key(s), or keys within keys, etc., navigate you to the information you want to access).