From 4c3302a589a1c7e2437b4a71df413f6a3d565afb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=89=9B=E6=80=9D=E7=90=AA?= <3310028989@qq.com> Date: Sun, 7 Jul 2024 17:55:21 +0800 Subject: [PATCH] 7.5zuoye --- pythonProject/.idea/.gitignore | 8 +++ .../inspectionProfiles/profiles_settings.xml | 6 ++ pythonProject/.idea/misc.xml | 7 +++ pythonProject/.idea/modules.xml | 8 +++ pythonProject/.idea/pythonProject.iml | 10 ++++ pythonProject/cos.py | 23 ++++++++ pythonProject/main.py | 24 ++++++++ pythonProject/templates/demo.html | 57 +++++++++++++++++++ pythonProject/templates/tuijian.html | 49 ++++++++++++++++ 9 files changed, 192 insertions(+) create mode 100644 pythonProject/.idea/.gitignore create mode 100644 pythonProject/.idea/inspectionProfiles/profiles_settings.xml create mode 100644 pythonProject/.idea/misc.xml create mode 100644 pythonProject/.idea/modules.xml create mode 100644 pythonProject/.idea/pythonProject.iml create mode 100644 pythonProject/cos.py create mode 100644 pythonProject/main.py create mode 100644 pythonProject/templates/demo.html create mode 100644 pythonProject/templates/tuijian.html diff --git a/pythonProject/.idea/.gitignore b/pythonProject/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/pythonProject/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/pythonProject/.idea/inspectionProfiles/profiles_settings.xml b/pythonProject/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..105ce2d --- /dev/null +++ b/pythonProject/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/pythonProject/.idea/misc.xml b/pythonProject/.idea/misc.xml new file mode 100644 index 0000000..2a01189 --- /dev/null +++ b/pythonProject/.idea/misc.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/pythonProject/.idea/modules.xml b/pythonProject/.idea/modules.xml new file mode 100644 index 0000000..e15ec35 --- /dev/null +++ b/pythonProject/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/pythonProject/.idea/pythonProject.iml b/pythonProject/.idea/pythonProject.iml new file mode 100644 index 0000000..74d515a --- /dev/null +++ b/pythonProject/.idea/pythonProject.iml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/pythonProject/cos.py b/pythonProject/cos.py new file mode 100644 index 0000000..a279bac --- /dev/null +++ b/pythonProject/cos.py @@ -0,0 +1,23 @@ +# 计算两个向量点乘 +def dot(a,b): + sum=0; + c=zip(a,b) + for item in c: + sum+=item[0]*item[1] + return sum + +def mo(a): + sum=0 + for i in a: + sum+=i*i + return sum**0.5 + +import math +def angle(a,b): + ji=dot(a,b) + amo=mo(a) + bmo=mo(b) + cos=ji/(amo*bmo) + hudu=math.acos(cos) + jiaodu=hudu*180/math.pi + return jiaodu diff --git a/pythonProject/main.py b/pythonProject/main.py new file mode 100644 index 0000000..f3e05ff --- /dev/null +++ b/pythonProject/main.py @@ -0,0 +1,24 @@ +from flask import Flask,render_template +from datas import datas +from cos import angle +app=Flask(__name__) +@app.route('/') +def index(): + return render_template("demo.html",datas=datas) + +@app.route('/tuijian/') +def tuijian(id): + current=datas[id] ["feature"] + arr=[] + for i in range(len(datas)): + if(i!=id): + obj={} + a=angle(current,datas[i] ["feature"]) + obj["angle"]=a + obj["id"]=i + arr.append(obj) + def k(v): + return v["angle"] + arr.sort(key=k) + return render_template("tuijian.html",datas=datas,arr=arr[:5]) +app.run() \ No newline at end of file diff --git a/pythonProject/templates/demo.html b/pythonProject/templates/demo.html new file mode 100644 index 0000000..3120017 --- /dev/null +++ b/pythonProject/templates/demo.html @@ -0,0 +1,57 @@ + + + + + Title + + + + + {%for i in range(datas|length))%} + + + + + + {{datas[i].name}} + 推荐电影 + + + {%endfor%} + + + \ No newline at end of file diff --git a/pythonProject/templates/tuijian.html b/pythonProject/templates/tuijian.html new file mode 100644 index 0000000..d02b0f1 --- /dev/null +++ b/pythonProject/templates/tuijian.html @@ -0,0 +1,49 @@ + + + + + Title + + + + + {%for item in arr%} + + + + + + {{datas[item.id].name}} + {{item.angle}} + + + {%endfor%} + + + \ No newline at end of file -- Gitee