Skip to content

minisky_example

minisky_example

Example runtime-local MiniSky plugin.

plugin module-attribute

plugin = Plugin(build=build)

Example

Example(random: Random)

Bases: Entity

Track passenger count for every aircraft in the owning runtime.

Source code in packages/minisky-example/src/minisky_example/__init__.py
27
28
29
30
31
32
def __init__(self, random: Random) -> None:
    super().__init__()
    self.random = random
    self.updates = 0
    with self.settrafarrays():
        self.npassengers = np.array([])

random instance-attribute

random = random

updates instance-attribute

updates = 0

npassengers instance-attribute

npassengers = np.array([])

create

create(n: int = 1) -> None
Source code in packages/minisky-example/src/minisky_example/__init__.py
34
35
36
def create(self, n: int = 1) -> None:
    super().create(n)
    self.npassengers[-n:] = [self.random.randint(50, 250) for _ in range(n)]

update

update() -> None

Count periodic execution.

Source code in packages/minisky-example/src/minisky_example/__init__.py
38
39
40
41
@hook(interval=5.0)
def update(self) -> None:
    """Count periodic execution."""
    self.updates += 1

passenger_count

passenger_count(index: AcId) -> Result[str, str]

See stack command: PASSENGERS

Show the number of passengers on an aircraft.

Source code in packages/minisky-example/src/minisky_example/__init__.py
43
44
45
46
47
@command(name="PASSENGERS")
def passenger_count(self, index: AcId) -> Result[str, str]:
    """Show the number of passengers on an aircraft."""
    callsign = self.traffic.callsign[index]
    return Ok(f"Aircraft {callsign} has {int(self.npassengers[index])} passengers")

set_passenger_count

set_passenger_count(index: AcId, count: Annotated[int, Ge(0), Le(500)]) -> Result[str, str]

See stack command: PASSENGERS

Set the number of passengers on an aircraft.

Source code in packages/minisky-example/src/minisky_example/__init__.py
49
50
51
52
53
54
55
56
@command(name="PASSENGERS")
def set_passenger_count(
    self, index: AcId, count: Annotated[int, Ge(0), Le(500)]
) -> Result[str, str]:
    """Set the number of passengers on an aircraft."""
    callsign = self.traffic.callsign[index]
    self.npassengers[index] = count
    return Ok(f"Set {callsign} passengers to {count}")

build

build(context: PluginContext[object]) -> PluginSpec
Source code in packages/minisky-example/src/minisky_example/__init__.py
14
15
16
def build(context: PluginContext[object]) -> PluginSpec:
    context.mount(Example(context.python_random))
    return context.finish()