Hive-Systems / pyfair

Factor Analysis of Information Risk (FAIR) model written in Python. Managed and maintained by Hive Systems
https://www.hivesystems.com
MIT License
88 stars 44 forks source link

Report shows vulnerability to only 2 decimal places #42

Closed markchatters closed 2 years ago

markchatters commented 2 years ago

Hi - is there a way to show more decimal places for vulnerability ? e.g. my vulnerability of 0.0033 is currently displayed as 0.00

theonaunheim commented 2 years ago

Hey, @markchatters . Thanks for your interest.

Are you talking about the display on on the output of the FairSimpleReport?

markchatters commented 2 years ago

Yes - the output on the Fair Simple Report

markchatters commented 2 years ago

pyfairreport

markchatters commented 2 years ago

I may have missed something - perhaps there already is a way to do this ?

theonaunheim commented 2 years ago

Not nicely there's not. The only thing I can think of is supplying a new format string to the FairSimpleReport before you calculate it.


import pyfair

# Create using LEF (PERT), PL, (PERT), and SL (constant)
model1 = pyfair.FairModel(name="Regular Model 1", n_simulations=10_000)
model1.input_data('Threat Event Frequency', low=20, most_likely=100, high=900)
model1.input_data('Loss Magnitude', low=3_000_000, most_likely=3_500_000, high=5_000_000)
model1.input_data('Vulnerability', low=.011, most_likely=.225, high=.934)
model1.calculate_all()

# Create report comparing 2 vs metamodel.
fsr = pyfair.FairSimpleReport([model1])

################################################################
# Change your vuln format string
fsr._format_strings['Vulnerability'] = '{0:.3f}'
################################################################

# Output stuff
fsr.to_html('output.html')

image

theonaunheim commented 2 years ago

For the sake of completeness ....

The FairSimpleReport inherits from the FairBaseReport. This FairBaseReport has a formatting table. If you change a format string AFTER instantiation but BEFORE rendering, if should respect your new formatting. That said, the report is pretty fragile so anything beyond a few decimal places runs the risk of moving things out of place.


class FairBaseReport(object):
    """A base class for creating FairModel and FairMetaModel reports
    This class exists to provide a common base for mutliple report types.
    It carries with it formatting data, file paths, and a variety of 
    methods for creating report components. It is not intended to be
    instantiated on its own.
    """
    def __init__(self, currency_prefix='$'):
        # Add formatting strings
        self._currency_prefix = currency_prefix
        self._model_or_models = None
        self._currency_format_string     = currency_prefix + '{0:,.0f}'
        self._float_format_string      = '{0:.2f}'
        self._format_strings = {
            'Risk'                           : self._currency_format_string,
            'Loss Event Frequency'           : self._float_format_string,
            'Threat Event Frequency'         : self._float_format_string,
            'Vulnerability'                  : self._float_format_string,         
            'Contact Frequency'              : self._float_format_string,
            'Probability of Action'          : self._float_format_string,
            'Threat Capability'              : self._float_format_string,
            'Control Strength'               : self._float_format_string,
            'Loss Magnitude'                 : self._currency_format_string,
            'Primary Loss'                   : self._currency_format_string,
            'Secondary Loss'                 : self._currency_format_string,
            'Secondary Loss Event Frequency' : self._float_format_string,
            'Secondary Loss Event Magnitude' : self._currency_format_string,
        }
markchatters commented 2 years ago

great - thank you - that worked !

If I could be cheeky it would also be good if the distribution curve allowed for a max value less than 1 - but thank you for your prompt reply