5. Data schema Flashcards
What is the data_schema file for?
- The data schema specifies all of the items in the model data, which can be accessed from your interface and your rating algorithm and is written in Python code.
- This should be edittted not data_schema_static as changes will not be saved in that one
What does a data item in the data_schema look like?
“assured”: hx.Str(mode=”input”, default=””, view={“label”: “Assured”}),
* The variable name (“assured”): This is how you will access the data item throughout the model.
* The node type (hx.Str), this is automatically detected from the example value in the example data
* Mode – This can be input, output or override.
* Default – The value that will load when the model first starts up, or when the model is recreated using default values. This is to give the user of the form some indication of the expected value type. Default is only required for input nodes, so when the nodes are changed to be outputs and overrides, this argument will be removed.
* View – How the field is displayed in the model, including the label (text to be displayed alongside the value) and number formatting.
What are the node types?
- hx.Int (integer, whole number)
- hx.Str (text)
- hx.Float (number with decimal places)
- hx.Bool (True or false)
- hx.Date
What is an override?
- Overrides combine the properties of input and output nodes, with the rating algorithm suggesting a calculated value, which the user may choose to override with a different value if they need to.
- In the model, you will now see a little green triangle in the top right-hand corner of this field, which indicates this cell can be overridden. Click on the triangle and then override to enter a new value into cell.
- Once the cell has been overwritten, it will turn white. If you click on the triangle again, you can remove the override.
- A full history of changes to the form, including if values have been overwritten can be seen by clicking on the show history icon in the top right-hand corner of the model.
How are labels generated?
When the data schema gets generated from example data, the script creates a label by:
* Removing any underscores and replacing them with spaces
* Adding capitals to the start of each new word
However, there may be cases where the label needs to be adjusted. It may be that the label needs to be changed completely, or some extra detail added to the label such as units, or capitalize acronyms
Describe the format property:
Format is a property of the view property in the data schema, which contains information about how a numeric value will be formatted when displayed. It contains the following properties
* “thousandSeparated”:True: Boolean property that adds commas to numbers. Defaults to False.
* “mantissa”:0: integer property that sets a fixed number of decimal places (in this example zero)
* “trimMantissa”:True : Boolean property that sets the maximum number of decimal places to the value specified by mantissa. Defaults to False.
* “output”:”percent”: Sets numbers as percentages.
There are also prepared number formatting functions that can be added to the data schema file between imports and @hx.data_schema
def thousands_format(mantissa=0):
return{“thousandSeparated”: True, “mantissa”:mantissa}
def percent_format(mantissa=0):
return{“output”: “percent”, “mantissa”:mantissa}
How do you create dropdowns?
To create dropdowns, the options property is used with our parameter files. Then there are a few different options
* They can be hard coded like so
“currency”: hx.Str(mode=”input”, default=”GBP”, options=[“USD”, “GBP”, “EUR”], view={“label”: “Currency”})
* They can use the parameter json files which have been converted to Python dictionary format:
“currency”: hx.Str(mode=”input”, options=list(currencies.keys()), default_index=0, view={“label”: “Currency”}),