tianyun 2 jaren geleden
bovenliggende
commit
4eeb8aab63
2 gewijzigde bestanden met toevoegingen van 75 en 5 verwijderingen
  1. 16 5
      tmp.py
  2. 59 0
      tmp_app.py

+ 16 - 5
tmp.py

@@ -1,5 +1,16 @@
-dic_test = {}
-dic_test['*' * 1000] = "1"
-dic_test['*' * 5000] = "2"
-print(dic_test)
-print(len(dic_test))
+# -*- coding: utf-8
+import time
+
+import pandas as pd
+
+value_list = [0, 10, 20, 30.4, 59, 61, 79, 80, 90, 99, 100]
+
+start = time.time()
+# 等频分箱
+value_freq_bins = pd.qcut(value_list, q=5)
+print("等频分箱:", value_freq_bins.codes)
+
+# 等距分箱
+value_dis_bins = pd.cut(value_list, bins=5)
+print("等距分箱:", value_dis_bins.codes)
+print("time: ", time.time() - start)

+ 59 - 0
tmp_app.py

@@ -0,0 +1,59 @@
+import uvicorn as uvicorn
+from fastapi import FastAPI
+from pydantic.main import BaseModel
+from starlette.middleware.cors import CORSMiddleware
+from starlette.middleware.sessions import SessionMiddleware
+from starlette.responses import JSONResponse
+
+app = FastAPI(title="project name ", description="系统描述 ", version="v 0.0.0")
+app.add_middleware(SessionMiddleware, secret_key='123456hhh')
+app.add_middleware(
+    CORSMiddleware,
+    allow_origins=["*", ],
+    allow_credentials=True,
+    allow_methods=["*"],
+    allow_headers=["*"],
+)
+
+
+@app.exception_handler(Exception)
+def validation_exception_handler(request, exc):
+    """请求校验异常捕获; application/json """
+    return JSONResponse({'message': "服务器内部错误", 'status_code': 500})
+
+
+@app.get("/query")
+def query(uid: str):
+    msg = f'uid为{uid}'
+    return {'success': True, 'msg': msg}
+
+
+@app.get("/query/{uid}")
+def query(uid: str):
+    msg = f'uid为{uid}'
+    return {'success': True, 'msg': msg}
+
+
+class People(BaseModel):
+    name: str
+    age: int
+    address: str
+    salary: float
+
+
+# json body请求
+@app.post("/insert")
+def insert(people: People):
+    msg = f"名字:{people.name},年龄{people.age}"
+    return msg
+
+
+if __name__ == '__main__':
+    uvicorn.run(app='main:app', host="127.0.0.1", port=8000, reload=True, debug=True)
+
+# 启动命令
+# pip3 install -r /tmp/request.txt -i https://pypi.douban.com/simple/
+# pip3 install uvicorn gunicorn fastapi -i https://pypi.douban.com/simple/
+#
+# gunicorn tmp_app:app -b 0.0.0.0:8000 -w 4 -k uvicorn.workers.UvicornWorker -D  # 不支持linux运行 -w 进程数
+# uvicorn tmp_app:app --reload --host 0.0.0.0 --port 8000