def load_model(spec, all): name = spec["name"] params = spec["parameters"] if "simulations" in spec: simul = int(spec["simulations"]) else: simul = 10000 if type(params) == dict: model = pyfair.FairModel(name=name, n_simulations=simul) model.bulk_import_data(params) all[name] = model return model if type(params) == list: models = [load_model(m, all) for m in params] metamodel = pyfair.FairMetaModel(name=name, models=models) all[name] = metamodel return metamodel raise RuntimeError("Bad model parameters")
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('Loss Event Frequency', low=20, mode=100, high=900) model1.input_data('Primary Loss', low=3_000_000, mode=3_500_000, high=5_000_000) model1.input_data('Secondary Loss', constant=3_500_000) model1.calculate_all() # Create another model using LEF (Normal) and LM (PERT) model2 = pyfair.FairModel(name="Regular Model 2", n_simulations=10_000) model2.input_data('Loss Event Frequency', mean=.3, stdev=.1) model2.input_data('Loss Magnitude', low=2_000_000_000, mode=3_000_000_000, high=5_000_000_000) model2.calculate_all() # Create metamodel by combining 1 and 2 mm = pyfair.FairMetaModel(name='My Meta Model!', models=[model1, model2]) mm.calculate_all() # Create report comparing 2 vs metamodel. fsr = pyfair.FairSimpleReport([model1, mm]) fsr.to_html('output.html')
def result(): if 'Email' in session: g.username = session['Email'] if request.method == "POST": if request.form['action'] == 'generate': try: global members2 members2 = [] # storing size of form values like number of participants rows = int((len(request.form) - 1) / 8) for i in range(1, rows + 1): row_array = {} fields = Field() fields.field_name = request.form["field{}".format(i)] fields.gamma = request.form["gamma{}".format(i)] fields.low = request.form["low{}".format(i)] fields.mode = request.form["mode{}".format(i)] fields.high = request.form["high{}".format(i)] fields.constant = request.form["constant{}".format(i)] fields.mean = request.form["mean{}".format(i)] fields.std = request.form["std{}".format(i)] row_array['name'] = fields.field_name if (fields.gamma != ""): row_array['gamma'] = int(fields.gamma) if (fields.low != ""): row_array['low'] = int(fields.low) if (fields.mode != ""): row_array['mode'] = int(fields.mode) if (fields.high != ""): row_array['high'] = int(fields.high) if (fields.constant != ""): row_array['constant'] = int(fields.constant) if (fields.mean != ""): row_array['mean'] = float(fields.mean) if (fields.std != ""): row_array['std'] = float(fields.std) members2.append(row_array) # for storing data into array model1 = pyfair.FairModel(name="Regular Model 1", n_simulations=simulation) global members1 for i in range(len(members1)): if 'low' in members1[i].keys(): model1.input_data(members1[i]['name'], low=members1[i]['low'], mode=members1[i]['mode'], high=members1[i]['high']) elif 'constant' in members1[i].keys(): model1.input_data(members1[i]['name'], constant=members1[i]['constant']) elif 'mean' in members1[i].keys(): model1.input_data(members1[i]['name'], mean=members1[i]['mean'], stdev=members1[i]['std']) model1.calculate_all() model2 = pyfair.FairModel(name="Regular Model 2", n_simulations=simulation) for i in range(len(members2)): if 'low' in members2[i].keys(): model2.input_data(members2[i]['name'], low=members2[i]['low'], mode=members2[i]['mode'], high=members2[i]['high']) elif 'constant' in members2[i].keys(): model2.input_data(members2[i]['name'], constant=members2[i]['constant']) elif 'mean' in members2[i].keys(): model2.input_data(members2[i]['name'], mean=members2[i]['mean'], stdev=members2[i]['std']) mm = pyfair.FairMetaModel(name='My Meta Model!', models=[model1, model2]) mm.calculate_all() # #modelMMResult = mm.export_results().to_dict() fsr = pyfair.FairSimpleReport([model1, mm]) fsr.to_html('./templates/result.html') # print (modelMMResult) return render_template("result.html") except: flash("Please Fill the information Carefully", "danger") return redirect(url_for("dashboard")) else: redirect(url_for("dashboard")) else: return redirect(url_for("dashboard")) else: return redirect(url_for("login"))