MCPcopy Create free account
hub / github.com/Derive-Risk/pyfair / FairTreeGraph

Class FairTreeGraph

pyfair/report/tree_graph.py:13–227  ·  view source on GitHub ↗

Provides a pretty tree diagram to summarize calculations. This tree class provides an image that descirbes those nodes that have been calculated, those nodes that have had data supplied, and those nodes which are not required. Parameters ---------- model : FairModel

Source from the content-addressed store, hash-verified

11
12
13class FairTreeGraph(object):
14 """Provides a pretty tree diagram to summarize calculations.
15
16 This tree class provides an image that descirbes those nodes that have
17 been calculated, those nodes that have had data supplied, and those
18 nodes which are not required.
19
20 Parameters
21 ----------
22 model : FairModel
23 The model which is being described by the tree
24 format_strings : dict of str
25 A dict with string keys describing the nodes, and string values
26 providing a formatting string for numbers of that type
27
28 """
29 # Class attribute with magic numbers galore
30 _DIMENSIONS = pd.DataFrame.from_dict(
31 {
32 'Contact' : ['C' , 0, 0, 600, 800],
33 'Threat Event Frequency' : ['TEF' , 600, 800, 1800, 1600],
34 'Action' : ['A' , 1200, 0, 600, 800],
35 'Threat Capability' : ['TC' , 2400, 0, 3000, 800],
36 'Vulnerability' : ['V' , 3000, 800, 1800, 1600],
37 'Control Strength' : ['CS' , 3600, 0, 3000, 800],
38 'Loss Magnitude' : ['LM' , 6600, 1600, 4200, 2400],
39 'Loss Event Frequency' : ['LEF' , 1800, 1600, 4200, 2400],
40 'Risk' : ['R' , 4200, 2400, 4200, 5000],
41 'Primary Loss' : ['PL' , 5400, 800, 6600, 1600],
42 'Secondary Loss' : ['SL' , 7800, 800, 6600, 1600],
43 'Secondary Loss Event Frequency': ['SLEF', 7200, 0, 7800, 800],
44 'Secondary Loss Event Magnitude': ['SLEM', 8400, 0, 7800, 800],
45 },
46 orient='index',
47 columns=['tag', 'self_x', 'self_y', 'parent_x', 'parent_y']
48 )
49
50 def __init__(self, model, format_strings):
51 self._colormap = {'Not Required': 'grey', 'Supplied': 'green', 'Calculated': 'blue'}
52 self._results = model.export_results().T
53 self._format_strings = format_strings
54 # Calculate mean and standard deviation for results
55 self._result_summary = pd.DataFrame({
56 'μ': self._results.mean(axis=1),
57 'σ': self._results.std(axis=1),
58 '↑': self._results.max(axis=1),
59 })
60 # Make status input into a dataframe.
61 self._statuses = model.get_node_statuses()
62 self._process_statuses()
63 # Make params a frame (must occur after process_statuses())
64 self._params = pd.DataFrame(model.export_params()).T.reindex(self._statuses.index)
65 # Tack all data together
66 self._data = pd.concat([
67 self._statuses,
68 self._DIMENSIONS,
69 self._result_summary,
70 self._params

Callers 2

_get_treeMethod · 0.85

Calls

no outgoing calls

Tested by 1