__init__.py 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. from fastapi import APIRouter, Request, Depends, Query, HTTPException, status
  2. from common.security import valid_access_token
  3. from sqlalchemy.orm import Session
  4. from sqlalchemy.sql import func
  5. from common.auth_user import *
  6. from sqlalchemy import text
  7. from pydantic import BaseModel
  8. from common.BigDataCenterAPI import *
  9. from database import get_db
  10. from typing import List
  11. from utils import *
  12. from utils.risk import *
  13. import json
  14. import traceback
  15. router = APIRouter()
  16. @router.post('/temperature')
  17. async def mine(request: Request,db: Session = Depends(get_db)):
  18. try:
  19. body = await request.json()
  20. args = body.get("args")
  21. print(args)
  22. result = []
  23. if args == "6h_precipitation":
  24. result.append(
  25. {"create_time":"",
  26. "pic_url":"https://soc.gd121.cn/sk6hrain/2024/10/MSP1_AGD_MANOBS_PRCPV_L88_AGD_202410071400_00600-00000.PNG"
  27. }
  28. )
  29. result.append(
  30. {"create_time": "",
  31. "pic_url": "https://soc.gd121.cn/sk6hrain/2024/10/MSP1_AGD_MANOBS_PRCPV_L88_AGD_202410071500_00600-00000.PNG"
  32. }
  33. )
  34. result.append(
  35. {"create_time": "",
  36. "pic_url": "https://soc.gd121.cn/sk6hrain/2024/10/MSP1_AGD_MANOBS_PRCPV_L88_AGD_202410071600_00600-00000.PNG"
  37. }
  38. )
  39. elif args == "24h_precipitation":
  40. result.append(
  41. {"create_time": "",
  42. "pic_url": "https://soc.gd121.cn/sk24hrain/2024/10/MSP1_AGD_MANOBS_PRCPV_L88_AGD_202410071400_02400-00000.PNG"}
  43. )
  44. result.append(
  45. {"create_time": "",
  46. "pic_url": "https://soc.gd121.cn/sk24hrain/2024/10/MSP1_AGD_MANOBS_PRCPV_L88_AGD_202410071500_02400-00000.PNG"}
  47. )
  48. result.append(
  49. {"create_time": "",
  50. "pic_url": "https://soc.gd121.cn/sk24hrain/2024/10/MSP1_AGD_MANOBS_PRCPV_L88_AGD_202410071600_02400-00000.PNG"}
  51. )
  52. elif args == "hourly_temperature":
  53. result.append(
  54. {"create_time": "",
  55. "pic_url": "https://soc.gd121.cn/skt/2024/10/MSP1_AGD_MANOBS_T_L88_AGD_202410071300_00000-00000.PNG"}
  56. )
  57. result.append(
  58. {"create_time": "",
  59. "pic_url": "https://soc.gd121.cn/skt/2024/10/MSP1_AGD_MANOBS_T_L88_AGD_202410071400_00000-00000.PNG"}
  60. )
  61. result.append(
  62. {"create_time": "",
  63. "pic_url": "https://soc.gd121.cn/skt/2024/10/MSP1_AGD_MANOBS_T_L88_AGD_202410071500_00000-00000.PNG"}
  64. )
  65. elif args == "24h_max_temperature":
  66. result.append(
  67. {"create_time": "",
  68. "pic_url": "https://soc.gd121.cn/sk24htmax/2024/10/MSP1_AGD_MANOBS_TMA_L88_AGD_202410071300_02400-00000.PNG"
  69. }
  70. )
  71. result.append(
  72. {"create_time": "",
  73. "pic_url": "https://soc.gd121.cn/sk24htmax/2024/10/MSP1_AGD_MANOBS_TMA_L88_AGD_202410071400_02400-00000.PNG"
  74. }
  75. )
  76. result.append(
  77. {"create_time": "",
  78. "pic_url": "https://soc.gd121.cn/sk24htmax/2024/10/MSP1_AGD_MANOBS_TMA_L88_AGD_202410071500_02400-00000.PNG"
  79. }
  80. )
  81. elif args == "24h_min_temperature":
  82. result.append(
  83. {"create_time": "",
  84. "pic_url": "https://soc.gd121.cn/sk24htmin/2024/10/MSP1_AGD_MANOBS_TMI_L88_AGD_202410071300_02400-00000.PNG"}
  85. )
  86. result.append(
  87. {"create_time": "",
  88. "pic_url": "https://soc.gd121.cn/sk24htmin/2024/10/MSP1_AGD_MANOBS_TMI_L88_AGD_202410071400_02400-00000.PNG"}
  89. )
  90. result.append(
  91. {"create_time": "",
  92. "pic_url": "https://soc.gd121.cn/sk24htmin/2024/10/MSP1_AGD_MANOBS_TMI_L88_AGD_202410071500_02400-00000.PNG"}
  93. )
  94. elif args == "24h_variable_temperature":
  95. result.append(
  96. {"create_time": "",
  97. "pic_url": "https://soc.gd121.cn/skt24hdt/2024/10/MSP1_AGD_MANOBS_TD_L88_AGD_202410071300_02400-00000.PNG"}
  98. )
  99. result.append(
  100. {"create_time": "",
  101. "pic_url": "https://soc.gd121.cn/skt24hdt/2024/10/MSP1_AGD_MANOBS_TD_L88_AGD_202410071400_02400-00000.PNG"}
  102. )
  103. result.append(
  104. {"create_time": "",
  105. "pic_url": "https://soc.gd121.cn/skt24hdt/2024/10/MSP1_AGD_MANOBS_TD_L88_AGD_202410071500_02400-00000.PNG"}
  106. )
  107. print(result)
  108. return {
  109. "code": 200,
  110. "msg": "成功",
  111. "data":
  112. {"max_level":result}
  113. }
  114. except Exception as e:
  115. db.rollback()
  116. traceback.print_exc()
  117. raise HTTPException(status_code=500, detail=f"Internal server error: {str(e)}")