|
@@ -0,0 +1,56 @@
|
|
|
+#!/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 models import *
|
|
|
+from utils import *
|
|
|
+from utils.spatial import *
|
|
|
+import json
|
|
|
+import traceback
|
|
|
+from jobs.rainfall_conditions_job import get_stcd_data
|
|
|
+from datetime import datetime,timedelta
|
|
|
+
|
|
|
+
|
|
|
+router = APIRouter()
|
|
|
+
|
|
|
+@router.get("/info/{code}")
|
|
|
+async def get_pattern_info(
|
|
|
+ code: str,
|
|
|
+ db: Session = Depends(get_db)
|
|
|
+):
|
|
|
+ rainfulldata = get_stcd_data(code,12)
|
|
|
+ update_time_list = []
|
|
|
+ rainfall_history = []
|
|
|
+ rainfall_future = []
|
|
|
+ cumulative_rainfall = []
|
|
|
+ for i in rainfulldata[::-1]:
|
|
|
+ area_name = i['F3070220000034_000018002']
|
|
|
+ update_time_list.append( datetime.strptime(i['F3070220000034_000018006'], "%Y-%m-%d %H:%M:%S"))
|
|
|
+ create_time = datetime.strptime(i['F3070220000034_000018004'], "%Y-%m-%d %H:%M:%S")
|
|
|
+ hour = create_time.strftime("%H")
|
|
|
+ value = i['F3070220000034_000018005']
|
|
|
+ rainfall_history.append({"hour":hour,"value":value})
|
|
|
+ update_time_max = max(update_time_list).strftime("%Y-%m-%d %H:%M:%S")
|
|
|
+ for t in range(1,13):
|
|
|
+ future_time = create_time+ timedelta(hours=t)
|
|
|
+ hour = future_time.strftime("%H")
|
|
|
+ value = 0
|
|
|
+ rainfall_future.append({"hour":hour,"value":value})
|
|
|
+
|
|
|
+ rainfall = 0
|
|
|
+ for cumulative in rainfall_history+rainfall_future:
|
|
|
+ rainfall += cumulative['value']
|
|
|
+ cumulative_rainfall.append({"hour":cumulative['hour'],"value":rainfall})
|
|
|
+
|
|
|
+ return {
|
|
|
+ "code": 200, "msg": "获取成功", "data":{"areaName":area_name,"updateTime":update_time_max,"rainfallHistory":rainfall_history,"rainfallFuture":rainfall_future,"cumulativeRainfall":cumulative_rainfall}
|
|
|
+ }
|