123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- #!/usr/bin/env python3
- # -*- coding: utf-8 -*-
- from fastapi import APIRouter, Request, Depends, Query, HTTPException, status
- from common.security import valid_access_token
- from sqlalchemy.orm import Session
- from sqlalchemy.sql import func
- from common.auth_user import *
- from sqlalchemy import text
- from pydantic import BaseModel
- from common.BigDataCenterAPI import *
- from database import get_db
- from typing import List
- from utils import *
- from utils.risk import *
- import json
- import traceback
- router = APIRouter()
- @router.post('/get_township_rain')
- async def mine(request: Request,db: Session = Depends(get_db)):
- try:
- body = await request.json()
- rn = body.get('rn')
- result = get_rain_township(db,rn)
- #print(result)
- return {
- "code": 200,
- "msg": "成功",
- "data":
- result
- }
- except Exception as e:
- db.rollback()
- traceback.print_exc()
- raise HTTPException(status_code=500, detail=f"Internal server error: {str(e)}")
- @router.post('/township_rain_warrning')
- async def mine(request: Request,body = Depends(remove_xss_json),db: Session = Depends(get_db)):
- try:
- body = await request.json()
- rn = body.get('rn')
- one_hour = get_rain_township(db,1)
- three_hour = get_rain_township(db,3)
- max_rain = get_max_rain_township(db)
- # print(one_hour)
- # print(three_hour)
- one_hour_rain = 6
- one_hour_more_50 = 0
- three_hour_more_50 = 0
- max_time = get_rain_max_time(db)
- result = ''
- raining_township = 0
- for i in range(len(one_hour)):
- if one_hour[i]["value"] == 0:
- one_hour_rain-=1
- elif one_hour[i]["value"] != 0:
- raining_township+=1
- elif one_hour[i]['name'] in ['暴雨(50-100)','大暴雨(100-200)','特大暴雨(>200)']:
- one_hour_more_50+=one_hour[i]["value"]
- elif three_hour[i]['name'] in ['大暴雨(100-200)','特大暴雨(>200)']:
- three_hour_more_50+=one_hour[i]["value"]
- max_rain_township = max_rain[0]["township"]
- max_rain_value = max_rain[0]["rn"]
- # print(one_hour_rain)
- # print(one_hour_more_50)
- # print(three_hour_more_50)
- # print(max_rain_township)
- # print(max_rain_value)
- if one_hour_rain==0:
- result = '''{}至当前,当前无地区下雨 。
- 当前1小时降雨量大于50毫米的镇街 {}个;
- 当前3小时降雨量大于100毫米的镇街 {}个;
- '''.format(max_time,one_hour_more_50,three_hour_more_50)
- else:
- result = '''{}至当前,全市有 {}个镇街发生降雨, 最大降雨出现在 {},累计雨量为{}毫米 。
- 当前1小时降雨量大于50毫米的镇街 {}个;
- 当前3小时降雨量大于100毫米的镇街 {}个;
- '''.format(max_time,one_hour_rain,max_rain_township,max_rain_value,one_hour_more_50,three_hour_more_50)
- #print(result)
- return {
- "code": 200,
- "msg": "成功",
- "data":
- {"result":result}
- }
- except Exception as e:
- db.rollback()
- traceback.print_exc()
- raise HTTPException(status_code=500, detail=f"Internal server error: {str(e)}")
|