handle get history Q and H data

This commit is contained in:
xinzish
2024-04-12 18:12:58 +08:00
parent 44e487f85f
commit 330248041f
4 changed files with 34 additions and 12 deletions

View File

@@ -1,25 +1,30 @@
from tjnetwork import * from tjnetwork import *
from get_realValue import * from get_realValue import *
from get_hist_data import *
import datetime import datetime
ids=['3489','3854','3853','2510','2514','4780','4854'] ids=['2498','3854','3853','2510','2514','4780','4854']
cur_data=None cur_data=None
def get_latest_cal_time()->datetime: def get_latest_cal_time()->datetime:
current_time=datetime.datetime.now() current_time=datetime.datetime.now()
return current_time return current_time
def get_current_data()->bool: def get_current_data(str_datetime: str=None)->bool:
global cur_data global cur_data
cur_data=get_realValue(ids) if str_datetime==None:
cur_data=get_realValue(ids)
else:
cur_date=get_hist_data(ids,str_datetime)
if cur_data ==None: if cur_data ==None:
return False return False
return True return True
def get_current_total_Q(str_dt:str='')->float: def get_current_total_Q(str_dt:str='')->float:
q_ids=['3489','3854','3853'] q_ids=['2498','3854','3853']
q_dn900=cur_data[q_ids[0]] q_dn900=cur_data[q_ids[0]]
q_dn500=cur_data[q_ids[1]] q_dn500=cur_data[q_ids[1]]
q_dn1000=cur_data[q_ids[2]] q_dn1000=cur_data[q_ids[2]]
@@ -52,3 +57,4 @@ if __name__ == '__main__':
if get_current_data()==True: if get_current_data()==True:
tQ=get_current_total_Q() tQ=get_current_total_Q()
print(f"the current tQ is {tQ}\n") print(f"the current tQ is {tQ}\n")
data=get_hist_data(ids,conver_beingtime_to_ucttime('2024-04-10 15:05:00'),conver_beingtime_to_ucttime('2024-04-10 15:10:00'))

View File

@@ -19,8 +19,14 @@ def convert_timestamp_to_beijing_time(timestamp):
return beijing_time return beijing_time
def conver_beingtime_to_ucttime(timestr:str):
beijing_time=datetime.strptime(timestr,'%Y-%m-%d %H:%M:%S')
utc_time=beijing_time.astimezone(pytz.utc)
str_utc=utc_time.strftime('%Y-%m-%dT%H:%M:%SZ')
#print(str_utc)
return str_utc
def get_hist_data(ids, begin_date, end_date): def get_hist_data(ids, begin_date,end_date)->dict[str,dict[datetime,float]]:
# 数据接口的地址 # 数据接口的地址
url = 'http://183.64.62.100:9057/loong/api/curves/data' url = 'http://183.64.62.100:9057/loong/api/curves/data'
@@ -30,7 +36,7 @@ def get_hist_data(ids, begin_date, end_date):
'beginDate': begin_date, 'beginDate': begin_date,
'endDate': end_date 'endDate': end_date
} }
lst_data={}
try: try:
# 发送 GET 请求获取数据 # 发送 GET 请求获取数据
response = requests.get(url, params=params) response = requests.get(url, params=params)
@@ -43,10 +49,11 @@ def get_hist_data(ids, begin_date, end_date):
# 打印 'mpointId' 和 'mpointName' # 打印 'mpointId' 和 'mpointName'
for item in data['items']: for item in data['items']:
print("mpointId:", item['mpointId']) #print("mpointId:", item['mpointId'])
print("mpointName:", item['mpointName']) #print("mpointName:", item['mpointName'])
# 打印 'dataDate' 和 'dataValue' # 打印 'dataDate' 和 'dataValue'
data_seriers={}
for item_data in item['data']: for item_data in item['data']:
# print("dataDate:", item_data['dataDate']) # print("dataDate:", item_data['dataDate'])
# 将时间戳转换为北京时间 # 将时间戳转换为北京时间
@@ -54,6 +61,10 @@ def get_hist_data(ids, begin_date, end_date):
print("dataDate (Beijing Time):", beijing_time.strftime('%Y-%m-%d %H:%M:%S')) print("dataDate (Beijing Time):", beijing_time.strftime('%Y-%m-%d %H:%M:%S'))
print("dataValue:", item_data['dataValue']) print("dataValue:", item_data['dataValue'])
print() # 打印空行分隔不同条目 print() # 打印空行分隔不同条目
r=float(item_data['dataValue'])
data_seriers[beijing_time]=r
lst_data[item['mpointId']]=data_seriers
return lst_data
else: else:
# 如果请求不成功,打印错误信息 # 如果请求不成功,打印错误信息
print("请求失败,状态码:", response.status_code) print("请求失败,状态码:", response.status_code)
@@ -64,6 +75,6 @@ def get_hist_data(ids, begin_date, end_date):
# 使用示例 # 使用示例
get_hist_data(ids='2498,2500', # get_hist_data(ids='2498,2500',
begin_date='2024-03-31T16:00:00Z', # begin_date='2024-03-31T16:00:00Z',
end_date='2024-04-01T16:00:00Z') # end_date='2024-04-01T16:00:00Z')

View File

@@ -45,7 +45,7 @@ def get_realValue(ids)->dict[str,float]:
#print("datadt (Beijing Time):", beijing_time.strftime('%Y-%m-%d %H:%M:%S')) #print("datadt (Beijing Time):", beijing_time.strftime('%Y-%m-%d %H:%M:%S'))
#print("realValue:", realValue['realValue']) #print("realValue:", realValue['realValue'])
#print() # 打印空行分隔不同条目 #print() # 打印空行分隔不同条目
r=float(realValue['value']) r=float(realValue['realValue'])
lst_data[str(realValue['id'])]=r lst_data[str(realValue['id'])]=r
else: else:
# 如果请求不成功,打印错误信息 # 如果请求不成功,打印错误信息

5
run_simlation.py Normal file
View File

@@ -0,0 +1,5 @@
from tjnetwork import *
from get_current_status import *
def run_simulation(cur_datetime:str=None)->str:
return