From 44dc822522a9c98de8572af05b680d4abe7968dd Mon Sep 17 00:00:00 2001 From: mukeshsihag Date: Thu, 30 Jan 2020 10:15:56 +0530 Subject: [PATCH 1/6] basic setup for web and created frontend --- .gitignore | 2 +- requirements.txt | Bin 118 -> 1470 bytes web/.flaskenv | 2 + web/app/__init__.py | 5 ++ web/app/routes.py | 20 +++++++ web/app/static/js/app.js | 56 ++++++++++++++++++ web/app/static/styles/style.css | 41 +++++++++++++ web/app/templates/base.html | 26 ++++++++ web/app/templates/index.html | 102 ++++++++++++++++++++++++++++++++ web/visma.py | 1 + 10 files changed, 254 insertions(+), 1 deletion(-) create mode 100644 web/.flaskenv create mode 100644 web/app/__init__.py create mode 100644 web/app/routes.py create mode 100644 web/app/static/js/app.js create mode 100644 web/app/static/styles/style.css create mode 100644 web/app/templates/base.html create mode 100644 web/app/templates/index.html create mode 100644 web/visma.py diff --git a/.gitignore b/.gitignore index f50cee8..60a274a 100644 --- a/.gitignore +++ b/.gitignore @@ -13,4 +13,4 @@ __pycache__ run.sh .vscode/ log.txt -.idea \ No newline at end of file +venv \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 5b11e13c59d00f03b24090fcb605df5f621e84b5..5adba421490243dd2f208bdcf847f7e45e21d205 100644 GIT binary patch literal 1470 zcmZ8hO;3YR5ZtqgKSd*G{Wy3sdN483c<@XqZBa@qP%Hj;b!Laxhladj+}+ukdAt04 zXV%%;R#sYWJ8SUntgzOu@g#O^r#L5eXa~m34jCbK^(UI6szJQ8IS#8+)FsBO#F0|F zbe!Clz-nxUiq13DYVq~j_@BU%aBjc#FRK> zsy=kN^?2<}8z5}=&Z?_2@6ormSD>V>hn>Y(irx_4;j}=g2K7`HxC`Y0^$k>Q!Sxw` z&j)uxR^sl^)eaeSIjA8P?}wS`kd?#3%%%ed@8H}s=+er)DByx7i8HZwZkn6R0ZY8- zow_bvUErf=4Zh6iM={m2(*_)JXyRSdqlIU2>d00Z6%ZD9grJDjC?1i=xSWx-&u0tv zJ^aut(Ral1m+3s_F=*8OC^xJAO$%}|xT6WU<*q_5gwMVIiV z#vEu13fu(04%Ki=+@G<=4qt_k&*>{r`{B8|HU3UqZG+f5(C8+&h!aXJssD-}z54Ws zCMs@T3*0p}W(vnEJj5t4W!%|jkHu~QssA^F@|P2^MFlZRpq=i!r9LD2I_xkV+|C)g gXu_o?d_Cwk_woyGPHOxn#f|zx{RU6aNk!uJ3&C>H_5c6? literal 118 zcmW-ZyAFgP6h!;`6(sfqTq&Wm*J^8Y?-CMTve!-cd(mnp=VWGJ6_3+b{6Mr+LZ;w1 zqem{dfON*vjFw!Eu(Xww(dsF0+~(wb!VYc;1N-L62!G_0gVKVHw#N;OesKkR{$sVS I52k*60lKFp6#xJL diff --git a/web/.flaskenv b/web/.flaskenv new file mode 100644 index 0000000..5d3a941 --- /dev/null +++ b/web/.flaskenv @@ -0,0 +1,2 @@ +FLASK_APP = visma.py +FLASK_DEBUG = 1 \ No newline at end of file diff --git a/web/app/__init__.py b/web/app/__init__.py new file mode 100644 index 0000000..82b47ea --- /dev/null +++ b/web/app/__init__.py @@ -0,0 +1,5 @@ +from flask import Flask + +app = Flask(__name__) + +from app import routes \ No newline at end of file diff --git a/web/app/routes.py b/web/app/routes.py new file mode 100644 index 0000000..f34ec51 --- /dev/null +++ b/web/app/routes.py @@ -0,0 +1,20 @@ +from flask import render_template, request, redirect, url_for +from app import app +from sympy import * +from sympy.parsing.sympy_parser import parse_expr + +@app.route('/') +@app.route('/index') +def index(): + if request.args.get('ans'): + return render_template('index.html', title='sol', ans=request.args.get('ans')) + else: + return render_template('index.html', title='home') + +@app.route('/simplify/posts',methods=['GET', 'POST']) +def simplify(): + value = request.form['expr'] + print(value) + ans = parse_expr(value) + ans = ans.evalf() + return redirect(url_for('index',ans=ans)) diff --git a/web/app/static/js/app.js b/web/app/static/js/app.js new file mode 100644 index 0000000..4e4b08c --- /dev/null +++ b/web/app/static/js/app.js @@ -0,0 +1,56 @@ +$(document).ready(function() { + var x = document.getElementById("visma_btn") + if(x.style.display !== "none") { + x.style.display = "none"; + } +}) + +// Get a value expression +function getExpr() { + // alert("here") + var url = 'http://127.0.0.1:5000/simplify/posts'; + var d = document.getElementById("user_input").value; + + var data = {'expr':d} + console.log("data is being sent"); + $.post({ + url, + data, + function (data,status) { + console.log(`${data} and status is ${status}` ); + } + }); + document.getElementById('simplify').href = "{{ url_for('index') }}" + hideButton(); +} + +function getValue() { + console.log("getting value"); + // var v = $(this).val(); + // console.log(v); + // document.getElementById('user_input').innerHTML = document.getElementById('user_input') +} + +$(".input_expr").click(function() { + var input_val = $(this).val(); + console.log(input_val); + + document.getElementById("user_input").value = document.getElementById('user_input').value + input_val +}); + +function showButton() { + var x = document.getElementById("visma_btn"); + console.log("show"); + if(x.style.display === "none") { + x.style.display = "block"; + } +} + +function hideButton() { + var x = document.getElementById("visma_btn"); + var ui = document.getElementById("user_input").value; + console.log("hide"); + if(x.style.display !== "none") { + x.style.display = "none"; + } +} \ No newline at end of file diff --git a/web/app/static/styles/style.css b/web/app/static/styles/style.css new file mode 100644 index 0000000..b08e6cb --- /dev/null +++ b/web/app/static/styles/style.css @@ -0,0 +1,41 @@ +table { + width: 90%; + margin-left: 5%; + margin-top: 5%; +} +#btn { + width: 100%; +} +.btn-info { + width: 20%; +} +.visma_btn { + margin-left: 30%; +} +.btn-success { + width: 30%; + margin: 1%; +} +a { + text-decoration: none; +} +.solution { + margin-top: 5%; + margin-right: 5%; +} +.history { + margin-left: 20%; + margin-right: 10%; +} +.show-history { + margin-left: 30%; +} +#history { + height: 50%; +} +.left-tab-content { + height: 200px; +} +.data { + margin-left: 15%; +} diff --git a/web/app/templates/base.html b/web/app/templates/base.html new file mode 100644 index 0000000..c8bf725 --- /dev/null +++ b/web/app/templates/base.html @@ -0,0 +1,26 @@ + + + + + + + + + + + + {% if title %} + {{ title }} - Visma + {% else %} + Welcome to Visma + {% endif %} + + + + {% block content %}{% endblock %} + + + + \ No newline at end of file diff --git a/web/app/templates/index.html b/web/app/templates/index.html new file mode 100644 index 0000000..5ec765e --- /dev/null +++ b/web/app/templates/index.html @@ -0,0 +1,102 @@ +{% extends 'base.html' %} + +{% block content %} +
+
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ +
+
+

Step By Step Solution will be Shown Here

+
+
+

Logger

+
+
+
+
+
+
+ +
+ +
+ +
+
+

History will be Shown Here

+
+
+
+
+
+{% endblock %} \ No newline at end of file diff --git a/web/visma.py b/web/visma.py new file mode 100644 index 0000000..e524e69 --- /dev/null +++ b/web/visma.py @@ -0,0 +1 @@ +from app import app \ No newline at end of file From 147601552b8d2116928dbd6dc86c68f784714fa9 Mon Sep 17 00:00:00 2001 From: mukeshsihag Date: Thu, 30 Jan 2020 10:31:14 +0530 Subject: [PATCH 2/6] requirements --- requirements.txt | Bin 1470 -> 254 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/requirements.txt b/requirements.txt index 5adba421490243dd2f208bdcf847f7e45e21d205..2806f01c9f1c85f038c4ee72376c7f921e800a2e 100644 GIT binary patch literal 254 zcmY+9Jr4mv5Qg7c;y+0A;;<#1p6cp59~;TuVI7G-k7ou6#qR9P`!)M~3^h>JPG?

XEvg3A-LZms0mG0Lvo*@#NcfwT{&V}39(Y-7)v7_y2Z0o-)bDQG!PTk;fL!V*BPu9$T@B*|FCw%|_ literal 1470 zcmZ8hO;3YR5ZtqgKSd*G{Wy3sdN483c<@XqZBa@qP%Hj;b!Laxhladj+}+ukdAt04 zXV%%;R#sYWJ8SUntgzOu@g#O^r#L5eXa~m34jCbK^(UI6szJQ8IS#8+)FsBO#F0|F zbe!Clz-nxUiq13DYVq~j_@BU%aBjc#FRK> zsy=kN^?2<}8z5}=&Z?_2@6ormSD>V>hn>Y(irx_4;j}=g2K7`HxC`Y0^$k>Q!Sxw` z&j)uxR^sl^)eaeSIjA8P?}wS`kd?#3%%%ed@8H}s=+er)DByx7i8HZwZkn6R0ZY8- zow_bvUErf=4Zh6iM={m2(*_)JXyRSdqlIU2>d00Z6%ZD9grJDjC?1i=xSWx-&u0tv zJ^aut(Ral1m+3s_F=*8OC^xJAO$%}|xT6WU<*q_5gwMVIiV z#vEu13fu(04%Ki=+@G<=4qt_k&*>{r`{B8|HU3UqZG+f5(C8+&h!aXJssD-}z54Ws zCMs@T3*0p}W(vnEJj5t4W!%|jkHu~QssA^F@|P2^MFlZRpq=i!r9LD2I_xkV+|C)g gXu_o?d_Cwk_woyGPHOxn#f|zx{RU6aNk!uJ3&C>H_5c6? From a28a55c802a470e9e51d6e434fb886995e8daacc Mon Sep 17 00:00:00 2001 From: mukeshsihag Date: Sun, 2 Feb 2020 14:50:06 +0530 Subject: [PATCH 3/6] Simplify and Factorial Button are working properly --- README.md | 12 +++++ requirements.txt | Bin 254 -> 1470 bytes web/app/routes.py | 59 ++++++++++++++++++----- web/app/static/js/app.js | 57 +++++++++++++---------- web/app/templates/base.html | 2 +- web/app/templates/index.html | 88 +++++++++++++++++------------------ 6 files changed, 138 insertions(+), 80 deletions(-) diff --git a/README.md b/README.md index bf4b1a5..ef2b0c7 100644 --- a/README.md +++ b/README.md @@ -69,6 +69,18 @@ OUTPUT: 13.0 + x [5]+ Stopped python3 ``` +## Run Visma Web: + + +To launch Visma on web do: +```shell +>>> pip install -r requirements.txt +Change Directory to web folder +>>> cd web +run flask server +>>> flask run +launch Your localhost http://127.0.0.1:5000 +``` ## Download: diff --git a/requirements.txt b/requirements.txt index 2806f01c9f1c85f038c4ee72376c7f921e800a2e..5adba421490243dd2f208bdcf847f7e45e21d205 100644 GIT binary patch literal 1470 zcmZ8hO;3YR5ZtqgKSd*G{Wy3sdN483c<@XqZBa@qP%Hj;b!Laxhladj+}+ukdAt04 zXV%%;R#sYWJ8SUntgzOu@g#O^r#L5eXa~m34jCbK^(UI6szJQ8IS#8+)FsBO#F0|F zbe!Clz-nxUiq13DYVq~j_@BU%aBjc#FRK> zsy=kN^?2<}8z5}=&Z?_2@6ormSD>V>hn>Y(irx_4;j}=g2K7`HxC`Y0^$k>Q!Sxw` z&j)uxR^sl^)eaeSIjA8P?}wS`kd?#3%%%ed@8H}s=+er)DByx7i8HZwZkn6R0ZY8- zow_bvUErf=4Zh6iM={m2(*_)JXyRSdqlIU2>d00Z6%ZD9grJDjC?1i=xSWx-&u0tv zJ^aut(Ral1m+3s_F=*8OC^xJAO$%}|xT6WU<*q_5gwMVIiV z#vEu13fu(04%Ki=+@G<=4qt_k&*>{r`{B8|HU3UqZG+f5(C8+&h!aXJssD-}z54Ws zCMs@T3*0p}W(vnEJj5t4W!%|jkHu~QssA^F@|P2^MFlZRpq=i!r9LD2I_xkV+|C)g gXu_o?d_Cwk_woyGPHOxn#f|zx{RU6aNk!uJ3&C>H_5c6? literal 254 zcmY+9Jr4mv5Qg7c;y+0A;;<#1p6cp59~;TuVI7G-k7ou6#qR9P`!)M~3^h>JPG?

XEvg3A-LZms0mG0Lvo*@#NcfwT{&V}39(Y-7)v7_y2Z0o-)bDQG!PTk;fL!V*BPu9$T@B*|FCw%|_ diff --git a/web/app/routes.py b/web/app/routes.py index f34ec51..f5fdf7d 100644 --- a/web/app/routes.py +++ b/web/app/routes.py @@ -1,20 +1,57 @@ -from flask import render_template, request, redirect, url_for +from flask import render_template, request, redirect, url_for, jsonify from app import app from sympy import * from sympy.parsing.sympy_parser import parse_expr +import mpmath +import math @app.route('/') -@app.route('/index') +@app.route('/index', methods=['GET']) def index(): - if request.args.get('ans'): - return render_template('index.html', title='sol', ans=request.args.get('ans')) - else: - return render_template('index.html', title='home') + return render_template('index.html', title='home') -@app.route('/simplify/posts',methods=['GET', 'POST']) +# Simplifying the expression +@app.route('/simplify/posts',methods=['POST']) def simplify(): + try: + value = request.form['expr'] + if '^' in value: + value = value.replace('^', '**') + print(value) + # ans = parse_expr(value) + # ans = ans.evalf() + ans = N(value) + ans = str(ans) + check = 0 + breakpoint + for i in range(ans.index('.')+1, len(ans)): + if ans[i] != '0': check=1 + if check: + return ans[:ans.index('.')+5] + else: + return ans[:ans.index('.')] + except (ValueError, KeyError, TypeError) as error: + print(error) + return error + +# Calculating the Factoral of given Number +@app.route('/factorial/posts', methods=['POST']) +def factorial(): + value = request.form['expr'] + # print(type(value)) + ans = math.factorial(int(value)) + return str(ans) + +# Integrating the given expression +# TODO ! +@app.route('/integrate/posts', methods=['POST']) +def integrate(): + value = request.form['expr'] + return value + +# Differentiatin the given expression +# TODO! +@app.route('/differentiate/posts', methods=['POST']) +def differentiate(): value = request.form['expr'] - print(value) - ans = parse_expr(value) - ans = ans.evalf() - return redirect(url_for('index',ans=ans)) + return value \ No newline at end of file diff --git a/web/app/static/js/app.js b/web/app/static/js/app.js index 4e4b08c..3155f5f 100644 --- a/web/app/static/js/app.js +++ b/web/app/static/js/app.js @@ -5,30 +5,35 @@ $(document).ready(function() { } }) -// Get a value expression -function getExpr() { - // alert("here") - var url = 'http://127.0.0.1:5000/simplify/posts'; +// Get expression value +function getExpr(type_of_operation) { + console.log(type_of_operation); + var url = `http://127.0.0.1:5000/${type_of_operation}/posts`; var d = document.getElementById("user_input").value; - - var data = {'expr':d} - console.log("data is being sent"); - $.post({ - url, - data, - function (data,status) { - console.log(`${data} and status is ${status}` ); - } - }); - document.getElementById('simplify').href = "{{ url_for('index') }}" - hideButton(); -} -function getValue() { - console.log("getting value"); - // var v = $(this).val(); - // console.log(v); - // document.getElementById('user_input').innerHTML = document.getElementById('user_input') + // Checking number is negative for not for Factorial + var check_negative_num = parseInt(d, 10); + if(type_of_operation==="factorial" && check_negative_num < 0) { + alert('Factorial is not defined for negative numbers'); + } + + else { + var data = {'expr':d} + console.log("data is being sent"); + $.post({ + url, + data, + success: function (data,status) { + console.log(status); + console.log(`${data} and status is ${status}` ); + document.getElementById('user_input').value = data + }, + error: function() { + alert('It seems that something is wrong in your Input') + } + }); + hideButton(); + } } $(".input_expr").click(function() { @@ -41,14 +46,18 @@ $(".input_expr").click(function() { function showButton() { var x = document.getElementById("visma_btn"); console.log("show"); - if(x.style.display === "none") { + input_val = document.getElementById('user_input').value; + if(input_val === "") { + alert('Please Provide a Input') + } + + else if(x.style.display === "none") { x.style.display = "block"; } } function hideButton() { var x = document.getElementById("visma_btn"); - var ui = document.getElementById("user_input").value; console.log("hide"); if(x.style.display !== "none") { x.style.display = "none"; diff --git a/web/app/templates/base.html b/web/app/templates/base.html index c8bf725..50d8dae 100644 --- a/web/app/templates/base.html +++ b/web/app/templates/base.html @@ -7,7 +7,7 @@ - + {% if title %} {{ title }} - Visma diff --git a/web/app/templates/index.html b/web/app/templates/index.html index 5ec765e..af66390 100644 --- a/web/app/templates/index.html +++ b/web/app/templates/index.html @@ -8,52 +8,52 @@ - - - - - - - - - - + + + + + + + + + + - - - - - - - - - - + + + + + + + + + + - - - - - - - - - - + + + + + + + + + + - - - - - - - - - - + + + + + + + + + +

@@ -80,10 +80,10 @@
- -
- - + +
+ +