diff --git a/get_current_status.py b/get_current_status.py index 8037c28..605fae8 100644 --- a/get_current_status.py +++ b/get_current_status.py @@ -1,25 +1,30 @@ from tjnetwork import * from get_realValue import * +from get_hist_data import * import datetime -ids=['3489','3854','3853','2510','2514','4780','4854'] +ids=['2498','3854','3853','2510','2514','4780','4854'] cur_data=None + def get_latest_cal_time()->datetime: current_time=datetime.datetime.now() return current_time -def get_current_data()->bool: +def get_current_data(str_datetime: str=None)->bool: 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: return False return True 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_dn500=cur_data[q_ids[1]] q_dn1000=cur_data[q_ids[2]] @@ -52,3 +57,4 @@ if __name__ == '__main__': if get_current_data()==True: tQ=get_current_total_Q() 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')) \ No newline at end of file diff --git a/get_hist_data.py b/get_hist_data.py index 14efa7e..3626505 100644 --- a/get_hist_data.py +++ b/get_hist_data.py @@ -19,8 +19,14 @@ def convert_timestamp_to_beijing_time(timestamp): 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' @@ -30,7 +36,7 @@ def get_hist_data(ids, begin_date, end_date): 'beginDate': begin_date, 'endDate': end_date } - + lst_data={} try: # 发送 GET 请求获取数据 response = requests.get(url, params=params) @@ -43,10 +49,11 @@ def get_hist_data(ids, begin_date, end_date): # 打印 'mpointId' 和 'mpointName' for item in data['items']: - print("mpointId:", item['mpointId']) - print("mpointName:", item['mpointName']) + #print("mpointId:", item['mpointId']) + #print("mpointName:", item['mpointName']) # 打印 'dataDate' 和 'dataValue' + data_seriers={} for item_data in item['data']: # 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("dataValue:", item_data['dataValue']) print() # 打印空行分隔不同条目 + r=float(item_data['dataValue']) + data_seriers[beijing_time]=r + lst_data[item['mpointId']]=data_seriers + return lst_data else: # 如果请求不成功,打印错误信息 print("请求失败,状态码:", response.status_code) @@ -64,6 +75,6 @@ def get_hist_data(ids, begin_date, end_date): # 使用示例 -get_hist_data(ids='2498,2500', - begin_date='2024-03-31T16:00:00Z', - end_date='2024-04-01T16:00:00Z') +# get_hist_data(ids='2498,2500', +# begin_date='2024-03-31T16:00:00Z', +# end_date='2024-04-01T16:00:00Z') diff --git a/get_realValue.py b/get_realValue.py index f8549e4..31788e2 100644 --- a/get_realValue.py +++ b/get_realValue.py @@ -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("realValue:", realValue['realValue']) #print() # 打印空行分隔不同条目 - r=float(realValue['value']) + r=float(realValue['realValue']) lst_data[str(realValue['id'])]=r else: # 如果请求不成功,打印错误信息 diff --git a/run_simlation.py b/run_simlation.py new file mode 100644 index 0000000..0a3e2b1 --- /dev/null +++ b/run_simlation.py @@ -0,0 +1,5 @@ +from tjnetwork import * +from get_current_status import * + +def run_simulation(cur_datetime:str=None)->str: + return \ No newline at end of file