TOI Builder
elements.sdk.builder.toi
This is a basic builder to help build factories in a safe way instead of managing JSON configuration files. This includes all the methods to incrementally build out a TOI proto struct that can be used in API calls.
TOIs follow the iCalendar rule specifications, which the TOI Builder helps construct.
TOIBuilder
TOIBuilder.build_toi()
- start (datetime) - the beginning of the time window for the TOI
- finish (datetime) - the end of the time window for the TOI
- [Optional] description (str) - description of the TOI
TOIBuilder.build_recurrence()
- rrule (str) - the iCalendar recurrence rule (see here for details)
- [Optional] cadence (Cadence) - the cadence to apply to the TOI
TOIBuilder.build_exclusion_dates()
- exclusion_dates (List[datetime]) - list of dates to exclude from the TOI
TOIBuilder.get() - return full TOI object
from elements.sdk.elements_sdk as TerraScopeSDK
from elements.sdk.builder.toi import TOIBuilder
# Build TOI with start and end datetime
start="2019-01-05 01:00:00"
finish="2019-01-15 01:00:00"
datetime_format = '%Y-%m-%d %H:%M:%S'
toi_configuration = TOIBuilder()
toi_configuration.build_toi(start=datetime.strptime(start, datetime_format),
finish=datetime.strptime(finish, datetime_format),
description="build main toi")TOIRuleBuilder
TOIRuleBuilder.build_rule()
- frequency (Frequency) - the rate of occurrences
- interval (int) - the step for the frequency. Frequency.DAILY with an interval of 2 is every other day, e.g.
- until (str) - the future date to end by, datetime format "%Y%m%dT%H%M%SZ"
- count (int) - the number of occurrences
from elements.sdk.elements_sdk as TerraScopeSDK
from elements.sdk.builder.toi import TOIRuleBuilder, Frequency
# Build basic rule with daily occurence
toi_rule = TOIRuleBuilder.build_rule(frequency=Frequency.DAILY, interval=1)
# Build rule with daily occurence until certain date
toi_rule = TOIRuleBuilder.build_rule(frequency=Frequency.DAILY, interval=1,
until="20220101T000000")TOICadenceBuilder
TOICadenceBuilder.build_cadence()
- frequency (Frequency) - the group frequency to apply (daily, weekly, monthly, etc.)
- value (int) - the interval to apply to the frequency (every X days, weeks, etc.)
from elements.sdk.elements_sdk as TerraScopeSDK
from elements.sdk.builder.toi import TOICadenceBuilder, Frequency
# Build TOI cadence (duration)
cadence = TOICadenceBuilder.build_cadence(frequency=Frequency.MONTHLY, value=1)End-to-end TOI Build
from elements.sdk.elements_sdk as TerraScopeSDK
from elements.sdk.builder.toi import TOIBuilder, TOIRuleBuilder, TOICadenceBuilder, Frequency
# Build TOI with start and end datetime
start="2019-01-05 01:00:00"
finish="2019-01-15 01:00:00"
datetime_format = '%Y-%m-%d %H:%M:%S'
toi_configuration = TOIBuilder()
toi_configuration.build_toi(start=datetime.strptime(start, datetime_format),
finish=datetime.strptime(finish, datetime_format),
description="build main toi")
# Build rule with daily occurence until certain date
toi_rule = TOIRuleBuilder.build_rule(frequency=Frequency.DAILY, interval=1,
until="20220101T000000")
# Build TOI cadence (duration)
toi_cadence = TOICadenceBuilder.build_cadence(frequency=Frequency.MONTHLY, value=1)
# Add new rules to TOI Configuration
toi_configuration.build_recurrence(rrule=toi_rule, cadence=toi_cadence)
# Create TOI
await sdk.toi.create(toi_configuration.get())Updated 6 months ago