Spaces:
Sleeping
Sleeping
from flask import Flask, render_template, request, jsonify | |
import numpy as np | |
import matplotlib.pyplot as plt | |
app = Flask(__name__) | |
def calcular_vpn(n, r, cash_flow): | |
descuento = 1 / ((1 + r) ** np.arange(1, n + 1)) | |
vpn = np.sum(cash_flow * descuento) | |
return vpn | |
def index(): | |
return render_template('index.html') | |
def calcular(): | |
data = request.get_json() | |
n = int(data['n']) | |
r = float(data['r']) | |
cash_flow = np.array(data['cash_flow']) | |
vpn = calcular_vpn(n, r, cash_flow) | |
plt.figure(figsize=(10, 6)) | |
plt.plot(np.arange(1, n + 1), cash_flow, marker='o') | |
plt.xlabel('Años') | |
plt.ylabel('Cash Flow') | |
plt.title('Flujo de Efectivo') | |
plt.grid(True) | |
# Guardar el gráfico como imagen | |
img_path = 'static/plot.png' | |
plt.savefig(img_path) | |
return jsonify({'vpn': vpn, 'plot_path': img_path}) | |
if __name__ == '__main__': | |
app.run(debug=True) |