Task headers

What is a table header

Each table in Lampyre is described by its header. Headers consist of their table name and fields. Every field in a header has a unique name, data type and some other features.

Example of header in Lampyre UI

Fields and types

Every field should be of one of the following data types: string, integer, float, boolean or datetime. In the Lighthouse API these types are listed in the ValueType special class . Also, if the field type is a string, it can contain binary information on an image or color. These data types are listed in the BinaryType class.

Describing headers in the code

In order to describe a table header in a custom task script, one should create a class using a Header metaclass and then describe the fields as this class’s properties, using the instances of the Field:

class AccountsHeader(metaclass=Header):
    display_name = 'Accounts'

    Name = Field(display_name='Name', type=ValueType.String, system_name='name')
    Age = Field('Age', ValueType.Integer)
    UserPic = Field('Avatar', ValueType.String, binary_type=BinaryType.Image)

Reserved class property display_name here contains a table name. The system_name argument in the Field constructor is optional and serves as a unique identifier for the field in some cases.

Additional header properties

After defining your header class, you can change some of its field special properties using the set_property() method. This method requires a field system name, special property name and its value.

Here are these properties:

  • datetime_format - If a field is of the ValueType.DateTime type, you can set the custom format for dates in this column using C# format

  • hidden property allows hiding a field in the default table view

  • multiline_width sets the column width in pixels

  • coordinates marks the field as the one containing coordinates in Geojson

  • latitude marks the field as containing data on latitude

  • longitude marks the field as containing data on longitude

This is how to set such properties in a code:

AccountsHeader.set_property(AccountsHeader.UserPic.system_name, 'hidden', True)

Features

Header classes have some additional features to make the development process easier:

create_empty() creates a dictionary with header fields as keys (this is what write_line() requires to add a row)

This is useful, because write_line requires the line dict to contain all the header fields.

line = AccountsHeader.create_empty()  # this dictionary contains all AccountsHeader fields
line[AccountsHeader.Name] = 'John Galt'
result_writer.write_line(line, header_class=AccountsHeader)

get_fields() creates a dictionary with the field names (as they are named in the class properties) as keys and fields as values

assert AccountsHeader.get_fields()['UserPic'] == AccountsHeader.UserPic  # true

fields returns a list of all the header fields

dtype returns a dictionary with the field system names and data types for the Pandas.DataFrame constructor or other functions, like read_csv

import pandas as pd

df = pd.read_csv('accounts.csv', dtype=AccountsHeader.dtype)
print(df['Age'])

# 0    27
# 1    41
# ...
# Name: Age, dtype: int32