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

DB Write and read give different results #50

Open gymzombie opened 1 year ago

gymzombie commented 1 year ago

Not sure if this is a bug or intended functionality.

I create a model and write it to the database. (v1) I decide I want to change the parameters of that model and adjust the values, then write it to the database. (v2) I load the model from the database, and the output shows the model for v1.

Sample code to reproduce:

# Create an initial model
model = FairModel('System 1, Risk A')
model.bulk_import_data({
    'Loss Event Frequency': {'mean':.3, 'stdev':.1},
    'Loss Magnitude': {'constant': 5_000_000}
})
model.calculate_all()

# Create a database file and store that model
db = FairDatabase('pyfair.sqlite3')
db.store(model)

# Create a new version of that model
model = FairModel('System 1, Risk 1')
model.bulk_import_data({
    'Threat Event Frequency': {'low':.3, 'mode':.6, 'high':.9},
    'Vulnerability':{'constant':.5},
    'Loss Magnitude': {'constant': 5_000_000}
})
model.calculate_all()

# Write the updated version of that model to the database
db.store(model)

# Load the model
reconstituted_model = db.load('System 1, Risk A')
reconstituted_model.calculate_all()

fsr = FairSimpleReport([reconstituted_model])
fsr.to_html('output.html')

This also might just be a style/documentation issue? Since we read and write based on the model name, but the database reads and writes based on the UID, it's just unexpected behavior for a new user.