Kaynağa Gözat

bge small dinge

Xiaopeng Zhang 5 ay önce
ebeveyn
işleme
22cd6700e5
3 değiştirilmiş dosya ile 253 ekleme ve 3 silme
  1. 135 2
      main.py
  2. 116 0
      subdir/db.py
  3. 2 1
      subdir/service.py

+ 135 - 2
main.py

@@ -8,6 +8,8 @@ import zipfile
 import json
 from fastapi.middleware.cors import CORSMiddleware
 from fastapi.middleware.gzip import GZipMiddleware
+from sentence_transformers  import SentenceTransformer
+model = SentenceTransformer("BAAI/bge-small-zh-v1.5")
 import base64
 from pydantic import BaseModel
 from subdir import service
@@ -466,9 +468,9 @@ async def read_dexilie(value: int, id: str):
     #print(result)
     return result
 
-@app.get("/singledexilie/{zhuanye}/{debh}")
+@app.get("/singledexilie2/{zhuanye}/{debh}")
 @cache(expire=86400)
-async def read_singledexilie(zhuanye: int, debh: str):
+async def read_singledexilie2(zhuanye: int, debh: str):
     if debh.startswith("D") :
         return json.dumps({
             "reverse": "None", 
@@ -597,6 +599,137 @@ async def read_singledexilie(zhuanye: int, debh: str):
     print(result3)
     return json.dumps(result3, ensure_ascii=False)
 
+@app.get("/singledexilie/{zhuanye}/{debh}/{mc}")
+@cache(expire=86400)
+async def read_singledexilie(zhuanye: int, debh: str, mc: str):
+    if debh.startswith("D") :
+        return json.dumps({
+            "reverse": "None", 
+            "rgde": None,
+            "jxde": None,
+            "clde": None,
+            "actual_zhuanye": zhuanye,
+            "bz_selected": {"BZBH": {}},
+            "bz_selected2": {"BZBH": {}}
+        }, ensure_ascii=False)
+    if "-F" in debh:
+        return service.read_singledexilie_azfy(debh)
+    r_debh = debh.split("!")[0]
+    print(r_debh)
+    result1, result2, rgde, jxde, clde, bz_selected, bz_selected2, actual_zhuanye= await db.getSingleDeXilie(model, client, zhuanye, r_debh, mc)
+    print("get result ***************************************")
+    if result1:
+        result3 = json.loads(result1)
+    else:
+        result3 = {}
+    result3["reverse"] = str(result2)
+    result3["rgde"] = rgde
+    result3["jxde"] = jxde
+    result3["clde"] = clde
+    result3["actual_zhuanye"] = actual_zhuanye
+    if bz_selected != None:
+        result3["bz_selected"] = json.loads(bz_selected)
+    else:
+        result3["bz_selected"] = {"BZBH": {}}
+    if bz_selected2 != None:
+        result3["bz_selected2"] = json.loads(bz_selected2)
+    else:
+        result3["bz_selected2"] = {"BZBH": {}}
+    ####14-227+[14-228]*-2
+    ####3-409*2
+    print(r_debh)
+    if "[" in r_debh:
+        position3 = r_debh.find("*")
+        coef = 1
+        if position3 == -1:
+            pass
+        else:
+            coef = r_debh[1 + position3:]
+            print(coef)
+            tail = 0
+            for i in range(0, len(coef) + 1):
+                if i == len(coef):
+                    tail = i
+                    break
+                if (coef[i] > '9' or coef[i] < '0') and coef[i] != '-':
+                    tail = i
+                    break
+            if tail == 0:
+                print("1113111")
+                result3["reverse"] = 'None'
+                return json.dumps(result3, ensure_ascii=False)
+            coef = int(coef[0:tail])
+
+        position1 = r_debh.find("[")
+        position2 = r_debh.find("]")
+        if position2 == -1:
+            print("1121111")
+            result3["reverse"] = 'None'
+            return json.dumps(result3, ensure_ascii=False)
+        if r_debh[position1-1] == "+":
+            pass
+        elif r_debh[position1-1] == "-":
+            coef = -coef
+        else:
+            print("111111")
+            result3["reverse"] = 'None'
+            return json.dumps(result3, ensure_ascii=False)
+        debh = r_debh[position1+1: position2]
+        if result3['GLDE']: ##csv文件里的字段,表示这个定额有没有配套的增减定额
+            hit = False
+            for key, value in result3['GLDE'].items():
+                if value == debh:
+                    hit = True
+            if not hit:
+                result3["reverse"] = 'None'
+                return json.dumps(result3, ensure_ascii=False)
+        else:
+            result3["reverse"] = 'None'
+            return json.dumps(result3, ensure_ascii=False)
+        result1_, result2_, rgde_, jxde_, clde_, bz_selected_, bz_selected2_, actual_zhuanye_ = await db.getSingleDeXilie(model, client, zhuanye, debh, mc)
+        if result1_:
+            util.mergerg(rgde, rgde_, coef)
+            util.mergejx(jxde, jxde_, coef)
+            util.mergecl(clde, clde_, coef)
+            result3["rgde"] = rgde
+            result3["jxde"] = jxde
+            result3["clde"] = clde
+            item_ = None
+            for item in result3['DW'].keys():
+                item_ = item
+            result3['DEBH'] = {item_: util.cleanBM(r_debh)}
+        else:
+            result3["reverse"] = 'None'
+    elif "*" in r_debh:##1-234*2
+        position3 = r_debh.find("*")
+        coef = 1
+        
+        coef = r_debh[1 + position3:]
+        print(coef)
+        tail = 0
+        for i in range(0, len(coef) + 1):
+            if i == len(coef):
+                tail = i
+                break
+            if (coef[i] > '9' or coef[i] < '0') and coef[i] != '-':
+                tail = i
+                break
+        if tail == 0:
+            print("1113111")
+            result3["reverse"] = 'None'
+            return json.dumps(result3, ensure_ascii=False)
+        coef = int(coef[0:tail])
+        util.multirg(result3["rgde"], coef)
+        util.multijx(result3["jxde"], coef)
+        util.multicl(result3["clde"], coef)
+        item_ = None
+        for item in result3['DW'].keys():
+            item_ = item
+        result3['DEBH'] = {item_: (r_debh)}
+
+    print(result3)
+    return json.dumps(result3, ensure_ascii=False)
+
 
 @app.post("/save/")
 async def save(r: Info):

+ 116 - 0
subdir/db.py

@@ -3,6 +3,7 @@ from subdir import service, util
 from bson.objectid import ObjectId
 import uuid
 from datetime import datetime
+import numpy as np
 
 
 
@@ -1385,9 +1386,124 @@ async def getJiagongcai(client, id):
 
 
 
+async def getSingleDeXilie(model, client, zhuanye, debh, mc):
+    db = client["dinge"]
+    collection = db["de-collection"]
+    count = 0
+    actual_zhuanye = []
+    mcs = []
+    if "附注" in debh:
+        position = debh.find("附注")
+        debh = debh[:position]
+    if "*" in debh:
+        position = debh.find("*")
+        debh = debh[:position]
+    if debh.endswith("换"):
+        debh = debh[:-1]
+    if "[" in debh:
+        position = debh.find("[")
+        debh = debh[:position-1]
+    async for post in collection.find({'DEBH': debh}):
+        print(post)
+        actual_zhuanye.append(post['zhuanye'])
+        mcs.append(post['GCLMC'])
+        count = count + 1
+    if count == 0:
+        return  None, None, None, None, None, None, None, zhuanye
+    elif count == 1:
+        if actual_zhuanye[0] == '土建':
+            A1, A2, A3, A4, A5, A6, A7 = service.getSingleDeXilie_tj(debh)
+            return A1, A2, A3, A4, A5, A6, A7, 10
+        elif actual_zhuanye[0] == '市政':
+            A1, A2, A3, A4, A5, A6, A7 = service.getSingleDeXilie_sz(debh)
+            return A1, A2, A3, A4, A5, A6, A7, 20
+        elif actual_zhuanye[0] == '安装':
+            A1, A2, A3, A4, A5, A6, A7 = service.getSingleDeXilie_az(debh)
+            return A1, A2, A3, A4, A5, A6, A7, 30
+        elif actual_zhuanye[0] == '园林':
+            A1, A2, A3, A4, A5, A6, A7 = service.getSingleDeXilie_yl(debh)
+            return A1, A2, A3, A4, A5, A6, A7,  40  
+        elif actual_zhuanye[0] == '修缮工程土建':
+            A1, A2, A3, A4, A5, A6, A7 = service.getSingleDeXilie_xstj(debh)
+            return A1, A2, A3, A4, A5, A6, A7, 50   
+        elif actual_zhuanye[0] == '修缮工程安装':
+            A1, A2, A3, A4, A5, A6, A7 = service.getSingleDeXilie_xsaz(debh)
+            return A1, A2, A3, A4, A5, A6, A7, 60   
+    else:
+        hit = False
+        for i in range(0, count):
+            if mcs[i] == mc:
+                hit = True
+                actual_zhuanye[0] = actual_zhuanye[i]
+        if hit:
+            if actual_zhuanye[0] == '土建':
+                A1, A2, A3, A4, A5, A6, A7 = service.getSingleDeXilie_tj(debh)
+                return A1, A2, A3, A4, A5, A6, A7, 10
+            elif actual_zhuanye[0] == '市政':
+                A1, A2, A3, A4, A5, A6, A7 = service.getSingleDeXilie_sz(debh)
+                return A1, A2, A3, A4, A5, A6, A7, 20
+            elif actual_zhuanye[0] == '安装':
+                A1, A2, A3, A4, A5, A6, A7 = service.getSingleDeXilie_az(debh)
+                return A1, A2, A3, A4, A5, A6, A7, 30
+            elif actual_zhuanye[0] == '园林':
+                A1, A2, A3, A4, A5, A6, A7 = service.getSingleDeXilie_yl(debh)
+                return A1, A2, A3, A4, A5, A6, A7,  40  
+            elif actual_zhuanye[0] == '修缮工程土建':
+                A1, A2, A3, A4, A5, A6, A7 = service.getSingleDeXilie_xstj(debh)
+                return A1, A2, A3, A4, A5, A6, A7, 50   
+            elif actual_zhuanye[0] == '修缮工程安装':
+                A1, A2, A3, A4, A5, A6, A7 = service.getSingleDeXilie_xsaz(debh)
+                return A1, A2, A3, A4, A5, A6, A7, 60   
+        else:
+            mcs.append(mc)
+            embeddings = model.encode(mcs)
+            similarities = model.similarity( embeddings[-1], embeddings)
+            ##array([1.0000002, 0.7662151, 1.0000002], dtype=float32)
+            print(similarities)
+            sim = similarities[0].numpy()[:-1]
+            print(sim)
+            index = np.argmax(sim).item()
+            print(index)
+            print(actual_zhuanye)
+
+            actual_zhuanye[0] = actual_zhuanye[index]
+            if actual_zhuanye[0] == '土建':
+                A1, A2, A3, A4, A5, A6, A7 = service.getSingleDeXilie_tj(debh)
+                return A1, A2, A3, A4, A5, A6, A7, 10
+            elif actual_zhuanye[0] == '市政':
+                A1, A2, A3, A4, A5, A6, A7 = service.getSingleDeXilie_sz(debh)
+                return A1, A2, A3, A4, A5, A6, A7, 20
+            elif actual_zhuanye[0] == '安装':
+                A1, A2, A3, A4, A5, A6, A7 = service.getSingleDeXilie_az(debh)
+                return A1, A2, A3, A4, A5, A6, A7, 30
+            elif actual_zhuanye[0] == '园林':
+                A1, A2, A3, A4, A5, A6, A7 = service.getSingleDeXilie_yl(debh)
+                return A1, A2, A3, A4, A5, A6, A7,  40  
+            elif actual_zhuanye[0] == '修缮工程土建':
+                A1, A2, A3, A4, A5, A6, A7 = service.getSingleDeXilie_xstj(debh)
+                return A1, A2, A3, A4, A5, A6, A7, 50   
+            elif actual_zhuanye[0] == '修缮工程安装':
+                A1, A2, A3, A4, A5, A6, A7 = service.getSingleDeXilie_xsaz(debh)
+                return A1, A2, A3, A4, A5, A6, A7, 60   
+
+
+
+
+
 
 
 
+
+
+
+
+
+
+
+
+
+   
+
 ##################################editor_code##########################
 def bjhz_template():
     result = []

+ 2 - 1
subdir/service.py

@@ -18,6 +18,7 @@ from numpy import float64, int64
 
 
 
+
 def getQingdanTuijian(bh, bt, bm):
     result = []
     try:
@@ -1262,6 +1263,7 @@ def getPbxl(name):
     return filtered.to_json(force_ascii=False)
 
 
+
 def getSingleDeXilie(zhuanye, debh):
     if zhuanye == 10:
         A1, A2, A3, A4, A5, A6, A7 = getSingleDeXilie_tj(debh)
@@ -1302,7 +1304,6 @@ def getSingleDeXilie(zhuanye, debh):
             A1, A2, A3, A4, A5, A6, A7 = getSingleDeXilie_az(debh)
             return A1, A2, A3, A4,A5, A6, A7, 30
 
-
 def getSingleDeXilie_xsaz(debh):
     id = None
     bz_selected = []