Browse Source

上传文件至 '后端/algorithm'

master
李思涵 3 years ago
parent
commit
67e4e8f80c
7 changed files with 152 additions and 0 deletions
  1. BIN
      后端/algorithm/__init__.py
  2. +3
    -0
      后端/algorithm/admin.py
  3. +6
    -0
      后端/algorithm/apps.py
  4. +3
    -0
      后端/algorithm/models.py
  5. +3
    -0
      后端/algorithm/tests.py
  6. +23
    -0
      后端/algorithm/urls.py
  7. +114
    -0
      后端/algorithm/views.py

BIN
后端/algorithm/__init__.py View File


+ 3
- 0
后端/algorithm/admin.py View File

@ -0,0 +1,3 @@
from django.contrib import admin
# Register your models here.

+ 6
- 0
后端/algorithm/apps.py View File

@ -0,0 +1,6 @@
from django.apps import AppConfig
class AlgorithmConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'algorithm'

+ 3
- 0
后端/algorithm/models.py View File

@ -0,0 +1,3 @@
from django.db import models
# Create your models here.

+ 3
- 0
后端/algorithm/tests.py View File

@ -0,0 +1,3 @@
from django.test import TestCase
# Create your tests here.

+ 23
- 0
后端/algorithm/urls.py View File

@ -0,0 +1,23 @@
"""yicanyishi URL Configuration
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/3.2/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: path('', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path, include
from . import views
urlpatterns = [
]

+ 114
- 0
后端/algorithm/views.py View File

@ -0,0 +1,114 @@
from django.db.models import Q
from general.views import *
from menu.models import *
def search_menu(upperbound, lowerbound, openid):
menu_search = Dish.objects.filter(Q(time__gt=lowerbound) & Q(time__lte=upperbound))
return menu_search
"""
fridge = FoodStock.objects.filter(owner_id=openid, is_active=1).values()
quantity = fridge.count()
for menus in menu_search:
menu_material_id = Material.objects.filter(Q(dish_id=menus.id) & Q(is_important=1)).values("food_type_id")
for Id in menu_material_id:
i = 0
for food in fridge:
i += 1
if food['type_id'] == Id:
i = 0
break
if i == quantity:
menu_search.remove(menus)
"""
"""
menu_material = Material.objects.get(all)
fridge = FoodStock.objects.get(all)
quantity = fridge.count()
for menus in menu_search:
id_dish = menus.id
for menu in menu_material:
if menu.dish_id == id_dish:
if menu.is_important == 1:
id_material = menu.food_type_id
i = 0
for food in fridge:
i += 1
if food.type_id == id_material:
i = 0
break
if i == quantity:
menu_search = menu_search.remove(menus)
"""
"""
import numpy as np
RI_dict = {1: 0, 2: 0, 3: 0.58, 4: 0.90, 5: 1.12, 6: 1.24, 7: 1.32, 8: 1.41, 9: 1.45}
def get_w(array):
row = array.shape[0] # 计算出阶数
a_axis_0_sum = array.sum(axis=0)
# print(a_axis_0_sum)
b = array / a_axis_0_sum # 新的矩阵b
# print(b)
b_axis_0_sum = b.sum(axis=0)
b_axis_1_sum = b.sum(axis=1) # 每一行的特征向量
# print(b_axis_1_sum)
w = b_axis_1_sum / row # 归一化处理(特征向量)
nw = w * row
AW = (w * array).sum(axis=1)
# print(AW)
max_max = sum(AW / (row * w))
# print(max_max)
CI = (max_max - row) / (row - 1)
CR = CI / RI_dict[row]
if CR < 0.1:
# print(round(CR, 3))
# print('满足一致性')
# print(np.max(w))
# print(sorted(w,reverse=True))
# print(max_max)
# print('特征向量:%s' % w)
return w
else:
print(round(CR, 3))
print('不满足一致性,请进行修改')
def main(array):
if type(array) is np.ndarray:
return get_w(array)
else:
print('请输入numpy对象')
if __name__ == '__main__':
# 由于地方问题,矩阵我就写成一行了
e = np.array([[1, 5, 1/2],
[1/5, 1, 5],
[2, 1/5, 1]])
a = np.array([[1, 1 / 3, 1 / 8], [3, 1, 1 / 3], [8, 3, 1]])
b = np.array([[1, 2, 5], [1 / 2, 1, 2], [1 / 5, 1 / 2, 1]])
c = np.array([[1, 1, 3], [1, 1, 3], [1 / 3, 1 / 3, 1]])
d = np.array([[1, 3, 4], [1 / 3, 1, 1], [1 / 4, 1, 1]])
f = np.array([[1, 4, 1 / 2], [1 / 4, 1, 1 / 4], [2, 4, 1]])
e = main(e)
a = main(a)
b = main(b)
c = main(c)
d = main(d)
f = main(f)
try:
res = np.array([a, b, c, d, f])
ret = (np.transpose(res) * e).sum(axis=1)
print(ret)
except TypeError:
print('数据有误,可能不满足一致性,请进行修改')
"""

Loading…
Cancel
Save