hazardous_condition.py 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. from fastapi import APIRouter, Request, Depends, Query, HTTPException, status
  4. from common.security import valid_access_token
  5. from sqlalchemy.orm import Session
  6. from sqlalchemy.sql import func
  7. from common.auth_user import *
  8. from sqlalchemy import text
  9. from pydantic import BaseModel
  10. from common.BigDataCenterAPI import *
  11. from database import get_db
  12. from typing import List
  13. from utils import *
  14. from utils.risk import *
  15. import json
  16. import traceback
  17. router = APIRouter()
  18. @router.post('/get_max_hazardous')
  19. async def mine(request: Request,db: Session = Depends(get_db)):
  20. try:
  21. body = await request.json()
  22. result = get_max_forest_level(db)
  23. result = get_warning_description(result)
  24. #print(result)
  25. return {
  26. "code": 200,
  27. "msg": "成功",
  28. "data":
  29. {"max_level":result}
  30. }
  31. except Exception as e:
  32. db.rollback()
  33. traceback.print_exc()
  34. raise HTTPException(status_code=500, detail=f"Internal server error: {str(e)}")
  35. def get_warning_description(level):
  36. if level == 1:
  37. return "轻风险"
  38. elif level == 2:
  39. return "一般风险"
  40. elif level == 3:
  41. return "较大风险"
  42. elif level == 4:
  43. return "重大风险"
  44. else:
  45. return "未知等级"
  46. @router.post('/hazardous_warrning')
  47. async def mine(request: Request,db: Session = Depends(get_db)):
  48. try:
  49. result = "电白区、信宜市"
  50. #print(result)
  51. return {
  52. "code": 200,
  53. "msg": "成功",
  54. "data":
  55. {"result":result}
  56. }
  57. except Exception as e:
  58. db.rollback()
  59. traceback.print_exc()
  60. raise HTTPException(status_code=500, detail=f"Internal server error: {str(e)}")
  61. @router.post('/hazardous_warrning_count')
  62. async def mine(request: Request,db: Session = Depends(get_db)):
  63. try:
  64. result = get_hazardous_warring_count(db)
  65. #print(result)
  66. return {
  67. "code": 200,
  68. "msg": "成功",
  69. "data":
  70. {"result":result}
  71. }
  72. except Exception as e:
  73. db.rollback()
  74. traceback.print_exc()
  75. raise HTTPException(status_code=500, detail=f"Internal server error: {str(e)}")