diff --git a/后端/algorithm/__init__.py b/后端/algorithm/__init__.py new file mode 100644 index 0000000..06d7405 Binary files /dev/null and b/后端/algorithm/__init__.py differ diff --git a/后端/algorithm/admin.py b/后端/algorithm/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/后端/algorithm/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/后端/algorithm/apps.py b/后端/algorithm/apps.py new file mode 100644 index 0000000..b5388c0 --- /dev/null +++ b/后端/algorithm/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class AlgorithmConfig(AppConfig): + default_auto_field = 'django.db.models.BigAutoField' + name = 'algorithm' diff --git a/后端/algorithm/models.py b/后端/algorithm/models.py new file mode 100644 index 0000000..71a8362 --- /dev/null +++ b/后端/algorithm/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/后端/algorithm/tests.py b/后端/algorithm/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/后端/algorithm/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/后端/algorithm/urls.py b/后端/algorithm/urls.py new file mode 100644 index 0000000..c4c8636 --- /dev/null +++ b/后端/algorithm/urls.py @@ -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 = [ + +] diff --git a/后端/algorithm/views.py b/后端/algorithm/views.py new file mode 100644 index 0000000..2ffbc53 --- /dev/null +++ b/后端/algorithm/views.py @@ -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('数据有误,可能不满足一致性,请进行修改') + +""" \ No newline at end of file