32 lines
975 B
Python
Executable File
32 lines
975 B
Python
Executable File
from flask import Flask, render_template, request
|
|
import math
|
|
from profiles import profiles
|
|
|
|
app = Flask(__name__)
|
|
|
|
def euclidean_distance(a, b):
|
|
return math.sqrt(sum((x - y) ** 2 for x, y in zip(a, b)))
|
|
|
|
@app.route("/", methods=["GET", "POST"])
|
|
def index():
|
|
if request.method == "POST":
|
|
user_values = [int(request.form.get(f"point{i}", 2)) for i in range(1, 7)]
|
|
|
|
# Find 3 best matches sorted by distance ascending
|
|
sorted_matches = sorted(profiles.items(), key=lambda p: euclidean_distance(user_values, p[1]['values']))
|
|
top_matches = sorted_matches[:3] # top 3 matches
|
|
|
|
return render_template(
|
|
"result.html",
|
|
user=user_values,
|
|
top_matches=top_matches,
|
|
)
|
|
return render_template("quiz.html")
|
|
|
|
@app.route("/profiles")
|
|
def profiles_page():
|
|
return render_template("profiles.html", profiles=profiles)
|
|
|
|
if __name__ == "__main__":
|
|
app.run(host='0.0.0.0', port=1337, debug=True)
|