Différences

Ci-dessous, les différences entre deux révisions de la page.

Lien vers cette vue comparative

api [2017/03/06 17:19]
emmanuel [How to distribute an addon]
api [2021/03/20 21:14]
Ligne 1: Ligne 1:
-===== 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. 
- 
-<code python># 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"]) 
-</code> 
- 
-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. 
-  - All parts of the addon have to be in the same directory; 
-  - The directory of the addon have to be in the "externe\modules\" directory of the Arbre-Analyste path; 
-  - 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: 
- 
-<code python> 
-# -*- 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!") 
-</code> 
- 
-==== 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: 
- 
-<code python># 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() 
-</code> 
- 
-==== 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: 
- 
-<code python> 
-# 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"])) 
-</code> 
-==== 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. 
- 
-<code python> 
-# 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())) 
-</code> 
-==== 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 at this address [[http://effbot.org/tkinterbook/tkinter-classes.htm|Tkinter documentation]] to get a complete documentation.