Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Insert excerpt
_Banners
_Banners
nameanalysis
nopaneltrue

By the end of this chapter you will be able to:

  • Use the attribute function replaceAll()
  • Use the attribute function toUpper()
  • Use the attribute function substring()
  • Use the attribute function if()
  • Use the internal variable _out

Reformat post codes to remove all spaces and make upper case

...

In your Introduction to Modelling analysis model, you will now reformat post codes to remove all spaces, and ensure that all letters are upper case:

  1. In your model, add a new

...

  1. table:
    1. Hover over Customer Details with Region, and press 

...

    1. Insert excerpt
      _table_new
      _table_new
      nopaneltrue
      .
    2. Give the new

...

    1. table the Name: Reformatted Customer Details.
    2. Drag all attributes from  to the new table Customer Details with Region

...

    1. .
  1. Open the

...

  1. settings for the Reformatted Customer Details table.
    1. In the Attributes section, add a new attribute:
      • Press 

...

      • Insert excerpt
        _add
        _add
        nopaneltrue
      • In the

...

      • New Table Attribute settings, set:

    ...

          • Name: ReformattedPostCode
          • Leave the settings for the attribute as default (Type is String, Length is 50)

    ...

          • Expression

    ...

          • :
    Code Block
    toUpper(replaceAll(in.PostCode, " ", ""))

    ...

      • Press Image Removed

    ...

      • Press 
        Insert excerpt
        _finish
        _finish
        nopaneltrue
         on the New Table Attribute settings.
    Tip

    Above the attribute's Expression is a help link that will open a page containing details of all attribute functions available in PhixFlow

    ...

    . Find the attribute functions you used above – toUpper() and replaceAll()

    ...

    –  click each of these to see the help pages specifically for these functions.

    Inline help is also provided for functions, this will appear as you type. At the bottom of the popup help is a link directly to the page for the function in question.

    Generate short code for Counties

    Now you will generate a short code for counties by taking the first 3 letters of the county for each customer detail record:

    ...

    1. In the Reformatted Customer Details table settings, add a new attribute called CountyShortCode.
    2. Leave the default settings.
    3. Set the attribute

    ...

    1. 's Expression to:

      Code Block
      substring(in.County, 1, 3)


    2. Press 

    ...

    1. Insert excerpt
      _finish
      _finish
      nopaneltrue
      .

    Categorise bills as "LARGE" or "NORMAL"

    ...

    To categorise bills as "LARGE" or "NORMAL":

    ...

    1. In the Reformatted Customer Details table settings, add a new attribute called BillCategory
    2. Leave the default settings.

    ...

    1. Set the attribute

    ...

    1. 's Expression to:

      Code Block
      if (in.BILLAMOUNT > 10.0, "LARGE", "NORMAL")


    2. Press 

    ...

    1. Insert excerpt
      _finish
      _finish
      nopaneltrue
      .

    Set special processing flag _out

    Finally, you will now set a special processing flag

    ...

    . This will be set to "YES" when the last bill for the customer is large. To do this, we need to access an attribute value that is in the

    ...

    table, but

    ...

    not in any of the input pipes to the

    ...

    table, only

    ...

    the

    ...

    table output.

    To do this, you will use the internal variable _out:

    ...

    1. In the Reformatted Customer Details table settings, add a new attribute called SpecialProcessing
    2. Leave the default settings.

    ...

    1. Set the attribute

    ...

    1. 's Expression to:

      Code Block
      if (_out.BillCategory == "LARGE", "YES", "NO")


    2. Press 

    ...

    Run stream

    ...

    1. Insert excerpt
      _finish
      _finish
      nopaneltrue
      .

    Check Point - Table Attributes

    1. The Attributes section for the Reformatted Customer Details table should now look like this:
      1. Image Added

    Run table

    1. In the settings for the table Reformatted Customer Details, press 
      Insert excerpt
      _finish
      _finish
      nopaneltrue
      .
    2. Run analysis on the table Reformatted Customer Details.
    3. Have a look at the data in

    ...

    1. this table – check that all your transformations have been correctly applied, like the image below:
    2. Image Added
    3. Remember to save your model layout, 
      Insert excerpt
      _save_saveModel
      _save_saveModel
      nopaneltrue
      .