-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
30 lines (23 loc) · 979 Bytes
/
app.py
File metadata and controls
30 lines (23 loc) · 979 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
from flask import Flask, render_template, request, jsonify
from calculator import OwaspCalculator
app = Flask(__name__)
calculator = OwaspCalculator()
@app.route('/')
def index():
return render_template('index.html')
@app.route('/calculate', methods=['POST'])
def calculate():
data = request.json
try:
likelihood_factors = [float(x) for x in data.get('likelihood', [])]
impact_factors = [float(x) for x in data.get('impact', [])]
if len(likelihood_factors) != 8 or len(impact_factors) != 8:
return jsonify({'error': 'Invalid number of factors. Expected 8 for each.'}), 400
result = calculator.calculate_risk(likelihood_factors, impact_factors)
return jsonify(result)
except ValueError:
return jsonify({'error': 'Invalid input values. Must be numbers.'}), 400
except Exception as e:
return jsonify({'error': str(e)}), 500
if __name__ == '__main__':
app.run(debug=True)