-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
216 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,8 @@ verify_ssl = true | |
|
||
[packages] | ||
pytest = "*" | ||
flask = "*" | ||
gunicorn = "*" | ||
|
||
[requires] | ||
python_version = "3.7" |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
web: gunicorn app:app |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import random | ||
from urllib.parse import unquote | ||
from flask import Flask, render_template, request, jsonify | ||
from lib.differentiator import differentiate | ||
|
||
app = Flask(__name__) | ||
|
||
@app.route('/', methods = ['get']) | ||
def hello_world(): | ||
random.seed() | ||
input = [ | ||
'(1 + sin(x)) ^ 3', | ||
'ln(sqrt(x) + 1)', | ||
'10 * (x + tan(x))' | ||
][(random.randint(0, 2))] | ||
return render_template("main.html", input=input) | ||
|
||
|
||
@app.route('/getDerivative', methods = ['get']) | ||
def get_derivative(): | ||
input = unquote(request.args.get('function')) | ||
result = differentiate(input) | ||
return jsonify(result.__dict__) | ||
|
||
if __name__ == "__main__": | ||
app.run() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
$ = window.$; | ||
MathJax = window.MathJax; | ||
|
||
function handleInput(inputFunction) { | ||
$('#function').attr('disabled', 'disabled'); | ||
$('#derivativeOutput').empty() | ||
$.ajax({ | ||
url: '/getDerivative', | ||
type: 'GET', | ||
data: {function: inputFunction}, | ||
success: function(response) { | ||
if(response.success) { | ||
var html = ''; | ||
html += 'I claim that, ' + response.answer; | ||
html += '<br>'; | ||
for(var i = 0; i < response.story.length; i++) { | ||
html += response.story[i] + '<br>'; | ||
} | ||
$('#derivativeOutput').append(html); | ||
$("#derivativeOutput").css("font-size","95%"); | ||
$("#derivativeOutput").css("color","black"); | ||
MathJax.Hub.Typeset(); | ||
} else { | ||
$('#derivativeOutput').append('Can\'t understand, sorry :( :('); | ||
$("#derivativeOutput").css("font-size","100%"); | ||
$("#derivativeOutput").css("color","red"); | ||
} | ||
$('#function').removeAttr('disabled'); | ||
}, | ||
error: function(){ | ||
alert('Something Went Wrong!'); | ||
}, | ||
}); | ||
} | ||
|
||
$(document).ready(function() { | ||
$('#inputForm').submit(function(e) { | ||
e.preventDefault(); | ||
var inputFunction = $('#function').val(); | ||
handleInput(inputFunction); | ||
}); | ||
$('#inputForm').submit(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>Derivative Calculator</title> | ||
|
||
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous"> | ||
|
||
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous"> | ||
|
||
<script type="text/javascript" | ||
src="https://code.jquery.com/jquery-3.2.1.min.js" | ||
integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=" | ||
crossorigin="anonymous"> | ||
</script> | ||
|
||
<script type="text/javascript" | ||
src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" | ||
integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" | ||
crossorigin="anonymous"> | ||
</script> | ||
|
||
<script type="text/javascript" | ||
src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=AM_HTMLorMML-full"> | ||
</script> | ||
|
||
<script src="{{ url_for('static', filename='js/index.js') }}"></script> | ||
</head> | ||
<body> | ||
<div class="row"> | ||
<div class="col-sm-2"> | ||
</div> | ||
<div class="col-sm-8"> | ||
<div class="row text-center"> | ||
<h3> Simple Derivative Calculator </h3> | ||
<form class="form" id="inputForm"> | ||
<div class="form-group"> | ||
<input type="text" class="form-control" id="function" value="{{input}}" placeholder="your function"> | ||
</div> | ||
</form> | ||
</div> | ||
<br> | ||
<div class="row" id="derivativeOutput"> | ||
</div> | ||
</div> | ||
</div> | ||
<div class="row footer"> | ||
<hr> | ||
<p class="text-center"> | ||
<a">readme and source code @ github</a> | ||
</p> | ||
</div> | ||
<div class = "row" style="height: 30px"> | ||
</div> | ||
</body> | ||
</html> |