Spaces:
Build error
Build error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# app.py
|
| 2 |
+
from flask import Flask, request, render_template
|
| 3 |
+
import math
|
| 4 |
+
|
| 5 |
+
app = Flask(__name__)
|
| 6 |
+
|
| 7 |
+
@app.route('/')
|
| 8 |
+
def index():
|
| 9 |
+
return render_template('index.html')
|
| 10 |
+
|
| 11 |
+
@app.route('/calculate', methods=['POST'])
|
| 12 |
+
def calculate():
|
| 13 |
+
voltage = float(request.form['voltage'])
|
| 14 |
+
current = float(request.form['current'])
|
| 15 |
+
real_power = float(request.form['power'])
|
| 16 |
+
|
| 17 |
+
apparent_power = voltage * current # in VA
|
| 18 |
+
if apparent_power == 0:
|
| 19 |
+
reactive_power = 0
|
| 20 |
+
else:
|
| 21 |
+
reactive_power = math.sqrt(apparent_power**2 - real_power**2) # in VAR
|
| 22 |
+
|
| 23 |
+
return render_template('index.html',
|
| 24 |
+
voltage=voltage,
|
| 25 |
+
current=current,
|
| 26 |
+
real_power=real_power,
|
| 27 |
+
reactive_power=round(reactive_power, 2))
|
| 28 |
+
|
| 29 |
+
if __name__ == '__main__':
|
| 30 |
+
app.run(debug=True)
|