├── app1 ├── model.py ├── compute.py ├── controller.py ├── hw.py ├── templates │ └── view.html ├── view.py └── app.py ├── .gitignore ├── mvc ├── compute.py ├── form.py ├── templates │ └── view.html └── main.py ├── FlaskScience.png ├── app ├── static │ ├── 1625798036.0574243.png │ └── style.css ├── app.py ├── model.py ├── compute.py └── templates │ └── view.html ├── requirements.txt └── README.md /app1/model.py: -------------------------------------------------------------------------------- 1 | r = 0.0 # input 2 | s = None # output -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .myvenv 2 | myvenv/ 3 | __pycache__/ 4 | 5 | 6 | -------------------------------------------------------------------------------- /app1/compute.py: -------------------------------------------------------------------------------- 1 | import math 2 | 3 | def compute(r): 4 | return math.sin(r) -------------------------------------------------------------------------------- /mvc/compute.py: -------------------------------------------------------------------------------- 1 | import math 2 | 3 | def compute(r): 4 | return math.sin(r) -------------------------------------------------------------------------------- /FlaskScience.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/the-akira/Flask-Science/master/FlaskScience.png -------------------------------------------------------------------------------- /app/static/1625798036.0574243.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/the-akira/Flask-Science/master/app/static/1625798036.0574243.png -------------------------------------------------------------------------------- /app1/controller.py: -------------------------------------------------------------------------------- 1 | import model, view 2 | 3 | # python controller.py [parâmetro numérico] 4 | model.r = view.get_input() 5 | view.present_output(model.r) -------------------------------------------------------------------------------- /mvc/form.py: -------------------------------------------------------------------------------- 1 | from wtforms import Form, FloatField, validators 2 | 3 | class InputForm(Form): 4 | r = FloatField(validators=[validators.InputRequired()]) -------------------------------------------------------------------------------- /app1/hw.py: -------------------------------------------------------------------------------- 1 | # python hw.py [parâmetro numérico] 2 | import sys, math 3 | r = float(sys.argv[1]) 4 | s = math.sin(r) 5 | print('Hello, World! sin(%g)=%g' % (r, s)) -------------------------------------------------------------------------------- /app1/templates/view.html: -------------------------------------------------------------------------------- 1 |
-------------------------------------------------------------------------------- /mvc/templates/view.html: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | Click==7.0 2 | cycler==0.10.0 3 | Flask==1.1.1 4 | Flask-WTF==0.14.2 5 | itsdangerous==1.1.0 6 | Jinja2==2.11.3 7 | kiwisolver==1.1.0 8 | MarkupSafe==1.1.1 9 | matplotlib==3.1.1 10 | numpy==1.22.0 11 | pyparsing==2.4.0 12 | python-dateutil==2.8.0 13 | six==1.12.0 14 | Werkzeug==0.15.4 15 | WTForms==2.2.1 16 | -------------------------------------------------------------------------------- /app1/view.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import compute 3 | 4 | # Input: float r 5 | # Output: "Hello, World! sin(r)=..." 6 | 7 | def get_input(): 8 | """Get input data from the command line.""" 9 | r = float(sys.argv[1]) 10 | return r 11 | 12 | def present_output(r): 13 | """Write results to terminal window.""" 14 | s = compute.compute(r) 15 | print('Hello, World! sin(%g)=%g' % (r, s)) -------------------------------------------------------------------------------- /mvc/main.py: -------------------------------------------------------------------------------- 1 | from flask import Flask, render_template, request 2 | from compute import compute 3 | from form import InputForm 4 | 5 | app = Flask(__name__) 6 | 7 | @app.route('/', methods=['GET', 'POST']) 8 | def index(): 9 | form = InputForm(request.form) 10 | if request.method == 'POST' and form.validate(): 11 | r = form.r.data 12 | s = compute(r) 13 | else: 14 | s = None 15 | return render_template("view.html", form=form, s=s) 16 | 17 | if __name__ == '__main__': 18 | app.run(debug=True) -------------------------------------------------------------------------------- /app/app.py: -------------------------------------------------------------------------------- 1 | from model import InputForm 2 | from flask import Flask, render_template, request 3 | from compute import compute 4 | 5 | app = Flask(__name__) 6 | 7 | @app.route('/', methods=['GET', 'POST']) 8 | def index(): 9 | form = InputForm(request.form) 10 | if request.method == 'POST' and form.validate(): 11 | result = compute(form.A.data, form.b.data, form.w.data, form.T.data) 12 | else: 13 | result = None 14 | return render_template('view.html', form=form, result=result) 15 | 16 | if __name__ == '__main__': 17 | app.run(debug=True) -------------------------------------------------------------------------------- /app/model.py: -------------------------------------------------------------------------------- 1 | from wtforms import Form, FloatField, validators 2 | from math import pi 3 | 4 | class InputForm(Form): 5 | A = FloatField( 6 | label='amplitude (m)', default=1.0, 7 | validators=[validators.InputRequired()]) 8 | b = FloatField( 9 | label='fator de amortecimento (kg/s)', default=0, 10 | validators=[validators.InputRequired()]) 11 | w = FloatField( 12 | label='frequência (1/s)', default=2*pi, 13 | validators=[validators.InputRequired()]) 14 | T = FloatField( 15 | label='intervalo de tempo (s)', default=18, 16 | validators=[validators.InputRequired()]) -------------------------------------------------------------------------------- /app1/app.py: -------------------------------------------------------------------------------- 1 | from flask import Flask, render_template, request 2 | from wtforms import Form, FloatField, validators 3 | from compute import compute 4 | 5 | app = Flask(__name__) 6 | 7 | # Model 8 | class InputForm(Form): 9 | r = FloatField(validators=[validators.InputRequired()]) 10 | 11 | @app.route('/', methods=['GET', 'POST']) 12 | def index(): 13 | form = InputForm(request.form) 14 | if request.method == 'POST' and form.validate(): 15 | r = form.r.data 16 | s = compute(r) 17 | else: 18 | s = None 19 | return render_template("view.html", form=form, s=s) 20 | 21 | if __name__ == '__main__': 22 | app.run(debug=True) -------------------------------------------------------------------------------- /app/static/style.css: -------------------------------------------------------------------------------- 1 | body { 2 | background-color: #7aafc4 !important; 3 | } 4 | 5 | h2{ 6 | color: black !important; 7 | } 8 | 9 | p{ 10 | font-size: 1.7rem; 11 | color: black !important; 12 | } 13 | 14 | td.name{ 15 | color: black; 16 | } 17 | 18 | .form-group{ 19 | margin-top: 5px; 20 | background-color: white !important; 21 | padding: 23px; 22 | border: 2px solid black; 23 | } 24 | 25 | .btn{ 26 | margin-top: 7px; 27 | } 28 | 29 | .btn-primary{ 30 | background-color: black !important; 31 | border: none !important; 32 | } 33 | 34 | label{ 35 | margin-left: 4px; 36 | } 37 | 38 | .center { 39 | display: block; 40 | margin-left: auto; 41 | margin-right: auto; 42 | width: 65%; 43 | margin-bottom: 10px; 44 | border: 1px solid black; 45 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Flask Científico 2 | 3 |  4 | 5 | Simples aplicação científica desenvolvida com Flask. 6 | 7 | ## Instalação 8 | 9 | ### Crie um Clone do Repositório 10 | 11 | ``` 12 | git clone https://github.com/the-akira/Flask-Science.git 13 | ``` 14 | 15 | ### Dentro do Diretório Principal (root) 16 | 17 | Crie um Ambiente Virtual 18 | 19 | ``` 20 | python -m venv myvenv 21 | ``` 22 | 23 | Faça a Ativação do Ambiente Virtual 24 | 25 | ``` 26 | source myvenv/bin/activate 27 | ``` 28 | 29 | Instale as dependências necessárias 30 | 31 | ``` 32 | pip install -r requirements.txt 33 | ``` 34 | 35 | Navegue até o diretório `app` e execute o comando 36 | 37 | ``` 38 | python app.py 39 | ``` 40 | 41 | Através do seu Web Browser, navegue até `http://127.0.0.1:5000/` 42 | 43 | Divirta-se experimentando! 44 | 45 | Inspirado no tutorial: **[Flask4Scientists](http://hplgit.github.io/web4sciapps/doc/pub/web4sa_flask.html)** -------------------------------------------------------------------------------- /app/compute.py: -------------------------------------------------------------------------------- 1 | from numpy import exp, cos, linspace 2 | import matplotlib.pyplot as plt 3 | import os, time, glob 4 | 5 | def damped_vibrations(t, A, b, w): 6 | return A*exp(-b*t)*cos(w*t) 7 | 8 | def compute(A, b, w, T, resolution=500): 9 | """Return filename of plot of the damped_vibration function.""" 10 | t = linspace(0, T, resolution+1) 11 | u = damped_vibrations(t, A, b, w) 12 | plt.figure() # needed to avoid adding curves in plot 13 | plt.plot(t, u) 14 | plt.title('A=%g, b=%g, w=%g' % (A, b, w)) 15 | if not os.path.isdir('static'): 16 | os.mkdir('static') 17 | else: 18 | # Remove old plot files 19 | for filename in glob.glob(os.path.join('static', '*.png')): 20 | os.remove(filename) 21 | # Use time since Jan 1, 1970 in filename in order make 22 | # a unique filename that the browser has not cached 23 | plotfile = os.path.join('static', str(time.time()) + '.png') 24 | plt.savefig(plotfile) 25 | return plotfile 26 | 27 | if __name__ == '__main__': 28 | print(compute(1, 0.1, 1, 20)) -------------------------------------------------------------------------------- /app/templates/view.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |12 | \( 13 | u(t) = Ae^{-bt}\sin (w t), \hbox{ for } t\in [0,T] 14 | \) 15 |
16 | 34 |