-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathweb.py
More file actions
48 lines (36 loc) · 1.26 KB
/
web.py
File metadata and controls
48 lines (36 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
from flask import Flask, jsonify, render_template, request
from patterns import calculate_matches_from_examples, get_patterns
app = Flask(__name__)
@app.route("/", methods=["GET", "POST"])
def index():
if request.method == "POST":
pattern = request.form.get("pattern")
delimiter = request.form.get("delimiter")
if pattern:
data = request.form.get("data1")
else:
data = request.form.get("data")
data = [i.strip() for i in data.split("\n")][:5000]
if not pattern:
top_candidate = max(
get_patterns(data, delimiter=delimiter).values(), key=len
)
tab = "calculate"
else:
top_candidate = pattern.split(delimiter)
tab = "run"
matches, results, fails = calculate_matches_from_examples(
top_candidate, data, delimiter=delimiter
)
return render_template(
"index.html",
data="\n".join(data),
pattern=delimiter.join(top_candidate),
match_rate=(matches / len(data)) * 100,
results=results,
tab=tab,
fails=fails,
)
return render_template("index.html")
if __name__ == "__main__":
app.run(debug=True)