Table des matières

API description for the conception of addons

Presentation

Arbre-Analyste comes with a rich API to design advanced addons.

You can see below an example of addon.

# Open an Open-PSA file
AA.OpenOPSA("fault-tree.xml")
# Find the gate with name "G01"
element = AA.Elements.GetGateByName("G01")
# element is the gate named "G01", we compute it
results = element.Compute(8760)
# We show the probability at 8760h
AA.Windows.MsgBox("Probability of G01",
                  "The probability of 'G01' at t=8760h is Q=%e"%results["Q"])

Addons have to be developped with the Python language version 3. You can get its documentation at this address: https://docs.python.org/3/

Anatomy of an addon

The anatomy of an addon have to respect the following rules.

  1. All parts of the addon have to be in the same directory;
  2. The directory of the addon have to be in the “externe\modules\” directory of the Arbre-Analyste path;
  3. main.py have to be the entry script of your addon.

For example, the anatomy of the simplest addon is :

In addition, in the “main.py” file, you can specify different informations:

Example:

# -*- coding: utf8 -*-
 
"""
__plugin_version 1.0
__plugin_author M. DUPOND marc.dupond at webmail.com
__plugin_description The "Hello world" script
__plugin_platform all
__plugin_arbre-analyste_minimum 2.0.0
"""
 
AA.Windows.MsgBox("My first addon", "Hello world!")

How to distribute an addon

To distribute an addon, you have to create a *.zpk file. A *.zpk file is just a zip file which contains all addon directories. It's realy important to zip the addon directory and not the file in the directory. Rename the zip extension to zpk extension, that's all.

In addition, you can zip many addons in the same zpk file.

API documentation

class AA

AA class is the entry point of the API. This class contains all functions of the API.

class AA.Compute

AA.Compute class contains all functions to perform calculations.

Certain functions of AA.Compute class return a compute object. The compute object is defined as below.

Example:

# Get a gate
myTopGate = AA.Elements.GetGateByName("G001")
# Create a new programmed calculation
myCompute = AA.Compute.Create("My first compute", myTopGate, 8760)
# Compute
myResults = myCompute.Compute()
# Display the unavailability
AA.Windows.MsgBox("My top gate probability", "The probability is Q=%e"%myResults["Q"])
# Remove the programmed calculation
myCompute.Delete()

class AA.Elements

AA.Elements class contains all functions to create, edit and delete elements (gate, transfert, basic event, house event) in fault tree.

Certain functions of AA.Elements class return an element object. The element object is defined as below.

Example:

# Creation of the top gate
myTopGate = AA.Elements.Create("or")
# Creation of the basic event parameter
myParameter = AA.Parameters.Create("My parameter","probability", 1e-6)
# Creation of 10 basic events
for num in range(10):
    # Creation of the basic event
    be = AA.Elements.Create("basic")
    # Modification of its gate parent
    be.Parent(myTopGate)
    # Configuration of its probability law
    be.Law("constant", myParameter)
# Organization of the fault tree
myTopGate.Organize()
# Computation of the top gate
results = myTopGate.Compute(1)
# Print the Q and F results
AA.Windows.MsgBox("Results", "Q=%e and F=%e"%(results["Q"], results["F"]))

class AA.Pages

AA.Pages class contains all functions to create, edit and delete pages.

Certain functions of AA.Pages class return a page object. The page object is defined as below.

class AA.Parameters

AA.Parameters class contains all functions to create, edit and delete named parameters (lambda, probability, MTTR, time etc…).

Certain functions of AA.Parameters class return a parameter object. The parameter object is defined as below.

The example bellow create a window which contains all parameters informations to be modified by the user and finally save the user modifications.

# Creation of the function which gets data from the text box and saves modifications
def save():
    global myWindow
    # Save modifications for all parameters
    for line in myWindow.Get().splitlines():
        data = line.split("\t")
        try:
            p = AA.Parameters.GetById(int(data[0]))
            if p:
                p.Name(data[3])
                p.Value(float(data[7]))
        except:
            pass
    # Show confirmation
    AA.Windows.MsgBox("Global edition of parameters","Modifications of parameters saved.")
    # Quit
    myWindow.Close()
 
 
# Creation of a text box
myWindow = AA.Windows.TextBox("Global edition of parameters",
                              "You can edit parameters bellow and then click on save button. However, never change the Id value.",
                              "Id\tType\t\tName\t\t\t\tValue",
                              "Save", save)
# We print parameter informations
for p in AA.Parameters.GetAll():
    myWindow.Add("\n%04i\t%s\t\t%s\t\t\t\t%g"%(p.GetId(), p.GetType(), p.Name(), p.Value()))

class AA.Windows

AA.Windows class contains all functions to create, edit and delete windows.

Certain functions of AA.Windows class return a window object. The window object is defined as bellow.

To create advanced windows, you can go to this address Tkinter documentation to get a complete documentation.