sdk.toi.create()
elements.sdk.api.toi
Create a TOI.
This will call the Create Times of Interest (toi) service and create a new TOI for usage in a computation. When defining a TOI please use an instance of a TOIConfiguration.
TOI BuilderSee the TOI Builder section for more details on how to construct a TOI.
Parameters
- toi (TOI) - The TOI object that contains the rules and time ranges for the time of interest.
Returns
TOI
Example(s)
Single Rule Recurrence: UNTIL
# Configuring a TOI using the builder: TOIConfiguration()
start_local="2020-01-01"
finish_local="2020-12-31"
datetime_format = '%Y-%m-%d'
toi_configuration = TOIBuilder()
toi_configuration.build_toi(start=datetime.strptime(start_local, datetime_format),
finish=datetime.strptime(finish_local, datetime_format),
description="A basic TOI object")
toi_configuration.build_recurrence(TOIRuleBuilder.build_rule(frequency=frequency,
interval=interval))
# Create TOI
await sdk.toi.create(toi=toi_configuration.get())
# Output (TOI)
id: "098ac9b8-11f2-455a-ae6e-b391319c78f2"
start_local {
seconds: 1577836800
}
finish_local {
seconds: 1609372800
}
recurrences {
id: "1bb4d6cd-feb7-4c20-a445-783d50fb38da"
rule: "FREQ=DAILY;INTERVAL=1"
duration {
frequency: DAILY
value: 1
}
}
description: "A basic TOI object"Configuration a TOI Directly
# Create TOI directly with Platform API
start_local = Timestamp()
start_local.FromJsonString("2020-01-01T00:00:00Z")
finish_local = Timestamp()
finish_local.FromJsonString("2020-12-31T00:00:00Z")
rule="FREQ=DAILY;INTERVAL=2"
client.models.tois.TOI(
start_local=start_local,
finish_local=finish_local,
exclude_dates=[start_local, finish_local],
recurrences=[client.models.tois.Recurrence(
rule=rule,
duration=client.models.tois.Cadence(
frequency=client.models.tois.Frequency.DAILY,
value=4
)
)]
)
await sdk.toi.create(toi=toi)Updated 6 months ago