Arbre-Analyste

Outils pour utilisateurs


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 :

  • C:\Program files\Arbre-Analyste\externe\modules\My new addon\main.py

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

  • __plugin_version Set the version of the addon
  • __plugin_author Set informations about authors
  • __plugin_description Set a description
  • __plugin_platform Set the platform compatibility (win32, linux64, all)
  • __plugin_arbre-analyste_minimum Set the minimal version of Arbre-Analyste

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.

  • bool AA.OpenProject( file ) Open an Arbre-Analyste project from file
  • bool AA.SaveProject( file ) Save an Arbre-Analyste project to file
  • bool AA.OpenOPSA( file ) Open an Open-PSA STRICT project from file
  • bool AA.SaveOPSA( file ) Save an Open-PSA STRICT project to file
  • bool AA.New() Create an empty project
  • string AA.GetLang() Get the user's language
  • list of int AA.GetVersion() Get the version of Arbre-Analyste
  • class AA.Compute Class to create and compute calculations
  • class AA.Elements Class to create and edit fault tree's elements (gates, basic events etc…)
  • class AA.Pages Class to create and edit pages
  • class AA.Parameters Class to create and edit named parameters
  • class AA.Windows Class to create and edit windows and dialogs

class AA.Compute

AA.Compute class contains all functions to perform calculations.

  • compute object AA.Compute.Create ( name , gate , time = 1 ) Create a new programmed calculation.
  • compute object AA.Compute.GetByName ( name ) Get a programmed calculation by its name.
  • list of compute object AA.Compute.GetAll () Get a list which contains all programmed calculations.
  • dictionnary AA.Compute.Compute ( element object gate , time = 1 , zero = 0 , step = None , maxOrder = 100 , minProbability = 0 ) Computes and returns all results.
    • Q : Unavailability
    • F : Unreliability
    • L : Conditional Failure Intensity
    • Lavg : Average Conditional Failure Intensity
    • W : Unconditional Failure Intensity
    • T : Time
    • MCS : list of min cut sets
    • IMPORTANCE : list of importance factors of basic events
    • PROBABILITY : list of unavailability and average unavailability function of time
    • FAILURE : list of Conditional Failure Intensity, average Conditional Failure Intensity and unreliability function of time

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

  • bool or string Name ( name = None ) Change the name if name is specified else return the name.
  • bool or list Time ( time = None , zero = 0 , step = None ) Change time parameters if time is specified else return a list which contains T0, T, STEP.
  • bool or element object Gate ( element object gate = None) Change the gate if gate is specified else return an element object of the gate.
  • bool HTML ( string file ) Compute and create a HTML report.
  • dictionnary Compute () Compute and return a dictionary which contains all results as it is described above.
  • bool Delete () Delete the programmed calculation.

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.

  • element object AA.Elements.Create( type = “or” , coords = (500 , 50) ) Create a new element (gates, transfers, basic events or house events). type can be “or”, “and”, “atleast”, “nor”, “nand”, “house”, “basic”.
  • list element object AA.Elements.GetByName( name ) Get a list of all elements found by their name.
  • element object AA.Elements.GetGateByName( name ) Get the only gate found bye its name
  • list element object AA.Elements.GetBasicByName( name ) Get a list of all basic events found by their name.
  • list element object AA.Elements.GetTransfertByName( name ) Get a list of all transfers found by their name.
  • lit element object AA.Elements.GetHouseByName( name ) Get a list of all house events found by their name.
  • element object AA.Elements.GetById( id ) Get an element by it id.
  • list element object AA.Elements.GetAll() Get a list of all elements.

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

  • integer GetId() Return the id of the element.
  • string GetType() Return the type of the element. Can be “or”, “and”, “atleast”, “nor”, “nand”, “house”, “basic”.
  • bool or string Name( name = None ) Change the name if name is specified else return the name of the element.
  • bool or string Description( text = None ) Change the description if text is specified else return the description of the element.
  • bool or list Position( coords = None ) Change the position if the list coords is specified else return the position of the element. The list coords is constituted by a list of x and y.
  • bool or element object Parent( element object parent = ””) If parent is not specified then return the element object of the parent gate of the element. If parent is None then split the element of its parent. Finally, if parent is an element object then join the current element and the gate together.
  • list element object GetChildren() Return a list which contains all children of the gate.
  • bool Organize( axis = “xy” )Organize the fault tree. axis can be “x”, “y” or “xy”.
  • bool or string Color( color = None ) If color is specified then change the color of the element else return the color. color must be an HTML code like #FFFFFF, #FF0000 etc…
  • bool IsGate() Return True if the element is a gate else False.
  • bool IsBasic() Return True if the element is a basic event else False.
  • bool IsHouse() Return True if the element is a house event else False.
  • bool IsTransfert() Return True if the element is a transfert else False.
  • parameter object GetParameter( type) Return the parameter of a certain type.
  • dictionary Compute( time = 1, zero = 0, step = None, maxOrder = 100, minProbability = 0) Compute the current gate and return a dictionary which contains all results as it is described for AA.Compute.Compute().
  • bool Logic( logic ) Change the logic of the gate. logic must be “and”, “or”, “atleast”, “nor”, “nand”.
  • bool State( state = None ) Return the state of the house event if state is not specified else change the state. state must be True or False.
  • bool or list Law( law = None, * parameters object )If law is specified, change the law of the basic event. law must be “constant”, “exponential”, “glm”, “weibull”, “repairable”, “simple-periodic-test” or “advanced-periodic-test”. If law and different parameter objects are specified then the parameters of the law will be modified. Finally, is neither law nor parameter object are specified then return a list which contains the law and all parameters.
  • bool Delete() Delete the current element.

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.

  • page object AA.Pages.Create( name = None ) Create a new page and return it.
  • page object AA.Pages.GetByName( name ) Get a page by its name.
  • page object AA.Pages.GetById( id ) Get a page by its id.
  • page object AA.Pages.GetActive() Get the active page.
  • list page object AA.Pages.GetAll() Return a list which contains all pages.
  • bool AA.Pages.Draw() Draw the page.

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

  • integer GetId() Return the id of the element.
  • bool or string Name( name = None ) Change the name if name is specified else return the name.
  • bool Activate() Change the active page of the project.
  • bool SVG( file ) Export the page to a SVG file.
  • bool Delete() Delete the page and all it contains.

class AA.Parameters

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

  • parameter object AA.Parameters.Create( name , type = “probability”, value = 0 )
  • list parameter object AA.Parameters.GetByName( name , type = None )
  • parameter object AA.Parameters.GetById( id )
  • list parameter object AA.Elements.GetAll( type = None )

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

  • integer GetId() Return the id of the parameter.
  • string GetType() Return the type of the parameter. type can be “probability”, “lambda”, “mu”, “mttr”, “tau”, “alpha”, “beta”, “teta”, “time”.
  • bool or string Name( name = None ) Change the name if name is specified else return the name of the parameter.
  • bool or float Value( value = None ) Change the value if value is specified else return the value of the parameter.
  • bool or string Description( text = None ) Change the description if text is specified else return the description of the parameter.
  • bool IsUsed() Return True is the parameter is used by a basic event.
  • bool Delete() Delete the parameter if it is unused.

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.

  • window object AA.Windows.Create ( title )
  • string AA.Windows.MsgBox ( title , text , type = “ok” )
  • string AA.Windows.InputBox ( title , text , default = ”” )
  • window object AA.Windows.TextBox ( title , text , default = ””, button = “ok” , function = None )
  • string AA.Windows.AskOpenFileBox( title )
  • string AA.Windows.AskSaveFileBox( title )

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

  • bool Show() Show the window.
  • bool Hide() Hide the window.
  • bool Close() Destroy the window.

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


© Arbre-Analyste 2013-17 | Tous droits réservés | E. CLEMENT