add feature

This commit is contained in:
baol 2024-11-23 18:07:09 +08:00
parent 6df0ea83bb
commit f33ea984f0
2 changed files with 43 additions and 16 deletions

View File

@ -77,6 +77,23 @@ def get_color_from_value(
return tuple(current_color)
def get_color_from_value(value: float, color_mapping: Dict[int, Tuple[int, int, int, int]]) -> Tuple[int, int, int, int]:
"""
根据输入的值,从颜色映射字典中查找对应的颜色
Parameters:
value: 输入值
color_mapping: 颜色映射字典
Returns:
Tuple[int, int, int, int]: RGBA颜色元组
"""
# 找到小于等于输入值的最大分界值
max_key = max([k for k in color_mapping if k <= value])
return color_mapping[max_key]
# 使用示例:
if __name__ == "__main__":
# 生成原始序列

View File

@ -22,23 +22,33 @@ def read_binary_file(file_path):
date = struct.unpack("<d", date_bytes)[0]
print(f"Date: {date}")
while True:
# print("index", index)
if index > 335:
break
time_bytes = file.read(8)
time = struct.unpack("<d", time_bytes)[0]
# print(f"time: {time}")
# 第一个时间戳所有数据
# 读取数据矩阵
data_size = column_count_int * 8 # 每个数据点8个字节
data_bytes = file.read(data_size)
data_matrix = struct.unpack(f"<{column_count_int}d", data_bytes)
data_matrix = [data_matrix]
new_df = pd.DataFrame(data_matrix)
df = pd.concat([df, new_df], ignore_index=True)
# print(f"Data Matrix: {data_matrix}")
index = index + 1
time_bytes = file.read(8)
time = struct.unpack("<d", time_bytes)[0]
print(f"Time: {time}")
for i in range(column_count_int):
print(i)
data_bytes = file.read(8)
data = struct.unpack("<d", data_bytes)[0]
print(f"Data: {data}")
# while True:
# # print("index", index)
# if index > 335:
# break
# time_bytes = file.read(8)
# time = struct.unpack("<d", time_bytes)[0]
# # print(f"time: {time}")
# # 读取数据矩阵
# data_size = column_count_int * 8 # 每个数据点8个字节
# data_bytes = file.read(data_size)
# data_matrix = struct.unpack(f"<{column_count_int}d", data_bytes)
# data_matrix = [data_matrix]
# new_df = pd.DataFrame(data_matrix)
# df = pd.concat([df, new_df], ignore_index=True)
# # print(f"Data Matrix: {data_matrix}")
# index = index + 1
return df