- Introduction
- Standard Events
- User Interface Helpers
- Data Fields
- Database Access
- Data input/output
- Heat Generation
- Class Ranking
- Race Points
- LED
- Video Receivers
- Active Race
- Event Results
- Language and Translation
- Hardware Interface
- Sensors Interface
Most plugin interfaces provide access to RHAPI
, an object providing a wide range of properties and methods across RotorHazard's internal systems. Using RHAPI, one can manipulate nearly every facet of a race event and RotorHazard's behavior.
The API version can be read from the API_VERSION_MAJOR
and API_VERSION_MINOR
properties.
The language translation function can be accessed directly via RHAPI.__()
in addition to its location within RHAPI.language
.
Significant timer actions trigger events. Plugin authors may bind handler functions to events which are run when the event occurs. Many timer subsystems trigger an initialize event so plugins can register behaviors within them. Plugin authors may also bind to and trigger custom events either for their own purposes or to share data between plugins.
A list of timer-provided events is contained within the Evt
class in /src/server/eventmanager.py
, which can be accessed with from eventmanager import Evt
.
For example, a plugin might register events to be run at startup like this:
from eventmanager import Evt
def initialize(rhapi):
rhapi.events.on(Evt.STARTUP, my_startup_function)
When an event is triggered, all registered handlers are run. Events may pass arguments containing useful data such as the node number, pilot callsign, or race object. All events return args(dict)
, but the available keys will vary.
Register a handler using the .on()
function, usually within your initialize()
function.
Handlers are given a name
during registration. One handler with each name
can be registered per event; registering with the same name
and event
multiple times will cause handlers to be overridden. Providing a name
is not needed in most circumstances, as one will be automatically generated if not provided. If multiple handlers need bound to the same event
in one plugin, separate name
s are required.
Events are registered with a priority that determines the order handlers are run, lower numbers first. Priorities < 100 are executed synchronously, blocking other code from executing until they finish. Priorities >= 100 are executed asynchronously, allowing the timer to continue running other code. Handlers should generally be run asynchronously, except initial registrations. Python's gevents
are not true threads, so code running asynchronously must call gevent.idle
or gevent.sleep
at frequent intervals to allow other parts of the server to execute.
If run asynchronously (priority >= 100), a handler will cancel other handlers that have the same name
. For example, only one LED effect can be visible at a time. Handler cancellation can also be prevented by setting a handler's unique
property to True
.
Registers a handler to an event. This causes the code in the handler to be run each time the event is triggered by any means (timer, plugin, or otherwise). No return.
event
(Evt|string): triggering event for this handlerhandler_fn
(function): function to run when this event triggersdefault_args
optional (dict): provides default arguments for the handler; these arguments will be overridden if theEvent
provides arguments with the same keys.priority
optional (int): event priority, as detailed above; if not set, default priority is 75 (synchronous) for intial registrations and 200 (asynchronous) for all othersunique
optional (boolean): if set toTrue
, this handler's thread will not be cancelled by other handlers with the samename
name
optional (string): sets this handler'sname
; if left unset, thename
is automatically generated from the module name of the plugin.
Removes a handler from an event. Removes only the specific name
and event
combination, so if handlers with the same name
are registered to multiple events
, others will not be removed. No return.
event
(string|Evt): the triggering event for this handler.name
(string): the registeredname
of the handler to remove.
Triggers an event, causing all registered handlers to run
event
(string|Evt): the event to triggerevtArgs
(dict): arguments to pass to the handler, overwriting matched keys in that handler'sdefault_args
Interact with RotorHazard's frontend user interface.
These methods are accessed via RHAPI.ui
Add custom UI panels to RotorHazard's frontend pages. Panels may contain Options and Quickbuttons.
Panels are represented with the UIPanel
class, which has the following properties:
name
(string): Internal identifier for this panellabel
(string): Text used as visible panel headerpage
(string): Page to add panel toorder
(int): Not yet implementedopen
(boolean): Whether panel is open or closed
Read only
The list of registered panels. Returns List[UIPanel]
.
Register a UI panel and assign it to a page. Returns all panels as list[UIPanel]
.
name
(string): Internal identifier for this panellabel
(string): Text used as visible panel headerpage
(string): Page to add panel to; one of "format", "settings"order
optional (int): Not yet implementedopen
optional (boolean): Whether panel is open or closed (default:False
)
Provides a simple interface to add a UI button and bind it to a function. Quickbuttons appear on assigned UI panels.
Quickbuttons are represented with the QuickButton
class, which has the following properties:
panel
(string):name
of panel where button will appearname
(string): Internal identifier for this quickbuttonlabel
(string): Text used for visible button labelfunction
(callable): Function to run when button is pressedargs
(any): Argument passed tofunction
when called
Pass a dict to args
and parse it in your function
if multiple arguments are needed.
Register a Quickbutton and assign it to a UI panel. Returns all buttons as list[QuickButton]
.
panel
(string):name
of panel previously registered withui.register_panel
name
(string): Internal identifier for this quickbuttonlabel
(string): Text used for visible button labelfunction
(callable): Function to run when button is pressedargs
(any): Argument passed tofunction
when called
Provides a simple interface to add a UI Markdown block to a panel.
Markdown blocks are represented with the Markdown
class, which has the following properties:
panel
(string):name
of panel where markdown will appearname
(string): Internal identifier for this markdown blockdesc
(string): Markdown-formatted text to display
Register a Markdown block and assign it to a UI panel.
panel
(string):name
of panel previously registered withui.register_panel
name
(string): Internal identifier for this markdown blockdesc
(string): Markdown-formatted text to display
Add custom pages to RotorHazard's frontend with Flask Blueprints.
Adds a Flask Blueprint which can be used to provide access to custom pages/URLs.
blueprint
(blueprint): Flask Blueprint object
Send messages to RotorHazard's frontend.
Send a message which is parsed by the text-to-speech synthesizer.
message
(string): Text of message to be spoken
Send a message which appears in the message center and notification bar.
message
(string): Text of message to display
Send a message which appears as a pop-up alert.
message
(string): Text of message to display
Calls function when a socket event is received.
message
(string): Socket event namehandler
(callable): Function to call
handler
is passed socket data as an argument.
Update data displayed on frontend. Use after modifying data structures with other API methods.
Broadcast UI panel setup to all connected clients.
page
(string): Page to update
Broadcast seat frequencies to all connected clients.
Broadcast pilot data to all connected clients.
Broadcast heat data to all connected clients.
Broadcast race class data to all connected clients.
Broadcast race format data to all connected clients.
Broadcast current heat selection to all connected clients.
Broadcast frequency set data to all connected clients.
Broadcast race setup and status to all connected clients.
Create and access new data structures.
These methods are accessed via RHAPI.fields
Options are simple storage variables which persist to the database and can be presented to users through frontend UI. Each option takes a single value.
Read only Provide a list of options registered by plugins. Does not include built-in options.
Register an option and optioanlly assign it to be desiplayed on a UI panel.
field
(UIField): See UI Fieldspanel
optional (string):name
of panel previously registered withui.register_panel
order
optional (int): Not yet implemented
Pilot Attributes are simple storage variables which persist to the database and can be presented to users through frontend UI. Pilot Attribute values are unique to/stored individually for each pilot.
Pilot Attributes are represented with the PilotAttribute
class, which has the following properties:
id
(int): ID of pilot to which this attribute is assignedname
(string): Name of attributevalue
(string): Value of attribute
Alter pilot attributes with db.pilot_alter
.
Read only
Provides a list of registered PilotAttribute
s.
Register an attribute to be displayed in the UI or otherwise made accessible to plugins.
field
(UIField): See UI Fields
Heat Attributes are simple storage variables which persist to the database. Heat Attribute values are unique to/stored individually for each heat.
Heat Attributes are represented with the HeatAttribute
class, which has the following properties:
id
(int): ID of heat to which this attribute is assignedname
(string): Name of attributevalue
(string): Value of attribute
Alter heat attributes with db.heat_alter
.
Read only
Provides a list of registered HeatAttribute
s.
Register an attribute to be made accessible to plugins.
field
(UIField): See UI Fields
Race Class Attributes are simple storage variables which persist to the database. Race Class Attribute values are unique to/stored individually for each race class.
Heat Attributes are represented with the RaceClassAttribute
class, which has the following properties:
id
(int): ID of race class to which this attribute is assignedname
(string): Name of attributevalue
(string): Value of attribute
Alter race class attributes with db.raceclass_alter
.
Read only
Provides a list of registered RaceClassAttribute
s.
Register an attribute to be made accessible to plugins.
field
(UIField): See UI Fields
Race Attributes are simple storage variables which persist to the database. Race Attribute values are unique to/stored individually for each race.
Race Attributes are represented with the SavedRaceMetaAttribute
class, which has the following properties:
id
(int): ID of race to which this attribute is assignedname
(string): Name of attributevalue
(string): Value of attribute
Alter race attributes with db.race_alter
.
Read only
Provides a list of registered SavedRaceMetaAttribute
s.
Register an attribute to be made accessible to plugins.
field
(UIField): See UI Fields
Race Format Attributes are simple storage variables which persist to the database. Race Format Attribute values are unique to/stored individually for each race format.
Race Format Attributes are represented with the RaceFormatAttribute
class, which has the following properties:
id
(int): ID of race format to which this attribute is assignedname
(string): Name of attributevalue
(string): Value of attribute
Alter race attributes with db.raceformat_alter
.
Read only
Provides a list of registered SavedRaceMetaAttribute
s.
Register an attribute to be made accessible to plugins.
field
(UIField): See UI Fields
Read and modify database values.
These methods are accessed via RHAPI.db
Properties and methods spanning the entire stored event.
Read only
Returns cumulative totals for all saved races as dict
.
Resets database to default state.
A pilot is an individual participant. In order to participate in races, pilots can be assigned to multiple heats.
Pilots are represented with the Pilot
class, which has the following properties:
id
(int): Internal identifiercallsign
(string): Callsignteam
(string): Team designationphonetic
(string): Phonetically-spelled callsign, used for text-to-speechname
(string): Real namecolor
(string): Hex-encoded colorused_frequencies
(string): Serialized list of frequencies this pilot has been assigned when starting a race, ordered by recencyactive
(boolean): Not yet implemented
The sentinel value RHUtils.PILOT_ID_NONE
should be used when no pilot is defined.
Read only
All pilot records. Returns list[Pilot]
.
A single pilot record. Does not include custom attributes. Returns Pilot
.
pilot_id
(int): ID of pilot record to retrieve
All custom attributes assigned to pilot. Returns list[PilotAttribute]
.
pilot_or_id
(pilot|int): Either the pilot object or the ID of pilot
The value of a single custom attribute assigned to pilot. Returns string
regardless of registered field type, or default value.
pilot_or_id
(pilot|int): Either the pilot object or the ID of pilotname
(string): attribute to retrievedefault_value
(optional): value to return if attribute is not registered (uses registered default if available)
ID of pilots with attribute matching the specified attribute/value combination. Returns list[int]
.
name
(string): attribute to matchvalue
(string): value to match
Add a new pilot to the database. Returns the new Pilot
.
name
(optional) (string): Name for new pilotcallsign
(optional) (string): Callsign for new pilotphonetic
(optional) (string): Phonetic spelling for new pilot callsignteam
(optional) (string): Team for new pilotcolor
(optional) (string): Color for new pilot
Alter pilot data. Returns the altered Pilot
pilot_id
(int): ID of pilot to altername
(optional) (string): New name for pilotcallsign
(optional) (string): New callsign for pilotphonetic
(optional) (string): New phonetic spelling of callsign for pilotteam
(optional) (string): New team for pilotcolor
(optional) (string): New color for pilotattributes
(optional) (dict): Attributes to alter, attribute values assigned to respective keys
Delete pilot record. Fails if pilot is associated with saved race. Returns boolean
success status.
pilot_or_id
(int): ID of pilot to delete
Delete all pilot records. No return value.
Heats are collections of pilots upon which races are run. A heat may first be represented by a heat plan which defines methods for assigning pilots. The plan must be seeded into pilot assignments in order for a race to be run.
Heats are represented with the Heat
class, which has the following properties:
id
(int): Internal identifiername
(string): User-facing nameclass_id
(int): ID of associated race classresults
(dict|None): Internal use only; see below_cache_status
: Internal use onlyorder
(int): Not yet implementedstatus
(HeatStatus): Current status of heat asPLANNED
orCONFIRMED
auto_frequency
(boolean): True to assign pilot seats automatically, False for direct assignmentactive
(boolean): Not yet implemented
The sentinel value RHUtils.HEAT_ID_NONE
should be used when no heat is defined.
NOTE: Results should be accessed with the db.heat_results
method and not by reading the results
property directly. The results
property is unreliable because results calulation is delayed to improve system performance. db.heat_results
ensures the calculation is current, will return quickly from cache if possible, or will build it if necessary.
Read only
All heat records. Returns list[Heat]
A single heat record. Returns Heat
.
heat_id
(int): ID of heat record to retrieve
All heat records associated with a specific class. Returns list[Heat]
raceclass_id
(int): ID of raceclass used to retrieve heats
The calculated summary result set for all races associated with this heat. Returns dict
.
heat_or_id
(int|Heat): Either the heat object or the ID of heat
The highest-numbered race round recorded for selected heat. Returns int
.
heat_id
(int): ID of heat
All custom attributes assigned to heat. Returns list[HeatAttribute]
.
heat_or_id
(heat|int): Either the heat object or the ID of heat
The value of a single custom attribute assigned to heat. Returns string
regardless of registered field type, or default value.
heat_or_id
(heat|int): Either the heat object or the ID of heatname
(string): attribute to retrievedefault_value
(optional): value to return if attribute is not registered (uses registered default if available)
ID of heats with attribute matching the specified attribute/value combination. Returns list[int]
.
name
(string): attribute to matchvalue
(string): value to match
Add a new heat to the database. Returns the new Heat
.
name
(optional) (string): Name for new heatraceclass
(optional) (int): Raceclass ID for new heatauto_frequency
(optional) (boolean): Whether to enable auto-frequency
Duplicate a heat record. Returns the new Heat
.
source_heat_or_id
(int|heat): Either the heat object or the ID of heat to copy fromdest_class
(optional) (int): Raceclass ID to copy heat into
db.heat_alter(heat_id, name=None, raceclass=None, auto_frequency=None, status=None, attributes=None)
Alter heat data. Returns tuple of this Heat
and affected races as list[SavedRace]
.
heat_id
(int): ID of heat to altername
(optional) (string): New name for heatraceclass
(optional) (int): New raceclass ID for heatauto_frequency
(optional) (boolean): New auto-frequency setting for heatstatus
(optional) (HeatStatus): New status for heatattributes
(optional) (dict): Attributes to alter, attribute values assigned to respective keys
Delete heat. Fails if heat has saved races associated or if there is only one heat left in the database. Returns boolean
success status.
heat_or_id
(int|heat): ID of heat to delete
Delete all heat records. No return value.
Slots are data structures containing a pilot assignment or assignment method. Heats contain one or more Slots corresponding to pilots who may participate in the Heat. When a heat is calculated, the method
is used to reserve a slot for a given pilot. Afterward, pilot
contains the ID for which the space is reserved. A Slot assignment is only a reservation, it does not mean the pilot has raced regardless of heat status
.
Slots are represented with the HeatNode
class, which has the following properties:
id
(int): Internal identifierheat_id
(int): ID of heat to which this slot is assignednode_index
(int): slot numberpilot_id
(int|None): ID of pilot assigned to this slotcolor
(string): hexadecimal color assigned to this slotmethod
(ProgramMethod): Method used to implement heat planseed_rank
(int): Rank value used when implementing heat planseed_id
(int): ID of heat or class used when implementing heat plan
Database.ProgramMethod
defines the method used when a heat plan is converted to assignments:
ProgramMethod.NONE
: No assignment madeProgramMethod.ASSIGN
: Use pilot already defined inpilot_id
ProgramMethod.HEAT_RESULT
: Assign usingseed_id
as a heat designationProgramMethod.CLASS_RESULT
: Assign usingseed_id
as a race class designation
Import ProgramMethod
with:
from Database import ProgramMethod
Read only
All slot records. Returns list[HeatNode]
.
Slot records associated with a specific heat. Returns list[HeatNode]
.
heat_id
(int): ID of heat used to retrieve slots
db.slot_alter(slot_id, method=None, pilot=None, seed_heat_id=None, seed_raceclass_id=None, seed_rank=None)
Alter slot data. Returns tuple of associated Heat
and affected races as list[SavedRace]
.
slot_id
(int): ID of slot to altermethod
(optional) (ProgramMethod): New seeding method for slotpilot
(optional) (int): New ID of pilot assigned to slotseed_heat_id
(optional) (): New heat ID to use for seedingseed_raceclass_id
(optional) (int): New raceclass ID to use for seedingseed_rank
(optional) (int): New rank value to use for seeding
With method
set to ProgramMethod.NONE
, most other fields are ignored. Only use seed_heat_id
with ProgramMethod.HEAT_RESULT
, and seed_raceclass_id
with ProgramMethod.CLASS_RESULT
, otherwise the assignment is ignored.
Make many alterations to slots in a single database transaction as quickly as possible. Use with caution. May accept invalid input. Does not trigger events, clear associated results, or update cached data. These operations must be done manually if required. No return value.
slot_list
: alist
ofdicts
in the following format:slot_id
(int): ID of slot to altermethod
(optional) (ProgramMethod): New seeding method for slotpilot
(optional) (int): New ID of pilot assigned to slotseed_heat_id
(optional) (): New heat ID to use for seedingseed_raceclass_id
(optional) (int): New raceclass ID to use for seedingseed_rank
(optional) (int): New rank value to use for seeding
Race classes are groups of related heats. Classes may be used by the race organizer in many different ways, such as splitting sport and pro pilots, practice/qualifying/mains, primary/consolation bracket, etc.
Race classes are represented with the RaceClass
class, which has the following properties:
id
(int): Internal identifiername
(string): User-facing namedescription
(string): User-facing long description, accepts markdownformat_id
(int): ID for class-wide required race format definitionwin_condition
(string): ranking algorithmresults
(dict|None): Internal use only; see below_cache_status
: Internal use onlyranking
(dict|None): Calculated race class rankingrank_settings
(string): JSON-serialized arguments for ranking algorithm_rank_status
: Internal use onlyrounds
(int): Number of expected/planned rounds each heat will be runheat_advance_type
(HeatAdvanceType): Method used for automatic heat advanceround_type
(RoundType): Method used for determining round groupingsorder
(int): Not yet implementedactive
(boolean): Not yet implemented
The sentinel value RHUtils.CLASS_ID_NONE
should be used when no race class is defined.
NOTE: Results should be accessed with the db.raceclass_results
method and not by reading the results
property directly. The results
property is unreliable because results calculation is delayed to improve system performance. db.raceclass_results
ensures the calculation is current, will return quickly from cache if possible, or will build it if necessary.
Database.HeatAdvanceType
defines how the UI will automatically advance heats after a race is finished.
HeatAdvanceType.NONE
: Do nothingHeatAdvanceType.NEXT_HEAT
: Advance heat; if allrounds
run advance race classHeatAdvanceType.NEXT_ROUND
: Advance heat ifrounds
has been reached; advance race class after last heat in class
Read only
All race class records. Returns list[RaceClass]
.
A single race class record. Returns RaceClass
.
raceclass_id
(int): ID of race class record to retrieve
All custom attributes assigned to race class. Returns list[RaceClassAttribute]
.
raceclass_or_id
(raceclass|int): Either the race class object or the ID of race class
The value of a single custom attribute assigned to race class. Returns string
regardless of registered field type, or default value.
raceclass_or_id
(raceclass|int): Either the race class object or the ID of race classname
(string): attribute to retrievedefault_value
(optional): value to return if attribute is not registered (uses registered default if available)
ID of race classes with attribute matching the specified attribute/value combination. Returns list[int]
.
name
(string): attribute to matchvalue
(string): value to match
db.raceclass_add(name=None, description=None, raceformat=None, win_condition=None, rounds=None, heat_advance_type=None, round_type=None)
Add a new race class to the database. Returns the new RaceClass
.
name
(optional) (string): Name for new race classdescription
(optional) (string): Description for new race classraceformat
(optional) (int): ID of format to assignwin_condition
(optional) (string): Class ranking identifier to assignrounds
(optional) (int): Number of rounds to assign to race classheat_advance_type
(optional) (HeatAdvanceType): Advancement method to assign to race classround_type
(optional) (RoundType): Method used for determining round groupings
Duplicate a race class. Returns the new RaceClass
.
source_class_or_id
(int|RaceClass): Either a race class object or the ID of a race class
db.raceclass_alter(raceclass_id, name=None, description=None, raceformat=None, win_condition=None, rounds=None, heat_advance_type=None, round_type=None, rank_settings=None, attributes=None)
Alter race class data. Returns tuple of this RaceClass
and affected races as list[SavedRace]
.
raceclass_id
(int): ID of race class to altername
(optional) (string): Name for new race classdescription
(optional) (string): Description for new race classraceformat
(optional) (int): ID of format to assignwin_condition
(optional) (string): Class ranking identifier to assignrounds
(optional) (int): Number of rounds to assign to race classheat_advance_type
(optional) (HeatAdvanceType): Advancement method to assign to race classround_type
(optional) (RoundType): Method used for determining round groupings-rank_settings
(optional) (dict): arguments to pass to class rankingattributes
(optional) (dict): Attributes to alter, attribute values assigned to respective keys
The calculated summary result set for all races associated with this race class. Returns dict
.
raceclass_or_id
(int|RaceClass): Either the race class object or the ID of race class
The calculated ranking associated with this race class. Returns dict
.
raceclass_or_id
(int|RaceClass): Either the race class object or the ID of race class
Delete race class. Fails if race class has saved races associated. Returns boolean
success status.
raceclass_or_id
(int|RaceClass): Either the race class object or the ID of race class
Delete all race classes. No return value.
Race formats are profiles of properties used to define parameters of individual races. Every race has an assigned format. A race formats may be assigned to a race class, which forces RotorHazard to switch to that formatwhen running races within the class.
Race formats are represented with the RaceFormat
class, which has the following properties:
id
(int): Internal identifiername
(string): User-facing nameunlimited_time
(int): True(1) if race clock counts up, False(0) if race clock counts downrace_time_sec
(int): Race clock duration in seconds, unused ifunlimited_time
is True(1)lap_grace_sec
(int): Grace period duration in seconds, -1 for unlimited, unused ifunlimited_time
is True(1)staging_fixed_tones
(int): Number of staging tones always played regardless of random delaystart_delay_min_ms
(int): Minimum period for random phase of staging delay in millisecondsstart_delay_max_ms
(int): Maximum duration of random phase of staging delay in millisecondsstaging_delay_tones
(int): Whether to play staging tones each second during random delay phasenumber_laps_win
(int): Number of laps used to declare race winner, if > 0win_condition
(int): Condition used to determine race winner and race rankingteam_racing_mode
(boolean): Whether local simultaneous team racing mode will be usedstart_behavior
(int): Handling of first crossingpoints_method
(String): JSON-serialized arguments for points algorithm
The sentinel value RHUtils.FORMAT_ID_NONE
should be used when no race format is defined.
The following values are valid for staging_delay_tones
.
- 0: None
- 2: Each Second
The following values are valid for win_condition
.
- 0: None
- 1: Most Laps in Fastest Time
- 2: First to X Laps
- 3: Fastest Lap
- 4: Fastest Consecutive Laps
- 5: Most Laps Only
- 6: Most Laps Only with Overtime
The following values are valid for start_behavior
.
- 0: Hole Shot
- 1: First Lap
- 2: Staggered Start
Notice: The race format specification is expected to be modified in future versions. Please consider this while developing plugins.
- The type for
staging_delay_tones
may change to boolean. - The type for
unlimited_time
may change to boolean. - The type for
win_condition
may change to a members of dedicated class or become string-based for extensibility. - The type for
start_behavior
may change to a members of dedicated class.
Read only
All race formats. Returns list[RaceFormat]
A single race format record. Returns RaceFormat
.
format_id
(int): ID of race format record to retrieve
All custom attributes assigned to race format. Returns list[RaceFormatAttribute]
.
raceformat_or_id
(raceformat|int): Either the race format object or the ID of race format
The value of a single custom attribute assigned to race format. Returns string
regardless of registered field type, or default value.
raceformat_or_id
(raceformat|int): Either the race format object or the ID of race formatname
(string): attribute to retrievedefault_value
(optional): value to return if attribute is not registered (uses registered default if available)
ID of race formats with attribute matching the specified attribute/value combination. Returns list[int]
.
name
(string): attribute to matchvalue
(string): value to match
db.raceformat_add(name=None, unlimited_time=None, race_time_sec=None, lap_grace_sec=None, staging_fixed_tones=None, staging_delay_tones=None, start_delay_min_ms=None, start_delay_max_ms=None, start_behavior=None, win_condition=None, number_laps_win=None, team_racing_mode=None, points_method=None)
Add a new race format to the database. Returns the new RaceFormat
.
name
(optional) (string): Name for new race formatunlimited_time
(optional) (int): Unlimited Time setting for new race formatrace_time_sec
(optional) (int): Race duration for new race formatlap_grace_sec
(optional) (int): Grace period for new race formatstaging_fixed_tones
(optional) (int): Fixed tones for new race formatstaging_delay_tones
(optional) (int): Delay tones setting for new race formatstart_delay_min_ms
(optional) (int): Delay minimum for new race formatstart_delay_max_ms
(optional) (int): Maximum delay duration for new race formatstart_behavior
(optional) (int): First crossing behavior for new race formatwin_condition
(optional) (int): Win condition for new race formatnumber_laps_win
(optional) (int): Lap count setting for new race formatteam_racing_mode
(optional) (boolean): Team racing setting for new race formatpoints_method
(optional) (string): JSON-serialized arguments for new race format
Duplicate a race format. Returns the new RaceFormat
.
source_format_or_id
(int|RaceFormat): Either a race format object or the ID of a race format
db.raceformat_alter(raceformat_id, name=None, unlimited_time=None, race_time_sec=None, lap_grace_sec=None, staging_fixed_tones=None, staging_delay_tones=None, start_delay_min_ms=None, start_delay_max_ms=None, start_behavior=None, win_condition=None, number_laps_win=None, team_racing_mode=None, points_method=None, points_settings=None, attributes=None)
Alter race format data. Returns tuple of this RaceFormat
and affected races as list[SavedRace]
.
raceformat_id
(int): ID of race format to altername
(optional) (string): Name for new race formatunlimited_time
(optional) (int): Unlimited Time setting for new race formatrace_time_sec
(optional) (int): Race duration for new race formatlap_grace_sec
(optional) (int): Grace period for new race formatstaging_fixed_tones
(optional) (int): Fixed tones for new race formatstaging_delay_tones
(optional) (int): Delay tones setting for new race formatstart_delay_min_ms
(optional) (int): Delay minimum for new race formatstart_delay_max_ms
(optional) (int): Maximum delay duration for new race formatstart_behavior
(optional) (int): First crossing behavior for new race formatwin_condition
(optional) (int): Win condition for new race formatnumber_laps_win
(optional) (int): Lap count setting for new race formatteam_racing_mode
(optional) (boolean): Team racing setting for new race formatpoints_method
(optional) (string): JSON-serialized arguments for new race formatpoints_settings
(optional) (dict): arguments to pass to class rankingattributes
(optional) (dict): Attributes to alter, attribute values assigned to respective keys
Delete race format. Fails if race class has saved races associated, is assigned to the active race, or is the last format in database. Returns boolean
success status.
raceformat_id
(int): ID of race format to delete
Resets race formats to default. No return value.
Frequency sets contain a mapping of band/channel/frequency values to seats. They also store enter and exit values.
Frequency sets are represented with the Profiles
class, which has the following properties:
id
(int): Internal identifiername
(string): User-facing namedescription
(string): User-facing long descriptionfrequencies
(string): JSON-serialized frequency objects per seatenter_ats
(string): JSON-serialized enter-at points per seatexit_ats
(string): JSON-serialized exit-at points per seatf_ratio
(int): Unused legacy value
frequencies
can be JSON-unserialized (json.loads) to a dict:
b
: list of band designations, ordered by seat number; values may string be nullc
: list of band-channel designations, ordered by seat number; values may int be nullf
: list of frequencies, ordered by seat number; values are int
enter_ats
and exit_ats
can be JSON-unserialized (json.loads) to a dict:
v
: list of enter/exit values, ordered by seat number; values are int
The length of lists stored in frequencies
, enter_ats
, and exit_ats
may not match the number of seats. In these cases values are either not yet available (if too few) or no longer used (if too many) for higher-index seats.
The sentinel value RHUtils.FREQUENCY_ID_NONE
should be used when no frequency is defined.
Notice: The frequency set specification is expected to be modified in future versions. Please consider this while developing plugins.
- Rename class
- Siimplify serialization for
enter_ats
,exit_ats
- Remove of unused
f_ratio
Read only
All frequency set records. Returns list[Profiles]
.
A single frequency set record. Returns Profiles
.
set_id
(int): ID of frequency set record to retrieve
Add a new frequency set to the database. Returns the new Profiles
.
name
(string): Name for new frequency setdescription
(string): Description for new frequency setfrequencies
(string|dict): Frequency, band, and channel information for new frequency set, as described above in serialized JSON (string) or unserialized (dict) formenter_ats
(string|dict): Enter-at points for new frequency set, as described above in serialized JSON (string) or unserialized (dict) formexit_ats
(string|dict): Exit-at points for new frequency set, as described above in serialized JSON (string) or unserialized (dict) form
Duplicate a frequency set. Returns the new Profiles
.
source_set_or_id
(int|Profiles): Either a frequency set object or the ID of a frequency set
db.frequencyset_alter(set_id, name=None, description=None, frequencies=None, enter_ats=None, exit_ats=None)
Alter frequency set data. Returns the altered Profiles
object.
set_id
(int): ID of frequency set to altername
(string): Name for new frequency setdescription
(string): Description for new frequency setfrequencies
(string|dict): Frequency, band, and channel information for new frequency set, as described above in serialized JSON (string) or unserialized (dict) formenter_ats
(string|dict): Enter-at points for new frequency set, as described above in serialized JSON (string) or unserialized (dict) formexit_ats
(string|dict): Exit-at points for new frequency set, as described above in serialized JSON (string) or unserialized (dict) form
Delete frequency set. Fails if frequency set is last remaining. Returns boolean
success status.
set_or_id
(int|Profiles): Either a frequency set object or the ID of a frequency set
Resets frequency sets to default. No return value.
Saved races are sets of stored information about race history. The Saved race object stores results and metadata. For a complete picture of a saved race, it is necessary to fetch associated Pilot Runs and Laps.
Saved races are represented with the SavedRaceMeta
class, which has the following properties:
id
(int): Internal identifierround_id
(int): round numberheat_id
(int): ID of associated heatclass_id
(int): ID of associated race class, orCLASS_ID_NONE
format_id
(int): ID of associated race formatstart_time
(int): Internal (monotonic) time value of race startstart_time_formatted
(string): Human-readable time of race startresults
(dict|None): Internal use only; see below_cache_status
: Internal use only
NOTE: Results should be accessed with the db.race_results
method and not by reading the results
property directly. The results
property is unreliable because results calulation is delayed to improve system performance. db.race_results
ensures the calculation is current, will return quickly from cache if possible, or will build it if necessary.
Read only
All saved race records. Returns list[SavedRaceMeta]
.
A single saved race record, retrieved by ID. Returns SavedRaceMeta
.
race_id
(int): ID of saved race record to retrieve
A single saved race record, retrieved by heat and round. Returns SavedRaceMeta
.
heat_id
(int): ID of heat used to retrieve saved raceround_number
(int): round number used to retrieve saved race
Saved race records matching the provided heat ID. Returns list[RaceClass]
.
heat_id
(int): ID of heat used to retrieve saved race
Saved race records matching the provided race class ID. Returns list[RaceClass]
.
raceclass_id
(int): ID of race class used to retrieve saved race
All custom attributes assigned to race. Returns list[SavedRaceMetaAttribute]
.
race_or_id
(race|int): Either the race object or the ID of race
The value of a single custom attribute assigned to race. Returns string
regardless of registered field type, or default value.
race_or_id
(race|int): Either the race object or the ID of racename
(string): attribute to retrievedefault_value
(optional): value to return if attribute is not registered (uses registered default if available)
ID of races with attribute matching the specified attribute/value combination. Returns list[int]
.
name
(string): attribute to matchvalue
(string): value to match
Alter race data. Supports only custom attributes. No return value.
race_id
(int): ID of race to alterattributes
(optional) (list[dict]): Attributes to alter, attribute values assigned to respective keys
Calculated result set for saved race. Returns dict
.
race_or_id
(int|SavedRaceMeta): Either the saved race object or the ID of saved race
Delete all saved races. No return value.
Pilot Runs store data related to individual pilots in each race, except lap crossings. Each saved race has one or more pilot runs associated with it.
Saved races are represented with the SavedPilotRace
class, which has the following properties:
id
(int): Internal identifierrace_id
(int): ID of associated saved racenode_index
(int): Seat numberpilot_id
(int): ID of associated pilothistory_values
(string): JSON-serialized raw RSSI datahistory_times
(string): JSON-serialized timestamps for raw RSSI datapenalty_time
(int): Not implementedpenalty_desc
(string): Not implementedenter_at
(int): Gate enter calibration pointexit_at
(int): Gate exit calibration pointfrequency
(int): Active frequency for this seat at race time
Read only
All pilot run records. Returns list[SavedPilotRace]
.
A single pilot run record, retrieved by ID. Returns SavedPilotRace
.
run_id
(int): ID of pilot run record to retrieve
Pilot run records matching the provided saved race ID. Returns list[SavedPilotRace]
.
race_id
(int): ID of saved race used to retrieve pilot runs
Laps store data related to start gate crossings. Each pilot run may have one or more laps associated with it. When displaying laps, be sure to reference the associated race format.
Laps are represented with the SavedRaceLap
class, which has the following properties:
id
(int): Internal identifierrace_id
(int): ID of associated saved racepilotrace_id
(int): ID of associated pilot runnode_index
(int): Seat numberpilot_id
(int): ID of associated pilotlap_time_stamp
(int): Milliseconds since race start timelap_time
(int): Milliseconds since previous counted laplap_time_formatted
(string): Formatted user-facing textsource
(LapSource): Lap source typedeleted
(boolean): True if record should not be counted in results calculations
Database.LapSource
describes the method used to enter a lap into the database:
LapSource.REALTIME
: Lap added by (hardware) interface in real timeLapSource.MANUAL
: Lap added manually by user in UILapSource.RECALC
: Lap added after recalculation (marshaling) or RSSI dataLapSource.AUTOMATIC
: Lap added by other automatic processLapSource.API
: Lap added by API (plugin)
Read only
All lap records. Returns list[SavedRaceLap]
.
Lap records matching the provided pilot run ID. Returns list[SavedRaceLap]
.
run_id
(int): ID of pilot run used to retrieve laps
Options are settings that apply to a server globally.
Options are stored with the GlobalSettings
class, which has the following properties:
id
(int): Internal identifieroption_name
(string): name of optionoption_value
(string): value of option
Read only
All options. Returns list[GlobalSettings]
.
Value of option with the provided name. Returns the option value.
name
(string): name of option to retrievedefault
(optional) (string): Value to return if option does not existas_int
(optional) (boolean): Return value as integer instead of string
Set value for the option with provided name. No return value.
name
(string): name of option to altervalue
(string): new value for option
Delete all options. No return value.
View and import/export data from the database via registered DataImporter
and DataExporter
. See Data Exporters and Data Importers.
These methods are accessed via RHAPI.io
Read only
All registered exporters. Returns list[DataExporter]
.
Run selected exporter. Returns output of exporter or False
if error.
exporter_id
(string): identifier of exporter to run
Read only
All registered importers. Returns list[DataImporter]
.
Run selected importer on supplied data
. Returns output of importer or False
if error.
importer_id
(string): identifier of importer to rundata
(any): data to importimport_args
(optional) (): arguments passed to the importer, overrides defaults
View and Generate heats via registered HeatGenerator
. See Heat Generators.
These methods are accessed via RHAPI.heatgen
Read only
All registered generators. Returns list[HeatGenerator]
.
Run selected generator, creating heats and race classes as needed. Returns output of generator or False
if error.
generator_id
(string): identifier of generator to rungenerate_args
(dict): arguments passed to the generator, overrides defaults
View registered RaceClassRankMethods
.
These methods are accessed via RHAPI.classrank
Read only
All registered class ranking methods. Returns dict
with the following format:
name
:RaceClassRankMethod
View registered RacePointsMethods
.
These methods are accessed via RHAPI.points
Read only
All registered race points methods. Returns dict
with the following format:
name
:RacePointsMethod
Activate and manage connected LED displays via registered LEDEffects
.
These methods are accessed via RHAPI.led
Read only Returns True if LED system is enabled.
Read only
All registered LED effects. Returns list[LEDEffects]
.
LED effect assigned to event. Returns LEDEffect
or None if event does not exist
event
(string): event to retrieve effect from
Assign effect to event. Returns boolean success value.
event
(string): event to assignname
(string): effect to assign to event
Clears LEDs. No return value.
Color of seat in active race. Returns Color
.
seat_index
(int): Seat numberfrom_result
(optional) (boolean): True to use previously active (cached) race data
Immediately activate an LED effect. Should usually be called asynchronously with gevent.spawn()
.
args
(dict): Must includehandler_fn
to activate; other arguments are passed to handler
View and manage connected Video Receiver devices.
These methods are accessed via RHAPI.vrxcontrol
Notice: The vrx control specification is expected to be modified in future versions. Please consider this while developing plugins.
Read only Returns True if VRx control system is enabled.
Read only Returns status of VRx control system.
Read only Returns list of attached VRx control devices.
Shuts down VRx control system.
List VRx control deviced connected with a specific pilot.
seat
(int): seat numberpilot_id
(int): ID of pilot
View and manage the currently active race.
These methods are accessed via RHAPI.race
Read only
Pilot IDs, indexed by seat. Returns list[int]
.
To change pilots, adjust the corresponding heat (identified by race.heat
).
Read only
Team of each pilot, indexed by seat. Returns list[string]
.
To change teams, adjust the corresponding pilot (identified by matching seat index in race.pilots
).
Read only
Total number of seats/slots. Returns int
.
Read only
Active color for each seat, indexed by seat. Returns list[Color]
.
Read only Loads color set into current race based on color mode and values in database. No return value.
Read/write
ID of assigned heat (int
or None
). None
is practice mode.
To change active heat options, adjust the assigned heat.
Read/write
ID of current frequency set (int
).
To change active frequency set options, adjust the assigned frequency set.
Read/write
Active race format object. Returns RaceFormat
, or None
if timer is in secondary mode.
To change active format options, adjust the assigned race format.
Read only
Current status of system. Returns RaceStatus
.
RHRace.RaceStatus
describes the current state:
RaceStatus.READY
: Ready to start a new race, no race runningRaceStatus.STAGING
: System is staging, race begins imminentlyRaceStatus.RACING
: Racing is underwayRaceStatus.DONE
: System no longer listening for lap crossings, race results must be saved or discarded
Read only
Internal (monotonic) timestamp of race staging start time. Returns int
Read only
System timestamp of race start time. Returns datetime
.
Read only
Internal (monotonic) timestamp of race start time. Is a future time during staging. Returns int
.
Read only
Internal (monotonic) timestamp of race end time. Invalid unless race.status
is DONE
. Returns int
.
Read only
Flag indicating whether pilot in a seat has completed all laps. Returns dict
with the format id
(int):value
(boolean).
Read only
Calculated lap results. Returns dict
.
Read only
Whether any laps have been recorded for this race. Returns boolean
.
Read only
All lap data. Returns list[dict]
.
All lap data, removing deleted laps. Returns list[dict]
.
filter_late_laps
(optional): SetTrue
to also remove laps flagged as late.
Add a lap record to the current race. Laps must be entered sequentially. No return value.
seat_index
(int): seat number on which to add laptimestamp
(int): timestamp of lap to add, in server monotonic time
Read only
Calculated race results. Returns dict
.
Read only
Calculated race team results. Returns dict
, or None
if not in team mode.
Read only
True if a winner has been declared. Returns boolean
.
Read only
Callsign of race winner, if declared. Returns str
, or None
.
Read only
Phonetic of race winner, if declared. Returns str
, or None
.
Read only
Lap count of race winner, if declared. Returns int
, or None
.
Read only
Pilot database ID of race winner, if declared. Returns int
, or None
.
Read only
Callsign of previous race winner, if declared. Updates upon race save. Returns str
, or None
.
Read only
Phonetic of previous race winner, if declared. Updates upon race save.. Returns str
, or None
.
Read only
Pilot database ID of previous race winner, if declared. Updates upon race save. Returns int
, or None
.
Read only
Lap count of current race leader. Returns int
, or None
.
Read only
Pilot database ID of current race leader. Returns int
, or None
.
Read only
Internal (monotonic) timestamp of scheduled race staging start time. Returns int
, or None
if race is not scheduled.
Schedule race with a relative future time offset. Fails if race.status
is not READY
. Cancels existing schedule if both values are falsy. Returns boolean success value.
sec_or_none
: seconds ahead to schedule raceminutes
(optional): minutes ahead to schedule race
Begin race staging sequence. May fail if race.status
is not READY
. No return value.
Stop race. No return value.
doSave
(optional): run race data save routines immediately after stopping
Save laps and clear race data. May activate heat advance and other procedures. No return value.
Clear laps and reset race.status
to READY
. Fails if race.status
is STAGING
or RACING
—stop race before using. No return value.
View result data for all races, heats, classes, and event totals.
These methods are accessed via RHAPI.eventresults
Read only
Calculated cumulative results. Returns dict
.
View and retrieve loaded translation strings.
These methods are accessed via RHAPI.language
Read only
List of available languages. Returns list[string]
.
Read only
Full translation dictionary of all loaded languages. Returns dict
.
Translate text
. Returns translated string
, or text
if not possible.
-text
(string): Input to translate
-domain
(optional) (string): Language to use, overriding system setting
View information provided by the harware interface layer.
These methods are accessed via RHAPI.interface
Read only
Hardware interface information. Returns list[Node]
.
View data collected by environmental sensors such as temperature, voltage, and current.
These methods are accessed via RHAPI.sensors
Read only
All sensor names and data. Returns dict
of name
(string):Sensor
.
Read only
List of available sensors. Returns list[string]
.
Read only
List of sensor data. Returns list[Sensor]
.
Individual sensor data. Returns Sensor
.
name
(string): Name of sensor to retrieve
Information and functions relating to server state.
These methods are accessed via RHAPI.server
When enabled, each time the server heartbeat function runs a Evt.HEARTBEAT
event will be triggered. No return value.
Read only
Server information. Returns dict
.
Read only
Currently loaded plugins. Returns list[plugin]
.
Read only
Time this server was started, in epoch milliseconds. Returns float
.
Read only
Time this server was started, in monotonic seconds. Returns float
.
Read only
Conversion offset between monotonic seconds and epoch milliseconds. Returns float
.
Read only
Time this server was started, in epoch milliseconds, displayed without decimals. Returns string
.
Read only
Time this server was started, formatted for readability. Returns string
.
Convert time value from server monotonic seconds to epoch milliseconds, using this server's conversion offset. Returns float
.
secs
(int|float): time in monotonic seconds
Convert time value from epoch milliseconds to server monotonic seconds, using this server's conversion offset. Returns float
.
ms
(int|float): time in epoch milliseconds
Read only
List of sensor data. Returns list[Sensor]
.
Read only
System path to server instance. Returns string
.
Read only
System path to user data directory. Returns string
.
Helper functions and utilities for data handling.
These methods are accessed via RHAPI.utils
Convert milliseconds converted to formatted time (00:00.000). Returns string
.
time_format
(optional) (string): Time format string, overriding user-specified format
Convert milliseconds to formatted time with leading zeros removed (0:00.000). Returns string
.
time_format
(optional) (string): Time format string, overriding user-specified format
Convert milliseconds to formatted phonetic callout time (0 0.0). Returns string
.
time_format
(optional) (string): Time format string, overriding user-specified format
Generate unique name within a naming context. Returns desired_name
if possible, otherwise adds an incremental token: "Name", "Name 2". Returns string
.
desired_name
(string): desired nameother_names
(list[string]): list of names to compare against and avoid
Generate unique name within a naming context. Always adds an incremental token to base_name
: "Name 1", "Name 2". Returns string
.
base_name
(string): desired base nameother_names
(list[string]): list of names to compare against and avoid
Convert HSL color values to a hexadecimal string. Returns string
.
h
(int|float): hue component, from 0 to <360s
(int|float): saturation component, from 0 to 100l
(int|float): luminance component, from 0 to 100
Convert hexadecimal string color to packed int. Accepts strings with or without "#" prefix. Returns int
.
hex_color
(string): hexadecimal color string to convert
Alter the output of functions and processes at specified hooks.
These methods are accessed via RHAPI.filters
For example, the Flt.EMIT_PHONETIC_DATA
hook runs just before lap announcement data is sent to the frontend. Adding a filter to this hook allows the filter to alter the text that is read aloud.
Add a new filter function to an existing hook. The filter will be run when the hook is triggered.
hook
(Flt|string): Hook to attach this filter toname
(string): Internal identifier for this filterfn
(function): Function to run when the hook is triggeredpriority
(optional) (int): Order in which this filter will run among all attached to this hook
Remove a filter from a hook.
hook
(Flt|string): Hook from which filter to remove is attachedname
(string): Internal identifier of filter to remove
Run filters attached to specified hook.
hook
(Flt|string): Hook on which filters will be calleddata
(any): Data supplied to filters attached to hook