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

@@ -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')